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.intercept url change not detected during file watching in Cypress open

See original GitHub issue

Current behavior

This issue occurred migrating the Cypress RWA from cy.route to cy.intercept.

A cy.route with a minimatch is converted to use cy.intercept:

Note: Two aliases are defined against the same path (/users)

beforeEach(function () {
    cy.intercept("GET", "/users").as("allUsers");
    cy.intercept("GET", "/users/search*").as("usersSearch");
})

When run in open mode the test fails:

Screen Shot 2020-11-25 at 4 26 11 PM

Migrating from cy.route to cy.intercept requires a glob-match (**) to be added to the beginning of the route.

The glob-match is added without stopping the current run and the file is saved:

beforeEach(function () {
    cy.intercept("GET", "/users").as("allUsers");
    cy.intercept("GET", "**/users/search*").as("usersSearch");
})

The browser refreshes and fails against a different alias:

Screen Shot 2020-11-25 at 4 31 59 PM

Solution Stop the current run and start a fresh run, where the glob-match is honored and the tests pass as expected

Screen Shot 2020-11-25 at 4 36 16 PM

A detailed demo of the issue and the solution is in this Loom:

https://www.loom.com/share/33778ef182bd489c80efa2d941e4e9f1

Desired behavior

When a glob-match is added to a cy.intercept the test runner should reflect that code change during the current run.

Test code to reproduce

See the Loom video and this diff in the RWA against the new-transactions.spec.ts where it can be reproduced: https://github.com/cypress-io/cypress-realworld-app/commit/504652c4561db611d6c54a8a40cdd3fea4db6bb1

Versions

6.0.0

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
joszocommented, Dec 7, 2020

Was just looking into this myself and it appears that cy.intercept does still support mini-match, but you have to pass an object with a pathname attribute including your glob string.

For example:

cy.intercept("GET", "/users/search*").as("usersSearch")

becomes

cy.intercept({
     method: "GET",
     pathname: "/users/search*",
}).as("usersSearch")

It doesn’t work

describe("intercept", () => {
    it("swapi", () => {
        cy.visit('https://swapi.dev/');
        // cy.intercept('GET', '\/api/\people').as('people');

        cy.intercept({
            method: 'get', 
            pathname: '/api/people*'
        }).as('people')
        cy.get('.input-group button').click();
        cy.wait('@people').then(interception => {
            console.log(interception.response.body);
        });
    });
});
1reaction
jonstone904commented, Dec 7, 2020

Was just looking into this myself and it appears that cy.intercept does still support mini-match, but you have to pass an object with a pathname attribute including your glob string.

For example:

cy.intercept("GET", "/users/search*").as("usersSearch")

becomes

cy.intercept({
     method: "GET",
     pathname: "/users/search*",
}).as("usersSearch")
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress cy.intercept Problems - Gleb Bahmutov
Cypress shows XHR calls by default in its Command Log, thus it has nothing to do with our intercept. I always thought NOT...
Read more >
intercept - Cypress Documentation
cy.intercept can be used solely for spying: to passively listen for matching routes and apply aliases to them without manipulating the request or...
Read more >
Troubleshooting | Cypress Documentation
Open Cypress via cypress open · Go to Developer Tools -> View App Data · This will take you to the directory in...
Read more >
Error Messages | Cypress Documentation
We found an error preparing your test file. This message means that Cypress encountered an error when compiling and/or bundling your test file....
Read more >
Migration Guide | Cypress Documentation
Migrating to Cypress 12.0 This guide details the changes and how to change your code to migrate to Cypress version 12.0.
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