I am testing a Gatsby app/site with Cypress. It makes a number of calls to an api from a variety of pages. We have taken the decision to stub and mock all these requests, so our tests should never hit our live api.
I was looking for a way to have Cypress error if a request to any of our API endpoints was made that wasn't stubbed, and I found the force404
config param (docs) for cy.server
which enforces a 404 to be returned for any routes that aren't stubbed. This works well, but actually too well. Gatsby uses XHRs internally to preload other pages (amongst other things) and this causes all those to return 404s as well, effectively breaking the app.
Is there a way to configure cy.server
to only return 404s from routes that aren't stubbed that are on a particular domain. For example if our api domain is api.example.com
. Is there a way to configure cy.server
to return a 404 only for requests to api.example.com
that are not stubbed, while leaving requests to other domains, or the same domain untouched.
Aucun commentaire:
Enregistrer un commentaire