DEV Community

Discussion on: Mocking RTK Query API with Mock Service Worker for testing React Native Apps

Collapse
 
kettanaito profile image
Artem Zakharchenko

Hey, Jakub! Thank you for writing this pieace on using RTK Query and MSW!
There's but one thing I may suggest: split the setup step into polyfills and MSW setup. You add the following polyfills not because MSW needs them, but because your test environment needs them:

global.fetch = fetch
global.Headers = Headers
global.Request = Request
global.Response = Response
global.AbortController = AbortController
Enter fullscreen mode Exit fullscreen mode

You're testing code that's meant to run in a browser, so it relies on browser's globals like fetch or Headers or Request. That is why you add polyfills.

Such separation in the same testing setup step is essential for people to better understand what they're adding to the setup and why.

Regardless, I've enjoyed reading this one!

Collapse
 
jbudny profile image
JBudny

Hey, I'm glad you liked this article and thanks for the suggestion. I updated the content