Skip to content
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

Migrate from cy.route to cy.intercept - requests mocked via MSW are not intercepted anymore #14745

Open
ElisaDellaC opened this issue Jan 26, 2021 · 13 comments
Labels
prevent-stale mark an issue so it is ignored by stale[bot] topic: cy.intercept()

Comments

@ElisaDellaC
Copy link

Current behavior

For our component tests we use storybook to render the component in isolation and cypress to run tests against it.
We have mocking done at Storybook level using Mock Service Worker

using cy.route we could successfully spy on the mocked requests, once migrating to cy.intercept even if I can see the requests in the network tab of the developer tools, they are not intercepted by the cy.intercept

Desired behavior

If this is a wanted change in behaviour, could you please advice on a workaround to migrate to cy.intercept that supports our use case?

Test code to reproduce

https://github.com/rosahealth/mws-cypress-storybook

Versions

Migrate from version 5.0.0 to 6.3.0

@Wimpert
Copy link

Wimpert commented Feb 17, 2021

I also have the same issue !

@icruzr93
Copy link

I'm facing the same issue, not a big deal on my side but I would like to know the workaround about this.

@ElisaDellaC ElisaDellaC changed the title Migrate from cy.route to cy.intercept - requests mocked via MSW are not intercepted Migrate from cy.route to cy.intercept - requests mocked via MSW are not intercepted anymore Feb 25, 2021
@mmanista-bynd
Copy link

mmanista-bynd commented Jun 30, 2021

The issue appears to still exist in version 7.6.0.

To add up to that - it's very unlikely that there is any race condition between the msw and the test itself, because the exact same scenario works perfectly fine when using cy.route instead of cy.intercept.

@Wimpert
Copy link

Wimpert commented Jun 30, 2021

Since cypress intercept does not actually incercept the request in the browser, but in a proxy outside the browser (see docs). This kind of behaviour is expected

@mmanista-bynd
Copy link

Feels like this might need to be stated more clearly in the docs as it's not that obvious (especially when we reach the point where we need to migrate to cy.intercept), probably with some notes on how to tackle this

@jennifer-shehane jennifer-shehane added topic: cy.intercept() stage: needs investigating Someone from Cypress needs to look at this labels Jul 20, 2021
@ArtifexEt
Copy link

Does this mean that way of intercept data will no longer be supported? Or will there be another way?

@mataspetrikas
Copy link

I can confirm that the problem still persists in 2022.
I'm using the current versions of msw 0.36.8 and cypress 9.3.1.
cy.route captures the mocked graphql request, but cy.intercept doesn't.
as a resut we'll try to stick with cy.route as long as we can.

@cypress-bot cypress-bot bot added stage: backlog and removed stage: needs investigating Someone from Cypress needs to look at this labels Apr 29, 2022
@pascalvos
Copy link

any update on this?

@Wimpert
Copy link

Wimpert commented May 5, 2022

any update on this?

I don't think this need fixing, since it is expected behaviour.

@mataspetrikas
Copy link

mataspetrikas commented Sep 29, 2022

tested with msw 0.39.2 and cypress 10.9.0, the problem still persists:

  • cy.route() intercepts the mocked requests
  • cy.intercept() doesn't intercept the mocked requests

@s4ms00n9
Copy link

any update on this?

I don't think this need fixing, since it is expected behaviour.

Since it is suggested to switch from cy.route() to cy.intercept(), it rather looks like getting rid of a feature that cy.route() had. I'd also like to know if this issue is going to be investigated further or it is ghoing to be dropped and I need to find a workaround for overwriting a msw response in a test.

@silent-tan
Copy link

yet, same problem, and i need to fork the cypress-msw-intercept to change to fit my case.

@mataspetrikas
Copy link

the latest Cypress release 12.0 removes the cy.server and cy.route methods:
#22126

I have tried using the https://github.com/deshiknaves/cypress-msw-interceptor but it doesnt seem to be able to priduce an alias that can be captured :(

@nagash77 nagash77 added the prevent-stale mark an issue so it is ignored by stale[bot] label Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prevent-stale mark an issue so it is ignored by stale[bot] topic: cy.intercept()
Projects
None yet
Development

No branches or pull requests