-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
peek_promise_state_test.ts
38 lines (34 loc) · 1.16 KB
/
peek_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 { flushPromises } from "./flush_promises.ts";
import { peekPromiseState } from "./peek_promise_state.ts";
test(
"peekPromiseState() returns 'fulfilled' for resolved promise",
async () => {
const p = Promise.resolve("Resolved promise");
assertEquals(await peekPromiseState(p), "fulfilled");
},
);
test(
"peekPromiseState() returns 'rejected' for rejected promise",
async () => {
const p = Promise.reject("Rejected promise");
p.catch(() => undefined); // Avoid 'Uncaught (in promise) Rejected promise'
assertEquals(await peekPromiseState(p), "rejected");
},
);
test(
"peekPromiseState() returns 'pending' for not resolved promise",
async () => {
const p = new Promise(() => undefined);
assertEquals(await peekPromiseState(p), "pending");
},
);
test("peekPromiseState() return the current state of the promise", async () => {
const p = Promise.resolve<void>(undefined)
.then(() => {})
.then(() => {});
assertEquals(await peekPromiseState(p), "pending");
await flushPromises();
assertEquals(await peekPromiseState(p), "fulfilled");
});