DEV Community

Discussion on: Clean Up Async Requests in `useEffect` Hooks

Collapse
 
pallymore profile image
Yurui Zhang

I think that might work - however it seems to be testing implementation details - which might be ok if your hook does nothing when aborted.

For testing with fetch I usually use something like sinon's fakeServer. You can intercept requests but not respond to it - unmount the component (or anything that triggers an abort) and check if corresponding side effects are firing (or not firing - e.g. no actions were dispatched)