If you have used Cypress in the past you should be familiar with the cy.server() and cy.route() methods. They enabled engineers to handle XHR requests within the browser for patterns such as mocking responses, aborting requests, and smart waiting.

Deprecated in Cypress 6.0.0, both cy.route() and cy.server() have been replaced by a new method, cy.intercept()

Released in November of 2020, the cy.intercept() method allows engineers to monitor all network traffic, not just XHR requests.² Simply put, this is a game changer. It places Cypress on the same level as Puppeteer and Playwright in terms of its ability to manipulate requests within the browser.

This tutorial will showcase the power behind the intercept() method by providing examples of request interceptions, mocks, and assertions. We will use the DemoQA Bookstore application as a base.

#javascript

Improve Your End to End Tests with Cypress Intercept
1.90 GEEK