KeyWord.uts 1.2 KB
Newer Older
杜庆泉's avatar
杜庆泉 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import { describe, test, expect, Result } from './tests.uts'

class User{
	name:string = "";
	age:number = 0
}

export function testKeyWord(): Result {
    return describe("Error", () => {
        test('new', () => {
           let new1 = new User()
		   expect(JSON.stringify(new1)).toEqual('{"age":0,"name":""}')
		   new1.age = 10
		   new1.name = "job"
		   expect(JSON.stringify(new1)).toEqual('{"age":10,"name":"job"}')
        })
		
		test('typeof', () => {
		   let new1 = new User()
		   expect(typeof(new1)).toEqual('object')
		   expect(typeof(123456.789)).toEqual('number')
		   expect(typeof("hello world")).toEqual('string')
杜庆泉's avatar
杜庆泉 已提交
23 24 25
		   console.log(typeof([1,2,3]))
		   let arr1 = new Array<any>()
		   console.log(arr1)
杜庆泉's avatar
杜庆泉 已提交
26 27 28 29
		})
        
		
		test('instanceof', () => {
杜庆泉's avatar
杜庆泉 已提交
30
			let user1:any = new User()
杜庆泉's avatar
杜庆泉 已提交
31 32 33 34
			let instanceRet1 = user1 instanceof User
			expect(instanceRet1).toEqual(true)
			let instanceRet2 = user1 instanceof String
			expect(instanceRet2).toEqual(false)
杜庆泉's avatar
杜庆泉 已提交
35 36 37 38 39
			let num1:any = 3.1415926 
			let instanceRet3 = num1 instanceof String
			expect(instanceRet3).toEqual(false)
			let instanceRet4 = num1 instanceof Number
			expect(instanceRet4).toEqual(true)
杜庆泉's avatar
杜庆泉 已提交
40 41 42 43 44
		})
		
		
    })
}