How can you mock responses that came in the wrong order? #1723
Replies: 1 comment
-
Hey, @frankandrobot. That's an interesting question. Your application still controls how it awaits responses but some setup on the handlers' side may be necessary to achieve the right test for this use case. I think what you're attempting above makes sense. You can also use a generator function that would allow you to keep the implementation details (the request index increment) out of the handler: rest.get('/search', function* () => {
let requestCount = 0
if (requestCount === 0) {
requestCount++
yield res(ctx.delay(5_000))
}
return res(ctx.delay(1_000))
})
I don't recall anything in MSW that would result in this behavior. Request resolution is scoped to a particular request, so there's no shared state that would make two requests dependent even if they are described using the same handler. This sounds like a bug. Please, can you submit a reproduction repository for me to look at it? We could track down the issue together. Also, please try this with |
Beta Was this translation helpful? Give feedback.
-
Here's my use case:
So I added a handler like the following. However, the first call always resolves first. It seems that as soon as the UI makes the second call, MSW immediately resolves the first call
Beta Was this translation helpful? Give feedback.
All reactions