提交 243b16d6 编写于 作者: 杜庆泉's avatar 杜庆泉

增加 UTSJSONObject.toJSONString 测试示例

上级 07175de3
...@@ -82,7 +82,7 @@ export function testKeyWord() : Result { ...@@ -82,7 +82,7 @@ export function testKeyWord() : Result {
test('typeof', () => { test('typeof', () => {
let new1 = new User() let new1 = new User()
expect(typeof (new1)).toEqual('object') expect(typeof (new1)).toEqual('object')
//expect(typeof null).toEqual('object')
// #ifdef APP-ANDROID || APP-IOS // #ifdef APP-ANDROID || APP-IOS
expect(typeof (123456.789)).toEqual('Double') expect(typeof (123456.789)).toEqual('Double')
//expect(typeof(789778979798797987979)).toEqual('number') //expect(typeof(789778979798797987979)).toEqual('number')
......
...@@ -43,6 +43,56 @@ export function testUTSJSONObject() : Result { ...@@ -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}}'); 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<UTSJSONObject>(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 // #endif
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册