Skip to content
Discussion options

You must be logged in to vote

Hi, @kristojorg.

However, the service worker is not registered until the page runs, at which point my application is also already making network requests I would like to mock.

This sounds like a culprit. I recommend integrating MSW in your app, not the test, so your app never renders until the service worker is up and running (see this). This integration is recommended for a reason, precisely to eliminate the race conditions like the one you're experiencing.

Once that's covered, you can expose window.msw and provide runtime handler overrides. We use this pattern extensively to test MSW itself. Take a look at the /test/browser directory for inspiration.

In the future, I would like to uti…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kettanaito
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants