MomasVII
MomasVII

Reputation: 5081

cy.intercept is not a function Cypress test

I am copying code from the Cypress docs and have returned this error cy.intercept is not a function

enter image description here

My code is straight from the docs...

describe('My First Test', () => {
  it('Visit Home Page', () => {
      cy.intercept('search/*', [{ item: 'Book 1' }, { item: 'Book 2' }]).as('getSearch')
  }
})

Not sure why this would happen?

Upvotes: 17

Views: 10687

Answers (1)

Ackroydd
Ackroydd

Reputation: 1610

See intercept - history, the functionality has been available since Cypress v5.1.0, it was just called cy.route2() (in case you did not want to upgrade).

Version Changes
6.0.0 Renamed cy.route2() to cy.intercept().
6.0.0 Removed experimentalNetworkStubbing option and made it the default behavior.
5.1.0 Added experimental cy.route2() command under experimentalNetworkStubbing option.

But if you remain at v5.3.0, you will have to add

"experimentalNetworkStubbing": true

to cypress.json.


Version 7.0.0

Release notes say

cy.route2() was previously aliased to cy.intercept(). Now the alias cy.route2() has been removed. Please update usage of cy.route2() to cy.intercept()

Upvotes: 19

Related Questions