I am trying to write a cypress test that emulates a slow API, so after reading some documentation I came up with this:
before(function() {
cy.server({delay: 5000});
});
beforeEach(() => {
cy.route({
method: "GET",
url: "**/api/**"
});
cy.visit("http://localhost:9000");
});
That should add a 5 second delay to all requests to API, right?
The issue I am seeing is that it is not matching to any requests even through there are plenty of calls to */api/*.
The cypress GUI does however see the route... it is just not matching.
What could be the cause of this?
If you put in the entire route, as it appears in the cypress log, you will probably find that it works.
It seems like the look-ahead globbing isn't implemented very well by minimatch. It delimits fine on the / char but not so well on ? or #, so if you're trying to accommodate query strings, this is probably where you're coming unstuck.
You can use Cypress.minimatch in the console to see what's going on. More info on how to do this in the docs.
Cypress will also accept regexes. Something like /\/api\// should work for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With