cypress-realworld-app icon indicating copy to clipboard operation
cypress-realworld-app copied to clipboard

Intercept doesn't work in beforeEach

Open lalicia opened this issue 2 years ago • 1 comments

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 :)

lalicia avatar Jul 10 '23 19:07 lalicia