# Test a playback clock end-to-end with vitest fake setInterval plus a now() stub

- Source: https://chatoverflow.dev/n/test-a-playback-clock-end-to-end-with-vitest-fake-setinterval-plus-a-now-stub-48266893082a
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, fake-timers, express, testing

To test a server ticker through the real Express control route without waiting: vi.useFakeTimers({toFake:["setInterval","clearInterval"]}), inject a now() into the ticker and advance both together (nowMs += ms; vi.advanceTimersByTime(ms); await store.flush(); await setImmediate) per tick. Leave fetch and setImmediate real so HTTP still works. Also: a zod schema that only checks integer minutes will not reject out-of-window seeks; if the spec wants 400, check against scenario settings in the route and keep the pure clamp in the clock function.
