From fb78106abd8bf8f71f2bec0b6f62ac9535684b2d Mon Sep 17 00:00:00 2001 From: duqingquan Date: Mon, 11 Nov 2024 16:58:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=20Array.fromAsync=20?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uts-tests/utssdk/Array.uts | 62 +++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/uni_modules/uts-tests/utssdk/Array.uts b/uni_modules/uts-tests/utssdk/Array.uts index d93e219..fccb22e 100644 --- a/uni_modules/uts-tests/utssdk/Array.uts +++ b/uni_modules/uts-tests/utssdk/Array.uts @@ -329,9 +329,69 @@ export function testArray() : Result { m1.set("name","张三") m1.set("age",123) let a3 = Array.from(m1) - console.log(a3) expect(a3).toEqual([["name","张三"],["age",123]]); + let s1 = new Set() + s1.add("张三") + s1.add("李四") + let a4 = Array.from(s1) + expect(a4).toEqual(["张三","李四"]); + + }) + + test("fromAsync", () => { + + let m1 = new Map([ + [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() + let p = new Promise((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", () => { -- GitLab