0PricingLogin
React Academy · Lesson

Mocking Fetch & Timers

Stub network with fetch mocks and control time with fake timers; write stable, fast tests for async components.

Why mock network & time

Goal: Mock async work so tests are fast and reliable.

  • Stub fetch responses
  • Control timers with fake clocks
  • Assert using findBy*/waitFor

Common patterns

  • fetch: spyOn global.fetch → mockResolvedValue
  • Timers: vi.useFakeTimers(); advance timers
  • Prefer findBy* for async DOM

All lessons in this course

  1. React Testing Library + Vitest/Jest Setup
  2. Queries, Events, Assertions — Forms & Async UI
  3. Mocking Fetch & Timers
← Back to React Academy