Understanding how to stub requests
Now that we know what XHR requests are, it is important to know how we can help Cypress test XHR requests, and better still, how we can avoid actual responses from the server and instead create our own "fake" responses that our application will interpret as the actual responses that have been sent from the server. In this section, we will look at how we can stub XHR requests to the server, when to stub requests, and the impact of stubbing server requests in our tests.
Stubbing XHR requests
Cypress gives the flexibility of allowing users to either have their requests reach the server, or instead have stubbed responses when the requests to the server endpoints are made by the application. With the flexibility of Cypress, we even have the ability to allow some requests to pass through to the server while denying other requests and stubbing them instead. Stubbing XHR responses adds a layer of control to our tests. With stubbing, we are...