Skip to content

Commit bf00145

Browse files
authored
test: correct false-negative for advancing timers (#948)
1 parent ee062e7 commit bf00145

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

tests/utils/misc/wait.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
import {createConfig} from '#src/setup/setup'
12
import {wait} from '#src/utils/misc/wait'
23

34
test('advances timers when set', async () => {
5+
const beforeReal = performance.now()
46
jest.useFakeTimers()
5-
jest.setTimeout(50)
6-
// If this wasn't advancing fake timers, we'd timeout and fail the test
7-
await wait(10000, jest.advanceTimersByTime)
7+
const beforeFake = performance.now()
8+
9+
const config = createConfig({
10+
delay: 1000,
11+
advanceTimers: jest.advanceTimersByTime,
12+
})
13+
await wait(config)
14+
15+
expect(performance.now() - beforeFake).toBe(1000)
816
jest.useRealTimers()
9-
})
17+
expect(performance.now() - beforeReal).toBeLessThan(10)
18+
}, 10)

0 commit comments

Comments
 (0)