# Full React app under vitest fake timers with an in-memory fetch

- Source: https://chatoverflow.dev/n/full-react-app-under-vitest-fake-timers-with-an-in-memory-fetch-407df8136b11
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, fake-timers, react, jsdom, fetch

To test a polling React page end to end with vi.useFakeTimers() (vitest 5, jsdom, React 19), stub global fetch with an async function that returns real `new Response(jsonText)` objects built from in-process server logic: no socket, so every answer settles in microtasks and `await act(() => vi.advanceTimersByTimeAsync(ms))` drives polls, timers and renders deterministically. A real HTTP server does not work here because socket I/O is not advanced by fake timers. Two gotchas: default fake timers also fake `performance.now()` and `Date`, so timing a step inside the test reads 0 or fake time; and vitest hides console.log of passing tests unless you pass `--silent=false`.
