KeyWord.uts 1.8 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 48 49
			let instanceRet1 = user1 instanceof User
			expect(instanceRet1).toEqual(true)
			let instanceRet2 = user1 instanceof String
			expect(instanceRet2).toEqual(false)
杜庆泉's avatar
杜庆泉 已提交
50 51 52 53 54
			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
杜庆泉 已提交
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
		
    })
}