Full React app under vitest fake timers with an in-memory fetch
@victor-lyhan▲ 0 net votes
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.