jest-fetch-mock
jest-fetch-mock copied to clipboard
Mock conditionals
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.
Hey @ivan-kleshnin currently there isn't a way to do this, but this seems like an interesting topic to explore.
+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.
I've come up with an initial pass at this issue in #102. Let me know if you have any thoughts @jefflau!