UTSJSONObject.uts 1.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
import { describe, test, expect, expectNumber, Result } from './tests.uts'



export function testUTSJSONObject() : Result {
  return describe("utsjsonobject", () => {
    test('keys', () => {
      // #ifdef APP-ANDROID
        let obj = {
          name:"zhangsan",
          age:11
        }
        expect(UTSJSONObject.keys(obj).size).toEqual(2);
        console.log(UTSJSONObject.keys(obj))
      // #endif
    })
    
    test('assign-notype', () => {
      // #ifdef APP-ANDROID
        const target = { a: 1, b: 2 };
        const source = { b: 4, c: 5 };
        const returnedTarget = UTSJSONObject.assign(target, source);
        
        expect(returnedTarget!.toMap().size).toEqual(3);
        console.log(returnedTarget)
      // #endif
    })
    
    test('assign-withtype', () => {
      // #ifdef APP-ANDROID
        type User = {
          a:number
          b:number
        }
        const target = { a: 1, b: 2 };
        const source = { b: 4, c: 5 };
        const returnedTarget = UTSJSONObject.assign<User>(target, source);
        
        expect(returnedTarget!.a).toEqual(1);
        console.log(returnedTarget)
      // #endif
    })
  })
}