Managing Network Requests in Cypress: Choosing Between Intercept and Route
Learn when to use cy.intercept() over the deprecated cy.route() to handle asynchronous network requests, stub API errors, and avoid the pitfalls of contract drift in Cypress.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Learn when to use cy.intercept() over the deprecated cy.route() to handle asynchronous network requests, stub API errors, and avoid the pitfalls of contract drift in Cypress.
Cypress’s <code>cy.intercept</code> lets you stub network calls, making integration tests reliable and fast. This guide shows how to set up intercepts, use aliases for assertions, avoid common pitfalls, and verify that your stubs work.
Learn how to use cy.intercept() to stub API responses in Cypress, eliminating backend flakiness and enabling the testing of edge cases like 500 errors and empty states.
Stub XHR/fetch at the browser boundary with cy.intercept() to make UI tests deterministic — registering, verifying, and recovering from silent pass-through.
Learn how to eliminate flaky E2E tests by using cy.intercept() to stub network requests, manage API state, and synchronize your UI assertions with network behavior.
Learn how to eliminate flaky tests in Cypress using cy.intercept() to stub network requests, handle asynchronous responses with aliases, and simulate server errors.
Learn how to control HTTP requests in Cypress tests with cy.intercept, see a worked example of stubbing a GET endpoint, and understand the trade-offs of over-stubbing.
Learn how to use Cypress.io's cy.intercept to stub network requests, isolate frontend tests, and avoid flaky CI builds.
Flaky network calls in Cypress tests? Use cy.intercept to mock, spy on, or modify HTTP traffic, turning flaky, data‑dependent checks into deterministic, fast tests. Learn how, when, and where to apply it effectively.