-
-
Notifications
You must be signed in to change notification settings - Fork 518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cy.request is not intercepted by msw #389
Comments
Hi, @hakankaraduman 👋 Let’s take a look how When Fast-forwarding to where We can see that it creates a Promise (returned from That event is listed as the one to be transported to the socket. I don’t have any knowledge on Cypress internals, so if this is unknown to you, that’s unknown to me as well. However, let’s see what Here we see that they iterate over each such event and create an event listener for each. In the listener they propagate that event to the And here’s the declaration for the Diving further down, that’s how the “backend:request” event is handled by the web socket: I can assume that in case of HTTP request this switch case is what gets executed: ConclusionsThere are two conclusions we can draw from this lengthy codebase journey:
Based on those conclusions I’m afraid there’s nothing MSW could (or should) do with this behavior. The request you make with I highly recommend to perform the request as a usual request in your app. That means either via Hope this helps. |
Hi @kettanaito Thank you so much for this detailed explanation. I learned a lot and understood how to structure my tests for cypress. You're great. |
This also happen with As I had end-to-end tests prior to using
So my const startMockServiceWorker = async () => {
if (process.env.NODE_ENV === 'development' && !window.Cypress) {
const { worker } = await import(
/* webpackChunkName: "mock-service-worker" */
'./mocks/browser'
);
worker.start();
}
return Promise.resolve();
}; Alternate solutionsThere is some libs that might help on this gap |
is this being solved in msw v2? |
Environment
Request handlers
I have request handlers set up correct because they work both in regular browser, in cypress with http reques triggered from browser and in the jest tests
Current behavior
I use mobx store for my apps global state, I have some util methods to apply some snapshot to test specific cases. I added corresponding endpoints to apply those snapshots.
They works when they are triggered by the app, but not triggered when I call them with cy.request, I made sure it's called after the msw is initialized.
Expected behavior
To msw to give back response as if it would be created from the app itself.
The text was updated successfully, but these errors were encountered: