cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.74k stars 3.16k forks source link

Intercept doesn't work in beforeEach #29405

Open lalicia opened 1 year ago

lalicia commented 1 year ago

I originally posted under this issue where someone had detailed the problem I was having in a different Cypress repository - I was advised to move the post to here by @nagash77.

The issue is NOT in this repository - it's in an archived repository https://github.com/cypress-io/cypress-realworld-testing-blog

The code given in cypress/e2e/practice/network-request.cy.js is:

describe("Network Requests", () => {
  beforeEach(() => {
    cy.intercept("GET", "http://localhost:3000/api/posts", (req) => {
      // this is to disable browser caching
      // https://glebbahmutov.com/blog/cypress-intercept-problems/
      delete req.headers["if-none-match"];
    }).as("posts");

    cy.visit("http://localhost:3000");
  });

The error is: image

Can someone please explain why this is happening and how to fix it? I'm new to Cypress and trying to learn. Thanks :)

sperrye commented 11 months ago

I'm also experiencing this issue after upgrading from 12 to 13. The intercept aliased in the beforeEach was working reliably until the upgrade.