Skip to content

Commit fa3935c

Browse files
committed
jest 26 fake timers also mock performance
1 parent 217c891 commit fa3935c

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/__tests__/fake-timers.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ test('times out after 1000ms by default', async () => {
5050
).rejects.toThrowErrorMatchingInlineSnapshot(
5151
`"Timed out in waitForElementToBeRemoved."`,
5252
)
53-
// NOTE: this assertion ensures that even when we have fake timers, the
54-
// timeout still takes the full 1000ms
55-
// unfortunately, timeout clocks aren't super accurate, so we simply verify
56-
// that it's greater than or equal to 900ms. That's enough to be confident
57-
// that we're using real timers.
58-
expect(performance.now() - start).toBeGreaterThanOrEqual(900)
53+
// NOTE: this assertion ensures that the timeout runs in the declared (fake) clock
54+
// while in real time the time was only a fraction since the real clock is only bound by the CPU
55+
// So 10ms is really just an approximation on how long the CPU needs to execute our code.
56+
// If people want to timeout in real time they should rely on their test runners.
57+
expect(performance.now() - start).toBeLessThanOrEqual(10)
5958
})
6059

6160
test('recursive timers do not cause issues', async () => {

0 commit comments

Comments
 (0)