-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Open
Labels
Description
🚀 Feature Proposal
Add a matcher for spies that spy on async functions.
Motivation
When spying on async functions, the received value of expect(spy).toHaveReturnedWith
is always a Promise. This causes the tests to fail.
One way to go around this is to manually retrieve the Promise from the mock's metadata and await it.
It would be nice if expect(spy).toHaveReturnedWith
automatically handles this or a new matcher (for example, toHaveResolvedWith) is created specifically for this use case.
Example
expect(asyncFunctionSpy).toHaveResolvedWith('expected')
Pitch
As helpful as the toHaveReturnedWith
matcher when dealing with async code.
amitbeck and Lucas-C