Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 425
MomasVII Avatar asked Nov 27 '20 19:11

MomasVII


1 Answers

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

like image 199
Ackroydd Avatar answered Oct 11 '22 19:10

Ackroydd