提交 471b5cad 编写于 作者: lizhongyi_'s avatar lizhongyi_

调整Promise 测试例,兼容安卓和web

上级 969c9666
...@@ -2,7 +2,6 @@ import { describe, test, expect, Result } from './tests.uts' ...@@ -2,7 +2,6 @@ import { describe, test, expect, Result } from './tests.uts'
export function testPromise(): Result { export function testPromise(): Result {
return describe("Promise", () => { return describe("Promise", () => {
// #ifdef APP-IOS
test('constructor', () => { test('constructor', () => {
// 常规方式 // 常规方式
let p = new Promise<number>((resolve, reject) => { let p = new Promise<number>((resolve, reject) => {
...@@ -308,7 +307,7 @@ export function testPromise(): Result { ...@@ -308,7 +307,7 @@ export function testPromise(): Result {
console.log(res); console.log(res);
let statusArr : string[] = [] let statusArr : string[] = []
res.forEach((item, index: number) => { res.forEach((item, index: number) => {
statusArr.append(item.status) statusArr.add(item.status)
}) })
expect(statusArr).toEqual(["fulfilled", "fulfilled", "rejected", "rejected"]) expect(statusArr).toEqual(["fulfilled", "fulfilled", "rejected", "rejected"])
}) })
...@@ -352,9 +351,17 @@ export function testPromise(): Result { ...@@ -352,9 +351,17 @@ export function testPromise(): Result {
.catch( .catch(
(error: any | null) => { (error: any | null) => {
console.log("test for promise.any error ==> ", error); console.log("test for promise.any error ==> ", error);
// #ifdef APP-IOS
expect((error as UTSPromiseAggregateError).name).toEqual("AggregateError"); expect((error as UTSPromiseAggregateError).name).toEqual("AggregateError");
expect((error as UTSPromiseAggregateError).message).toEqual("All promises were rejected"); expect((error as UTSPromiseAggregateError).message).toEqual("All promises were rejected");
expect((error as UTSPromiseAggregateError).errors).toEqual([null, "error"]); expect((error as UTSPromiseAggregateError).errors).toEqual([null, "error"]);
// #endif
// #ifdef APP-ANDROID
expect((error as UTSPromiseAggregateError).name).toEqual("AggregateError");
expect((error as UTSPromiseAggregateError).message).toEqual("All promises were rejected");
expect((error as UTSPromiseAggregateError).errors).toEqual([null, "error"]);
// #endif
}) })
}) })
...@@ -392,6 +399,5 @@ export function testPromise(): Result { ...@@ -392,6 +399,5 @@ export function testPromise(): Result {
expect(error).toEqual(null); expect(error).toEqual(null);
}) })
}) })
// #endif
}) })
} }
...@@ -46,10 +46,7 @@ export function runTests() : UTSJSONObject { ...@@ -46,10 +46,7 @@ export function runTests() : UTSJSONObject {
const ArrayBufferRes = testArrayBuffer(); const ArrayBufferRes = testArrayBuffer();
// #endif // #endif
const NativeCodeRes = testNativeCode(); const NativeCodeRes = testNativeCode();
const PromiseRes = testPromise();
// #ifdef APP-IOS
const PromiseRes = testPromise();
// #endif
return { return {
Array: ArrayRes, Array: ArrayRes,
Date: DateRes, Date: DateRes,
...@@ -73,8 +70,6 @@ export function runTests() : UTSJSONObject { ...@@ -73,8 +70,6 @@ export function runTests() : UTSJSONObject {
ArrayBuffer: ArrayBufferRes, ArrayBuffer: ArrayBufferRes,
// #endif // #endif
NativeCode: NativeCodeRes, NativeCode: NativeCodeRes,
// #ifdef APP-IOS Primise: PromiseRes
Primise: PromiseRes
// #endif
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册