diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-11-01 23:25:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-01 22:25:18 +0000 |
commit | ab72019a17ccc077384c37eaeae15fffc9ce4d92 (patch) | |
tree | 9817bf313e25bdd8d318fb58b3e366f14d252858 /cli/tests | |
parent | 24c3c9695865bb478f5651da4982b7e0a34afc72 (diff) |
feat: enable Array.fromAsync (#21048)
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit/console_test.ts | 1 | ||||
-rw-r--r-- | cli/tests/unit/globals_test.ts | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts index d8990559e..d6e2a5263 100644 --- a/cli/tests/unit/console_test.ts +++ b/cli/tests/unit/console_test.ts @@ -500,6 +500,7 @@ Deno.test(function consoleTestStringifyFunctionWithProperties() { [isArray]: [Function: isArray] { [length]: 1, [name]: "isArray" }, [from]: [Function: from] { [length]: 1, [name]: "from" }, [of]: [Function: of] { [length]: 0, [name]: "of" }, + [fromAsync]: [Function: fromAsync] { [length]: 1, [name]: "fromAsync" }, [Symbol(Symbol.species)]: [Getter] }`, ); diff --git a/cli/tests/unit/globals_test.ts b/cli/tests/unit/globals_test.ts index e5ff2cc8e..b47e83cfd 100644 --- a/cli/tests/unit/globals_test.ts +++ b/cli/tests/unit/globals_test.ts @@ -153,3 +153,20 @@ Deno.test(async function promiseWithResolvers() { await assertRejects(() => promise, Error, "boom!"); } }); + +Deno.test(async function arrayFromAsync() { + // Taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync#examples + // Thank you. + const asyncIterable = (async function* () { + for (let i = 0; i < 5; i++) { + await new Promise((resolve) => setTimeout(resolve, 10 * i)); + yield i; + } + })(); + + const a = await Array.fromAsync(asyncIterable); + assertEquals(a, [0, 1, 2, 3, 4]); + + const b = await Array.fromAsync(new Map([[1, 2], [3, 4]])); + assertEquals(b, [[1, 2], [3, 4]]); +}); |