提交 41e2c4c8 编写于 作者: 杜庆泉's avatar 杜庆泉

补充UTSNumber 部分测试示例

上级 e7def913
...@@ -319,6 +319,12 @@ export function testJSON() : Result { ...@@ -319,6 +319,12 @@ export function testJSON() : Result {
a: 1 a: 1
}.toMap() }.toMap()
expect(map.get('a')).toEqual(1) expect(map.get('a')).toEqual(1)
const json = `{"result":true, "count":42}`;
const obj = JSON.parse(json) as UTSJSONObject;
let retStr = JSON.stringify(obj)
expect(retStr).toEqual('{"result":true,"count":42}')
}) })
test('parse Map', () => { test('parse Map', () => {
......
...@@ -60,6 +60,25 @@ export function testNumber() : Result { ...@@ -60,6 +60,25 @@ export function testNumber() : Result {
expect(isFinite(910)).toEqual(true); expect(isFinite(910)).toEqual(true);
expect(isFinite(0)).toEqual(true); expect(isFinite(0)).toEqual(true);
}) })
test('number-from-json-parse', () => {
type A = {
a:number
}
let aj = JSON.parse<A>('{"a":1}');
expect(aj?.a == 1).toEqual(true);
expect(aj?.a == 1 as number).toEqual(true);
expect(aj?.a == 1.0).toEqual(true);
expect(aj?.a == 1.0 as number).toEqual(true);
let ki:Int = 1;
let kd:Double = 1.0;
let kf:Float = (1.0).toFloat();
expect(aj?.a == ki).toEqual(true);
expect(aj?.a == kd).toEqual(true);
expect(aj?.a == kf).toEqual(true);
})
test('isInteger', () => { test('isInteger', () => {
expect(Number.isInteger(12)).toEqual(true); expect(Number.isInteger(12)).toEqual(true);
expect(Number.isInteger(12.01)).toEqual(false); expect(Number.isInteger(12.01)).toEqual(false);
......
...@@ -21,7 +21,21 @@ export function testConsole() : Result { ...@@ -21,7 +21,21 @@ export function testConsole() : Result {
expect(obtainInnerObject(pageInstance).get("className")).toEqual("io.dcloud.uniapp.vue.ComponentInternalInstance"); expect(obtainInnerObject(pageInstance).get("className")).toEqual("io.dcloud.uniapp.vue.ComponentInternalInstance");
expect(obtainInnerObject(pageInstance).get("type")).toEqual("object"); expect(obtainInnerObject(pageInstance).get("type")).toEqual("object");
// #endif // #endif
} })
)
test('console-number-from-JSON-parse', () => {
// #ifdef APP-ANDROID
let aj2 = JSON.parse('{"a":1}') as UTSJSONObject;
console.log(aj2!['a'])
expect(obtainInnerObject(aj2!['a']).get("type")).toEqual("number");
expect(obtainInnerObject(aj2!['a']).get("subType")).toEqual("number");
// #endif
})
}) })
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册