Skip to content

Commit 431ed58

Browse files
authored
test(async/unstable): fix flaky waitFor() test (#6413)
1 parent a03baf9 commit 431ed58

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

async/unstable_wait_for_test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
// Copyright 2018-2025 the Deno authors. MIT license.
2-
import { assertAlmostEquals, assertEquals, assertRejects } from "@std/assert";
2+
import { assertEquals, assertLess, assertRejects } from "@std/assert";
33
import { waitFor } from "./unstable_wait_for.ts";
44

55
// NOT detecting leaks means that the internal interval was correctly cleared
66

77
Deno.test("waitFor() returns fulfilled promise", async () => {
88
let flag = false;
99
setTimeout(() => flag = true, 100);
10-
const start = Date.now();
10+
const start = performance.now();
1111
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);
1413
});
1514

1615
Deno.test("waitFor() throws DOMException on timeout", async () => {
1716
let flag = false;
1817
const id = setTimeout(() => flag = true, 1000);
19-
const start = Date.now();
18+
const start = performance.now();
2019
const error = await assertRejects(
2120
() => waitFor(() => flag === true, 100),
2221
DOMException,
2322
"Signal timed out.",
2423
);
25-
assertAlmostEquals(Date.now() - start, 100, 10);
24+
assertLess(performance.now() - start, 1000);
2625
assertEquals(error.name, "TimeoutError");
2726
clearTimeout(id);
2827
});

0 commit comments

Comments
 (0)