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.route doesn't match http calls to .js resources

See original GitHub issue

Current behavior:

image (Notice how # is - because cypress doesn’t think the route is matched)

Interestingly the response handler is still called and the log appears in the console.

Desired behavior:

I’d like the route to match and be able to replace the contents of the resource I’m trying to hijack.

Steps to reproduce:

describe('Route matching fails', function () {
    it('fail matching routes', function () {
        cy.server()
        cy.route({
            method: 'GET',
            url: 'https://consent.snmmd.nl/js/cookiebar-latest.js',
            response: (req) => {
                console.log('[REQUEST] JavaScript');
            }
        })
        cy.visit('http://www.nu.nl')
    })
})

Versions

Cypress 2.1.0 macOS 10.12.6 Node 10.0.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
jennifer-shehanecommented, Aug 8, 2019

Have been thinking about this some. I thought maybe some people would find it useful to hook into the onLoad event and edit the <head> directly, maybe edit the JS resources here.

cy.visit('https://example.cypress.io', {
  onBeforeLoad: (contentWindow) => {
    // contentWindow is the remote page's window object
    contentWindow.document.head
    // I can change the <head> however I want here
    // including <script> src or content
  },
})
0reactions
jennifer-shehanecommented, Apr 1, 2021

cy.route() and cy.server() are now deprecated. We suggest migrating to cy.intercept(). Open a new issue if you encounter one with intercepting calls to .js resources using cy.intercept().

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress doesn't match the newest route stub when url ...
Current behavior: When having multiple routes with paths that match a request, the newest one assigned does not match and a different stub ......
Read more >
Is there a way to assert that a route has not been called in ...
I am currently working around this by asserting that the successful request toast message is not being displayed but it is a flimsy...
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
The command cy.intercept can match requests using a substring, a minimatch, or a regular expression. By default, it intercepts requests ...
Read more >
intercept - Cypress Documentation
Match the route to a specific HTTP method ( GET , POST , PUT , etc). If no method is defined Cypress will...
Read more >
Stubbing and Mocking Network Request with Cypress new ...
We will also see what difference it makes with cy. route () vs cy.intercept() commands This video is part of the course: ...
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