DEV Community

Discussion on: Testing a Generic Fetch Item List hook with Mock Service Worker

Collapse
 
rexebin profile image
Rex • Edited

Thank you Guilherme.

It feels like a hack but I think it is not.

It is a very interesting topic to discuss, what msw could have done as a proper solution? If you ask me, I would say it is out of scope for msw. msw provide the infrastructure much like any other API server, it is up to us to return whatever is required.

I think we should not develop the mocked API as if we are developing the real thing, there shouldn't be any complicated logic inside a mocked API. We must take the shortest and simplest route to mimic the responses we expect from a real server. We shouldn't care about how and why the response is returned from the real API.

The tests need to communicate with the mocked API and I think using things like localstorage works is one of the "proper" ways. I could be wrong, @kettanaito what do you think?

Collapse
 
kettanaito profile image
Artem Zakharchenko • Edited

Hey, Rex.

I wouldn't recommend using localStorage for global error handling but, in the end, it's your testing setup and you should evaluate what works best for you, taking benefits/trade-offs into consideration.

I've written a more detailed response to Guilherme above, let me know what you think about it.

Thank you once more for this fantastic article!