question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cy.route2 routes not being matched with external URLs

See original GitHub issue

First 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');

image

Specifying url:

cy.route2({ url: 'https://example.cypress.io/example-path', method: 'GET' }, { fixture: 'example.json' }).as('example');

image

Specifying hostname:

cy.route2({ hostname: 'example.cypress.io', method: 'GET' }, { fixture: 'example.json' }).as('example');

image

Specifying hostname and path:

cy.route2({ hostname: 'example.cypress.io', path: '/example-path', method: 'GET' }, { fixture: 'example.json' }).as('example');

image

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:closed
  • Created 3 years ago
  • Reactions:24
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
troythackercommented, Sep 19, 2020

I am also seeing this behavior in the new 5.2.0 version.

7reactions
flotwigcommented, Sep 24, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found