-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pausing and resuming intercepted requests on demand #16472
Comments
Have you tried passing an array of aliases to cy.intercept('/api/a').as('a');
cy.intercept('/api/b').as('b');
cy.visit('http://localhost:3000');
cy.wait(['@a', '@b']).then(
(interceptions) => {
// interceptions will now be an array of matching requests
// interceptions[0] <-- a
// interceptions[1] <-- b
}
) The response resolution will always be defined in the cy.intercept('/api/a', (req) => {
// do something with the intercepted request
}) |
With two requests I have two possible orders of resolution and I want it to be deterministic for each test case.
This is my main point. I now have to:
Having ability to resolve requests deterministically as test case goes without need to juggle delays would be wonderful EDIT: I forgot to add another benefit of stopping everything and resolving by case basis on demand. If I have multiple requests for the same route with different outcomes. Let's say I'm fetching user profile. To properly test, I need to respond with error and then retry either with error again, or with data. |
You may be interested in the |
@ezhikov It may be helpful to see the solutions with |
^ yeah, your second proposal -
- is exactly how I'd recommend solving this problem, so if it's not working, there might be some bug/something we can document better. |
I'll make suitable demo to illustrate what I want to achieve this weekend |
Hi, I think I've faced a very similar issue. My app is allowing user to ask for data with some custom filter, the query is passed via http request. The user can ask multiple times in a row for data with different filters, but only the most recent query is meaningful. So with scenario below
App is supposed to ignore the 4th point (as opposed to loading the dataA into the app). I couldn't find a way to force the order of responses, other than adding a delay. Something like
Now this solution is a bit sketchy - it is slow, and doesn't really guarantee the order of responses. |
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
This issue has been closed due to inactivity. |
What would you like?
I'd like ability to pause intercepted request indefinitely and then resume it at will when I need with response which I need.
Why is this needed?
I'm using @xstate/test for testing. It generates scenarios based on states and events with different paths. Problem I encounter is that when scenario includes race condition, I can't guarantee order of execution inside application. For example, I have two requests:
A
andB
. In one scenarioA
should settle first, and in anotherB
should settle first.Approaches I tried to solve this problem:
Another issue that I have is that there can be multiple responses for request, depending on scenario. Right now I have to inspect each scenario beforehand and stub responses. I'd like to do it on demand when I need to settle response.
If we abstract from model based testing, I'd like to write something like this:
The text was updated successfully, but these errors were encountered: