Skip to content

Latest commit

 

History

History
 
 

stubbing-spying__intercept

Stubbing application requests using cy.intercept

  • control-clock-spec.js shows how to reply with different responses to an ajax request
  • count-spec.js uses cy.intercept and cy.spy|cy.stub combination to count the number of intercepted network calls
  • form-spec.js shows how to stub form submission request and verify the submitted form fields (application/x-www-form-urlencoded or multipart/form-data)
  • headers-spec.js adds a custom header to the outgoing request. Note that this request header won't be shown by the browser's Network tab, since the request has already left the browser.
  • html-css-spec.js modifies the page itself and changes the CSS requested by the page.
  • image-spec.js shows how to spy and stub static resources like images
  • jsonp-spec.js shows how to spy on or stub a JSONP data request
  • loading-element-spec.js shows how to test the loading element that appears while the app is fetching the data
  • matching-spec.js shows how the same request can match multiple cy.intercept matchers
  • ping-spec.js shows how to confirm <a ping="/track"> really is making a POST request
  • 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
  • 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, event depending on the object sent
  • 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