feat(intercept): support regexp matcher with middleware intercepts #16390
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
User facing changelog
cy.intercept
accepts a RegExp matcher forurl
now when route matcher options are passed to it as the second argument.Additional details
When upgrading to Cypress 7 I had to figure out how to add a delay to one of our requests. In Cypress 6 we were just adding such intercept before other intercepts but now they are matched in the reverse order.
So we had a code like this:
but since this request was done immediately on startup of our application we couldn't just reorder those commands - because
cy.visit
only resolves after theload
event.So I've figured out that
{ middleware: true }
can actually save me here and to my surprise this both didn't work and didn't typecheck correctly:The work around this is quite simple:
But I think that the DX could be improved here by just allowing a regexp matcher, unless there is a strong reason why this is not supported.
How has the user experience changed?
It has been improved since now
cy.intercept
will accept more combination of arguments.PR Tasks
cypress-documentation
?type definitions
?