Using MSW for both server-side and client-side request mocking #32138
-
I've followed the example here for setting up MSW on my nextjs project. I'm using MSW in my cypress integration test. The initial page load, requests data via GetServerSideProps, which is correctly intercepted by MSW. However, when I trigger subsequent API calls via interacting with the page in my test, they are not intercepted, because only the server-side service worker ever gets set up. The client-side one doesn't. I'm not sure if I'm doing something incorrect on my end, or if it's a flaw in the example code, or if this functionality is even possible to achieve. As a test, I added the Has anyone successfully got this up and running? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Found a nice tutorial here, which helped me realize I had forgotten to run |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Found a nice tutorial here, which helped me realize I had forgotten to run
npx msw init ./public
, so the service worker wasn't accessible to my front-end code. I'll probably create a PR to add that to the example docs, as it's not mentioned there.