cypress: Intercept doesn't work in beforeEach but it works when I add them to every it()// Some intercepts don't work at all

Current behavior

I defined intercept in beforeEach. Running my test the cypress can’t see my intercept.

The intercepts work when I add them to every it section.

Desired behavior

Cypress should see the intercept from beforeEach. I migrated my cypress (and all tests) from the 9.7 version to 12.5.1; previously, I didn’t have a problem with beforeEach.

Test code to reproduce

  beforeEach(() => {
    
    cy.restoreLocalStorage();
    cy.intercept("POST", "/api/utility/v2/buildings/*/referenceyears").as("referenceYears");
    
  });

same in it:

it("xxxxx2", function () {
    cy.intercept("POST", "/api/utility/v2/buildings/*/referenceyears").as("referenceYears");
.
.
.
.
}); 

Cypress Version

v12.5.1

Node version

v16.13.2

Operating System

Windows 10 21H2

Debug Logs

No response

Other

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

@alexandersdickinson yes you are right this is a different problem…not related to mine…