cy.route2 routes not being matched with external URLs
See original GitHub issueFirst of all, thanks for the work on cy.route2
, it looks like it’s going to make a lot of things much easier to do! I’ve jumped in to try it out and am having some trouble with URLs that are outside of my application (ie, API requests and such).
Current behavior:
If the application sends a request to an external URL:
fetch('https://example.cypress.io/example-path')
In the tests, when cy.route2
is used, it does not appear to be possible to match the request.
Specifying path
:
cy.route2({ path: '/example-path', method: 'GET' }, { fixture: 'example.json' }).as('example');
Specifying url
:
cy.route2({ url: 'https://example.cypress.io/example-path', method: 'GET' }, { fixture: 'example.json' }).as('example');
Specifying hostname
:
cy.route2({ hostname: 'example.cypress.io', method: 'GET' }, { fixture: 'example.json' }).as('example');
Specifying hostname
and path
:
cy.route2({ hostname: 'example.cypress.io', path: '/example-path', method: 'GET' }, { fixture: 'example.json' }).as('example');
Desired behavior:
The request should be matched by the routes, and stubbed accordingly.
Test code to reproduce
https://github.com/blakemann/cypress-test-tiny
Versions
Cypress: 5.1.0 Operating System: MacOS Catalina (10.15.6) Browser: Chrome 85
Issue Analytics
- State:
- Created 3 years ago
- Reactions:24
- Comments:8 (2 by maintainers)
Top Results From Across the Web
intercept - Cypress Documentation
Match the route to a specific HTTP method ( GET , POST , PUT , etc). If no method is defined Cypress will...
Read more >Cypress not matching routes - Stack Overflow
Once I provided the response, the Cypress GUI displayed that it was properly stubbing out the call. Changing this from: cy.route({ method: "POST ......
Read more >cypress-io/cypress - Gitter
Morning everyone, I'm still battling cy.route2! If I specify the url passed to route2 as http://localhost:xxxx/path then it works (I then point my...
Read more >Cypress cy.intercept Problems - Gleb Bahmutov
The problem. The command cy. intercept can match requests using a substring, a minimatch, or a regular expression. By default, it intercepts ...
Read more >Cypress v6: Network control using cy.intercept introduction
In this video, I will give a glimpse of cy.intercept command (see ... a much more powerful replacement for the deprecated cy. route...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am also seeing this behavior in the new 5.2.0 version.
I’ve narrowed down the issue and it seems to only affect HTTPS traffic to a different origin, opened a PR to fix: https://github.com/cypress-io/cypress/pull/8662