I am writing an integration test with cypress and having trouble with minimatch pattern.
I have two endpoints that I need to stub.
/users/1
and /users/1/profile
.
The way I am trying to mock these two endpoints with cy.intercept()
is the following.
For the first url, /users/1
, I tried cy.intercept('GET', '/users/1', {})
.
For the secton url , /users/1/profile
, I tried cy.intercept('GET', '/users/1/profile', {})
.
The problem is that the first pattern intercepts twice.
Can I get some help on this?? Thanks.
I, too, fell into this problem when first using
cy.intercept
. The solution is to pass in aRouteMatcher
object to the method. In particular, you'll want to use the last method signature from the image below:In the
RouteMatcher
object, you can specify apath
property. Here's the description of thepath
property:In essence, using the
path
property of theRouteMatcher
object does an exact match against the given string, whereas theurl
parameter in the 1st and 2nd method signatures does a substring match against the given string.So what you'll want is:
In my opinion, this slight change from Cypress between the
cy.route
andcy.intercept
methods was weird and a bit unexpected on the first run-through.