Allow dynamically matching requests with a function
See original GitHub issueTo allow highly flexible matching of which requests you want to stub, we could add the option to accept a function instead of a fixed method/URL. This would recieve the request object (or some wrapper around it). The motivation is that I have and SPA that uses a GraphQL backend where all requests have the same URL and I want to filter them by the query name which is sent as a parameter in the POST body.
cy.route({
matcher: (request) => !! request.body.match(//)
})
Issue Analytics
- State:
- Created 7 years ago
- Reactions:45
- Comments:14 (3 by maintainers)
Top Results From Across the Web
How to Use Dynamic Parameters for Intelligent Mock Responses
Dynamic parameters enable you to pass values from incoming requests to responses, as well as execute logic within your responses.
Read more >Using Parameters of One Request to Dynamically Change the ...
What I probably need to do is do a findAll() on the requests, find the one that matches with the request, and retrieve...
Read more >Dynamically Route Viewer Requests to Any Origin Using ...
Now you can programmatically define the origin based on logic in your Lambda function. This enables you to route requests to different ...
Read more >Dynamically Selecting API Gateway Back Ends Based on ...
A common requirement is to route requests sent to the same API gateway to different back ends based on elements in the request....
Read more >Dynamic methods for matching requests to suppliers in ...
Peer-to-peer transportation platforms dynamically match requests (e.g., a ride, ... cannot be certain that a supplier will accept an offered request.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for the update @jennifer-shehane
I’ve been able to find a work-around that provides me with the required functionality. I feel it’s a bit hacky but it works for now.
My
support/index.js
contains:And the following in my
support/commands.js
The above can be used as follows:
HTH anybody with the same requirements.
Opened a PR for this feature request after spending way to much time trying to hack it in in userland. This should be supported out of the box IMO.
https://github.com/cypress-io/cypress/pull/3984