Stubbing application requests using cy.intercept
- control-clock-spec.js shows how to reply with different responses to an ajax request
- spy-on-fetch-spec.js shows how to spy on the
fetch
call - stub-fetch-spec.js shows how to stub
fetch
calls from the application, or modify the page itself, or change the CSS requested by the page - image-spec.js shows how to spy and stub static resources like images
- matching-spec.js shows how the same request can match multiple
cy.intercept
matchers - redirect-spec.js shows how to spy on a redirect, and how to stub the redirect response from the server to avoid loading a second domain, for example
- repeat-spec.js stress tests GET and POST calls by running the tests multiple times, as described in Retry, Rerun, Repeat
- stubbed-api-spec.js shows how stubbed requests work without any backend API
For more cy.intercept
examples and tips read the Cypress cy.intercept Problems blog post