You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to spy on an async function that gets called twice; first time I'd like to return a rejected Promise and second time a resolved one. I've read through the comments in #1590; the callFake() is something I use for the simple case where I just want to just return a rejected promise all the time. But that won't work with multiple calls.
Of course, one workaround is to use callFake() in combination with a counter in the test spec and conditionally return a resolved/rejected promise based on the counter. But this reduces the test readability and is just a pain to do more than once. I feel the library should provide a better way.
Expected Behavior
One option could be to introduce a callFakes() that accepts multiple callbacks and calls them in order, similar to what .and.returnValues() does. This way I can conveniently write:
which in my opinion looks good and can even be used for other things.
Note: after writing this I did a search on callFakes and it turned out this has been proposed before, see #1688 (comment). Would this be something we want in jasmine then?
The text was updated successfully, but these errors were encountered:
If possible, I'd still like to see something more general (as I mentioned). This would also allow mixing and matching strategies, instead of requiring the use of a full fake function. To bring those suggestions inline here too, something like:
The first option feels more fluent, but will probably be more complicated to implement. I think either would be fine and I'm happy to discuss what feels better to the community as well.
I am trying to spy on an async function that gets called twice; first time I'd like to return a rejected Promise and second time a resolved one. I've read through the comments in #1590; the callFake() is something I use for the simple case where I just want to just return a rejected promise all the time. But that won't work with multiple calls.
Of course, one workaround is to use callFake() in combination with a counter in the test spec and conditionally return a resolved/rejected promise based on the counter. But this reduces the test readability and is just a pain to do more than once. I feel the library should provide a better way.
Expected Behavior
One option could be to introduce a
callFakes()
that accepts multiple callbacks and calls them in order, similar to what.and.returnValues()
does. This way I can conveniently write:which in my opinion looks good and can even be used for other things.
Note: after writing this I did a search on callFakes and it turned out this has been proposed before, see #1688 (comment). Would this be something we want in jasmine then?
The text was updated successfully, but these errors were encountered: