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() logs do not display as expected

See original GitHub issue
describe("Test mocking of api requests using route2", () => {
    it("Launch Website and mock meta.json api using route2", () => {
        cy.fixture("meta.json").as("meta.json.mock.response");
        // cy.route2("GET","**/meta.json","@meta.json.mock.response");
        cy.route2(
            "GET",
            "**/meta.json",
            `{
            "loggedIn": true,
            "displayName": "vivek",
            "clubActive": false,
            "flybuysLinked": false,
            "cartItemCount": "100",
            "wishlistItemCount": 1,
            "messageCount": 0
        }`
        );
        homePage.navigateToUrl("https://www.catch.com.au/");
        //WHEN PAGE IS LOADED THE CART COUNT SHOULD BE = 100
    });
});

So couple of issues here:

  1. When I supply the mock json file using alias, the mocking of “/meta.json” doesn’t happen. However when I supply the whole response body it works.
  2. As can be seen in the attached image, when the mocking happens by supplying the response explicitly, the time travel doesn’t indicate it as a (xhr stub)

});

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
vivekbwajcommented, Sep 10, 2020

Thanks so much @flotwig , this worked perfectly. wrt the second part, the issue is that in the time travel window if an xhr is stubbed it shows (xhr stub). However even on successfully stubbing using the solution you provided the time travel window doesn’t depict that the request has been stubbed. As you can see in the attached snapshot it simply says (xhr) for /meta.json call. It should depict (xhr stub)

route2Issue
0reactions
flotwigcommented, Feb 1, 2021

Created issue to track specific implementation https://github.com/cypress-io/cypress/issues/14843

Read more comments on GitHub >

github_iconTop Results From Across the Web

intercept - Cypress Documentation
intercept() route using cy.wait() will yield an object that contains information about the matching request/response cycle. See Using the yielded object for ...
Read more >
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 >
cy.intercept() not stubbing API in Cypress - Stack Overflow
I'm not entirely sure why it's not stubbing (presume you mean the server response is getting through?). In any case, the stubbed response ......
Read more >
A Practical Guide to Intercepting Network Requests in Cypress
In this article, I'd like to walk you through some of the capabilities of Cypress' .intercept() command. It is a super useful tool,...
Read more >
cy.request vs. cy.intercept - DEV Community ‍ ‍
cy.intercept does not make a request, but rather "listens" to requests that occur on the network layer. If we "ask" Cypress to name...
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