diff --git a/uni_modules/uts-tests/utssdk/JSON.uts b/uni_modules/uts-tests/utssdk/JSON.uts index 32cb2da5f60131a06e900791d03319dde9d05342..cdf8917b776c4c876812c70af40fb12e0315056b 100644 --- a/uni_modules/uts-tests/utssdk/JSON.uts +++ b/uni_modules/uts-tests/utssdk/JSON.uts @@ -38,9 +38,59 @@ function countOccurrences(str : string, substr : string) : number { return count; } +class A1 implements IJsonStringify{ + override toJSON():any|null{ + let jsonRet = { + 'name': "zhangsan", + 'age': 12, + } + return jsonRet + } +} + +class A2 implements IJsonStringify{ + override toJSON():any|null{ + return 2 + } +} + +class A3 implements IJsonStringify{ + override toJSON():any|null{ + return "json" + } +} + +class A4 implements IJsonStringify{ + override toJSON():any|null{ + return null + } +} + +class A5 implements IJsonStringify{ + override toJSON():any|null{ + return new A1() + } +} + +class A6 implements IJsonStringify{ + override toJSON():any|null{ + return new A5() + } +} + export function testJSON() : Result { return describe("JSON", () => { + + test('custom-stringify', () => { + expect(JSON.stringify(new A1()).length).toEqual(28) + expect(JSON.stringify(new A2())).toEqual("2") + expect(JSON.stringify(new A3())).toEqual('"json"') + expect(JSON.stringify(new A4())).toEqual('null') + expect(JSON.stringify(new A5()).length).toEqual(28) + expect(JSON.stringify(new A6()).length).toEqual(28) + }) + test('parse', () => { // #TEST JSON.parse_tip,JSON.parse const json = `{"result":true, "count":42}`; @@ -264,9 +314,11 @@ export function testJSON() : Result { expect(a8.length).toEqual(73); expect(countOccurrences(a8, "99999")).toEqual(6); - // #endif }) + + + test('stringify', () => { // #ifdef APP-ANDROID diff --git a/uni_modules/uts-tests/utssdk/tests.uts b/uni_modules/uts-tests/utssdk/tests.uts index 27b1136983c3cdf2244c731128b2d7e98b0e48f3..fc6457d257277426d85eb7a4877caa0e74080492 100644 --- a/uni_modules/uts-tests/utssdk/tests.uts +++ b/uni_modules/uts-tests/utssdk/tests.uts @@ -2,7 +2,7 @@ import { Matchers,NumberMatchers } from './Matchers.uts' export const describes = new Map() -export class Result implements io.dcloud.uts.json.IJsonStringify { +export class Result implements IJsonStringify { total = 0 passed: string[] = [] failed: string[] = []