KeyWord.uts 1.9 KB
Newer Older
杜庆泉's avatar
杜庆泉 已提交
1 2 3 4 5 6 7 8
import { describe, test, expect, Result } from './tests.uts'

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

export function testKeyWord(): Result {
lizhongyi_'s avatar
lizhongyi_ 已提交
9
    return describe("KeyWord", () => {
杜庆泉's avatar
杜庆泉 已提交
10 11
        test('new', () => {
           let new1 = new User()
lizhongyi_'s avatar
lizhongyi_ 已提交
12 13 14
		   // expect(JSON.stringify(new1)).toEqual('{"age":0,"name":""}')
		   console.log(JSON.stringify(new1))
		   
杜庆泉's avatar
杜庆泉 已提交
15 16
		   new1.age = 10
		   new1.name = "job"
lizhongyi_'s avatar
lizhongyi_ 已提交
17 18 19
		   console.log(JSON.stringify(new1))
		   // expect(JSON.stringify(new1)).toEqual('{"age":10,"name":"job"}')
		   
杜庆泉's avatar
杜庆泉 已提交
20 21 22
        })
		
		test('typeof', () => {
杜庆泉's avatar
杜庆泉 已提交
23 24 25 26 27 28 29 30 31
			let new1 = new User()
			expect(typeof(new1)).toEqual('object')
			expect(typeof(123456.789)).toEqual('number')
			expect(typeof(789778979798797987979)).toEqual('number')
			expect(typeof(0.0)).toEqual('number')
			expect(typeof("hello world")).toEqual('string')
			expect(typeof([1,2,3])).toEqual('object')
			expect(typeof(new Array<any>())).toEqual('object')
			expect(typeof(new Set<any>())).toEqual('object')
lizhongyi_'s avatar
lizhongyi_ 已提交
32
			// expect(typeof(new Map<any,any>())).toEqual('object')
杜庆泉's avatar
杜庆泉 已提交
33 34
			expect(typeof(new Date())).toEqual('object')
			expect(typeof("hello world")).toEqual('string')
lizhongyi_'s avatar
lizhongyi_ 已提交
35 36
			// 原生对象  
			// #ifndef APP-IOS
杜庆泉's avatar
杜庆泉 已提交
37
			expect(typeof(UTSAndroid.getUniActivity())).toEqual('object')
lizhongyi_'s avatar
lizhongyi_ 已提交
38 39
			// #endif
			   
杜庆泉's avatar
杜庆泉 已提交
40
		   
杜庆泉's avatar
杜庆泉 已提交
41 42 43 44
		})
        
		
		test('instanceof', () => {
杜庆泉's avatar
杜庆泉 已提交
45
			let user1:any = new User()
杜庆泉's avatar
杜庆泉 已提交
46 47
			let instanceRet1 = user1 instanceof User
			expect(instanceRet1).toEqual(true)
48
			let instanceRet2 = (typeof user1) == "string"
杜庆泉's avatar
杜庆泉 已提交
49
			expect(instanceRet2).toEqual(false)
杜庆泉's avatar
杜庆泉 已提交
50
			let num1:any = 3.1415926 
51
			let instanceRet3 = (typeof num1) == "string" 
杜庆泉's avatar
杜庆泉 已提交
52
			expect(instanceRet3).toEqual(false)
53
			let instanceRet4 = (typeof num1) == "number"
lizhongyi_'s avatar
lizhongyi_ 已提交
54
			expect(instanceRet4).toEqual(false)
杜庆泉's avatar
杜庆泉 已提交
55 56
		})
		
杜庆泉's avatar
杜庆泉 已提交
57 58 59 60 61 62
		test('isArray', () => {
			let user1:any = new User()
			expect(Array.isArray(user1)).toEqual(false)
			expect(Array.isArray([1,2,3])).toEqual(true)
		})
		
杜庆泉's avatar
杜庆泉 已提交
63 64 65
		
    })
}