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?
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!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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?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!