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

补充 Array.fromAsync 相关测试

上级 241ee805
...@@ -329,9 +329,69 @@ export function testArray() : Result { ...@@ -329,9 +329,69 @@ export function testArray() : Result {
m1.set("name","张三") m1.set("name","张三")
m1.set("age",123) m1.set("age",123)
let a3 = Array.from(m1) let a3 = Array.from(m1)
console.log(a3)
expect(a3).toEqual([["name","张三"],["age",123]]); expect(a3).toEqual([["name","张三"],["age",123]]);
let s1 = new Set<string>()
s1.add("张三")
s1.add("李四")
let a4 = Array.from(s1)
expect(a4).toEqual(["张三","李四"]);
})
test("fromAsync", () => {
let m1 = new Map<any,any>([
[1, 2],
[3, 4],
])
Array.fromAsync(
m1
).then((array) => {
expect(array).toEqual([[1, 2], [3, 4]]);
});
let s1 = new Set([Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)])
Array.fromAsync(
s1
).then((array) => {
expect(array).toEqual([1, 2, 3]);
});
UTSAndroid.getDispatcher("io").async(function(_){
let ret2 = new Array<any>()
let p = new Promise<number>((resolve, reject) => {
setTimeout(() => {
reject("xxxxxxxx")
}, 1000)
})
let pArray = [p, 1, 2, "3"]
const a = Array.fromAsync(pArray)
a.then((res) => {
ret2 = ret2.concat(res)
}).catch((err) => {
ret2.clear()
})
const pArray1 = Array.fromAsync("abcdefg");
pArray1.then((res) => {
ret2 = ret2.concat(res)
})
setTimeout(function(){
expect(ret2).toEqual(["a", "b", "c", "d", "e", "f", "g"]);
},200)
setTimeout(function(){
expect(ret2).toEqual([1]);
},2000)
},null)
}) })
test("indexOf", () => { test("indexOf", () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册