function
test.jest.useFakeTimers
Replace the timer functions on globalThis with fakes that use a fake clock. The clock only moves when the test moves it. A reference saved before this call, such as const savedSetTimeout = setTimeout, stays real.
The real timers are restored when the test file ends, unless a preload made this call at its top level.
Referenced types
interface FakeTimersOptions
- advanceTimers?: number | boolean
Jest's name for
shouldAdvanceTime(passtrue) andadvanceTimeDelta(pass a number). - loopLimit?: number
The number of timers
runAllTimers()runs before it throws. Any function that moves the clock also throws after this many fakedprocess.nextTickorqueueMicrotaskcallbacks in a row. - shouldAdvanceTime?: boolean
Advance the fake clock by
advanceTimeDeltamilliseconds everyadvanceTimeDeltareal milliseconds.