deno.land / std@0.166.0 / async / deferred_test.ts

deferred_test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.import { assertEquals, assertRejects, assertThrows,} from "../testing/asserts.ts";import { deferred } from "./deferred.ts";
Deno.test("[async] deferred: resolve", async function () { const d = deferred<string>(); assertEquals(d.state, "pending"); d.resolve("🦕"); assertEquals(await d, "🦕"); assertEquals(d.state, "fulfilled");});
Deno.test("[async] deferred: reject", async function () { const d = deferred<number>(); assertEquals(d.state, "pending"); d.reject(new Error("A deno error 🦕")); await assertRejects(async () => { await d; }); assertEquals(d.state, "rejected");});
Deno.test("[async] deferred: state with promised value", async function () { const d = deferred<string>(); const e = deferred<string>(); assertEquals(d.state, "pending"); d.resolve(e); assertEquals(d.state, "pending"); e.resolve("🦕"); assertEquals(await d, "🦕"); assertEquals(d.state, "fulfilled");});
Deno.test("[async] deferred: state is readonly", () => { const d = deferred<string>(); assertEquals(d.state, "pending"); assertThrows(() => { (d.state as unknown) = "fulfilled"; });});
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2458

Version Info

Tagged at
2 months ago