Fake Timers in Vitest

From the Vitest cheat sheet · Fake Timers & Dates · verified Nov 2026

Fake Timers

Fast-forward timers and intervals without waiting in real time

typescript
vi.useFakeTimers()

setTimeout(callback, 1000)
vi.advanceTimersByTime(1000)   // fast-forward
expect(callback).toHaveBeenCalled()

vi.runAllTimers()              // flush every timer
vi.useRealTimers()             // restore
📌 Use the Async variants when timer callbacks await promises
⚠️ nextTick and queueMicrotask aren't faked unless listed in toFake
💡 expect.poll and vi.waitFor auto-advance fake timers for you
⚡ fakeNodeBuiltins (5.1+) also fakes node:timers/promises imports
fake-timersuseFakeTimersadvanceTimersByTime

Continue with Vitest

Save the full cheat sheet or work through every related task.

More Vitest tasks

Back to the full Vitest cheat sheet