Stop guessing waits: stub HTTP responses with cy.intercept() in Cypress
Replace cy.server() and cy.route() with cy.intercept() and alias waits to reduce flaky E2E tests.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Replace cy.server() and cy.route() with cy.intercept() and alias waits to reduce flaky E2E tests.
Stub XHR/fetch at the browser boundary with cy.intercept() to make UI tests deterministic — registering, verifying, and recovering from silent pass-through.
Replace flaky waits with deterministic network control using Cypress cy.intercept(): stub responses, synchronize with aliases, and modify requests to cover error and slow-network states.
cy.intercept() makes Cypress tests deterministic by stubbing or spying on HTTP requests — but heavy stubbing can drift from the real API. Here's how to use it well.
Replace real API calls with deterministic stubs in Cypress using cy.intercept(). Follow a clear workflow to define, trigger, and verify interceptions, simulate errors, and recover from common pitfalls.
Learn how to use Cypress.io's cy.intercept to stub network requests, isolate frontend tests, and avoid flaky CI builds.
Fixed cy.wait(ms) delays are the top cause of flaky Cypress suites. Learn how cy.intercept() with aliased routes fixes timing, enables deterministic stubbing, and where its limits are.
Background In Cypress, cy.intercept is commonly used to stub or monitor network requests during tests. The official documentation states that intercepts are automatically cleared after each test case unless explicitly cleared earlier. However, many developers wish for intercepts to persist across multiple tests to avoid redefining identical stubs, and the Cy
Cypress testRetries re-executes the whole test including before and beforeEach hooks when a run fails. The documented behavior means any real side-effecting operation performed during the attempt, such as a UI form submission or cy.request POST, can be executed again on retry. Cypress clears cookies and local storage between attempts but does not roll back s