New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
One test in the suite is slower than the rest, and it fails whenever the network hiccups, because it's calling the real API.
What you'll have at the end
A component test with fetch mocked and canned data returned, so it never leaves the machine
You need
A component test suite that already renders and queries a component whose data-loading effect calls a small, separately exported async function wrapping fetch, with at least one currently-passing test that leaves that function untouched and therefore reaches the real network.
Not covered
Rendering the component's own loading and error states with Testing Library queries, or intercepting requests below fetch with a dedicated mocking server; this recipe only replaces the loader's own call to fetch.
Leans on
Checked 25 Aug 2026
Part of the Vitest Testing Framework cookbook