DEV Community

Bruno Antunes
Bruno Antunes

Posted on

Please don't mock SWR, Fetch or Axios in your unit/integration tests

Please don't mock SWR, Fetch or Axios in your unit/integration tests.

In this video you will learn how to test components that use "useSWR" without doing jest.mock("swr") or jest.mock("axios") or jest.spyOn(window, 'fetch') in order to give you more confidence on your tests :)

We are going to use MSW (Mock Service Worker) in order to mock the HTTP call itself, not your favorite fetching library

Discussion (2)

Collapse
braydoncoyer profile image
Braydon Coyer

A huge help, Bruno! Loving this series, and some of the best out there for React testing! This area has a HUGE void, and I’m glad you’re filling it!

Collapse
bmvantunes profile image
Bruno Antunes Author

Thank you Braydon :)