Skip to content

Commit

Permalink
test: correct false-negative for advancing timers (#948)
Browse files Browse the repository at this point in the history
  • Loading branch information
ph-fritsche authored May 10, 2022
1 parent ee062e7 commit bf00145
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tests/utils/misc/wait.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import {createConfig} from '#src/setup/setup'
import {wait} from '#src/utils/misc/wait'

test('advances timers when set', async () => {
const beforeReal = performance.now()
jest.useFakeTimers()
jest.setTimeout(50)
// If this wasn't advancing fake timers, we'd timeout and fail the test
await wait(10000, jest.advanceTimersByTime)
const beforeFake = performance.now()

const config = createConfig({
delay: 1000,
advanceTimers: jest.advanceTimersByTime,
})
await wait(config)

expect(performance.now() - beforeFake).toBe(1000)
jest.useRealTimers()
})
expect(performance.now() - beforeReal).toBeLessThan(10)
}, 10)

0 comments on commit bf00145

Please sign in to comment.