https://cypress.io logo
When intercepting & modifying response, does the b...
# i-need-help
f
If I was to do something along the lines of
Copy code
cy.intercept(
          "GET",
          "https://mywebsite.com/api/checkout",
          {
            statusCode: 500,
          }
        ).as("checkout500");
I was under the impression that we're just intercepting the traffic, modifying it, and sending it on it's way. Is that traffic still hitting the backend, or are we stopping the request entirely and faking the response altogether? Thanks folks! 🙏
w
Hi! When you provide the
staticResponse
- in this case the object with
statusCode: 500
you are stubbing the response from the backend and the request does not hit your server. Instead, Cypress responds in place of your back end with the data you provide. If you don't pass that object to, the request will go through and hit your real backend, you'll only be spying on the request. You can learn a bit more here https://docs.cypress.io/api/commands/intercept#Syntax about the different arguments that intercept takes and what they do.
f
Ah, thank you! I appreciate it.