-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromise_state_test.ts
38 lines (34 loc) · 1.06 KB
/
promise_state_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
import { test } from "@cross/test";
import { assertEquals } from "@std/assert";
import { promiseState } from "./promise_state.ts";
test(
"promiseState() returns 'fulfilled' for resolved promise",
async () => {
const p = Promise.resolve("Resolved promise");
assertEquals(await promiseState(p), "fulfilled");
},
);
test(
"promiseState() returns 'rejected' for rejected promise",
async () => {
const p = Promise.reject("Rejected promise");
p.catch(() => undefined); // Avoid 'Uncaught (in promise) Rejected promise'
assertEquals(await promiseState(p), "rejected");
},
);
test(
"promiseState() returns 'pending' for not resolved promise",
async () => {
const p = new Promise(() => undefined);
assertEquals(await promiseState(p), "pending");
},
);
test("promiseState() returns refreshed status", async () => {
const { promise, resolve } = Promise.withResolvers<void>();
const p = (async () => {
await promise;
})();
assertEquals(await promiseState(p), "pending");
resolve();
assertEquals(await promiseState(p), "fulfilled");
});