diff --git a/uni_modules/uts-tests/utssdk/KeyWord.uts b/uni_modules/uts-tests/utssdk/KeyWord.uts index 5ea2bb67f34a25f988c5fc68b0b0b0471273b65f..c294fabc136b54746471db61eb53f8317a6ef4be 100644 --- a/uni_modules/uts-tests/utssdk/KeyWord.uts +++ b/uni_modules/uts-tests/utssdk/KeyWord.uts @@ -82,7 +82,7 @@ export function testKeyWord() : Result { test('typeof', () => { let new1 = new User() expect(typeof (new1)).toEqual('object') - + //expect(typeof null).toEqual('object') // #ifdef APP-ANDROID || APP-IOS expect(typeof (123456.789)).toEqual('Double') //expect(typeof(789778979798797987979)).toEqual('number') diff --git a/uni_modules/uts-tests/utssdk/UTSJSONObject.uts b/uni_modules/uts-tests/utssdk/UTSJSONObject.uts index b1a896245b42b28b34ad460c967e65c0e01b9155..4b41a23252564545ee86d45898b1e25d4f920af6 100644 --- a/uni_modules/uts-tests/utssdk/UTSJSONObject.uts +++ b/uni_modules/uts-tests/utssdk/UTSJSONObject.uts @@ -43,6 +43,56 @@ export function testUTSJSONObject() : Result { expect(result.toJSONObject().toJSONString()).toEqual('{"opt":"xxxx","service":{"array":[{"name":"xxx","type":0}],"name":"0xxxb34fb","type":0}}'); + + type TestData = { + num:number; + num2:number; + str:string; + } + + let data1:TestData = { + num:1, + num2:2.369, + str:'test' + } + let data2 = JSON.parse(JSON.stringify(data1)) + + expect(data2!.toJSONString()).toEqual('{"str":"test","num":1.0,"num2":2.369}') + + class TestData2 implements IJsonStringify{ + toJSON():any|null{ + return "122" + } + } + + let testData2 = TestData2() + let dataClass = UTSAndroid.getJavaClass(data2) + let data3 = { + strA:"stringA", + dataClass:dataClass, + booleanB:false, + testData:testData2 + } + + expect(data3!.toJSONString()).toEqual('{"testData":"122","strA":"stringA","dataClass":"io.dcloud.uts.UTSJSONObject","booleanB":false}') + + + type TestData4 = { + name:string, + data:any, + } + + let data4 : TestData4 = { + name:"张三", + data:data1 + } + + let data5 = { + data4 :data4 + } + + expect(data5!.toJSONString()).toEqual('{"data4":{"data":{"num":1,"num2":2.369,"str":"test"},"name":"张三"}}') + // #endif })