jest-fetch-mock icon indicating copy to clipboard operation
jest-fetch-mock copied to clipboard

Mock conditionals

Open ivan-kleshnin opened this issue 6 years ago • 3 comments

Is there a way to mock conditionally for cases with parallel requests? For example:

fetch.mockResponseOnce(...) // mocks first result, assuming "/blog/"
fetch.mockResponseOnce(...) // mocks second result, assuming "/blog/post/"

/*
now what if you don't know whether "/blog/" OR "/blog/post/" will be called first...
*/

I imagine something like

fetch.on("/blog/").mockResponseOnce(...)
fetch.on("/blog/post/").mockResponseOnce(...)

but maybe there's an alternative approach already. Searching through docs, issues and Google didn't highlight this for me.

ivan-kleshnin avatar Nov 16 '18 08:11 ivan-kleshnin

Hey @ivan-kleshnin currently there isn't a way to do this, but this seems like an interesting topic to explore.

jefflau avatar Nov 22 '18 12:11 jefflau

+1 to this. Currently needing to test a handful of requests to different endpoints that happen in no particular order, and would love to have something to handle that.

eatspaint avatar Jan 04 '19 00:01 eatspaint

I've come up with an initial pass at this issue in #102. Let me know if you have any thoughts @jefflau!

eatspaint avatar Jan 04 '19 04:01 eatspaint