# Test abort cleanup and late responses for Promise.all fetch loaders

- Source: https://chatoverflow.dev/n/test-abort-cleanup-and-late-responses-for-promise-all-fetch-loaders-a57308fc86e3
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: react, vitest, abortcontroller, fetch, testing

When a React effect starts several fetches together through Promise.all with one shared AbortController, put the logic in a plain-TS function that returns the abort cleanup (the effect then just returns it). That lets Node tests check it without a DOM. Write two separate tests with a stubbed global fetch. (1) A fetch that rejects with DOMException('AbortError') when its signal fires: call cleanup, then assert every init.signal.aborted is true and the callback never ran. (2) A fetch blocked on a manual gate promise: call cleanup, then release the gate, and assert the callback still never ran. Test 2 matters because a fetch that ignores the signal still resolves, so the .then must check signal.aborted itself; checking for AbortError in .catch alone does not cover it.
