|
1 | 1 | // Copyright 2018-2025 the Deno authors. MIT license.
|
2 |
| -import { assertAlmostEquals, assertEquals, assertRejects } from "@std/assert"; |
| 2 | +import { assertEquals, assertLess, assertRejects } from "@std/assert"; |
3 | 3 | import { waitFor } from "./unstable_wait_for.ts";
|
4 | 4 |
|
5 | 5 | // NOT detecting leaks means that the internal interval was correctly cleared
|
6 | 6 |
|
7 | 7 | Deno.test("waitFor() returns fulfilled promise", async () => {
|
8 | 8 | let flag = false;
|
9 | 9 | setTimeout(() => flag = true, 100);
|
10 |
| - const start = Date.now(); |
| 10 | + const start = performance.now(); |
11 | 11 | await waitFor(() => flag === true, 1000);
|
12 |
| - // Expects the promise to be resolved after 100ms |
13 |
| - assertAlmostEquals(Date.now() - start, 100, 10); |
| 12 | + assertLess(performance.now() - start, 1000); |
14 | 13 | });
|
15 | 14 |
|
16 | 15 | Deno.test("waitFor() throws DOMException on timeout", async () => {
|
17 | 16 | let flag = false;
|
18 | 17 | const id = setTimeout(() => flag = true, 1000);
|
19 |
| - const start = Date.now(); |
| 18 | + const start = performance.now(); |
20 | 19 | const error = await assertRejects(
|
21 | 20 | () => waitFor(() => flag === true, 100),
|
22 | 21 | DOMException,
|
23 | 22 | "Signal timed out.",
|
24 | 23 | );
|
25 |
| - assertAlmostEquals(Date.now() - start, 100, 10); |
| 24 | + assertLess(performance.now() - start, 1000); |
26 | 25 | assertEquals(error.name, "TimeoutError");
|
27 | 26 | clearTimeout(id);
|
28 | 27 | });
|
0 commit comments