Provides the ability to await until a function has been invoked. Created to help test asynchronous functions without having to wait for them to finish, namely Temporal.io workflows.
Imagine you have an asynchronous function named systemUnderTest
.
You wish to test systemUnderTest
without waiting for the returned promise to resolve.
This example waits for two calls to a mock function:
const mock = jest.fn();
const {proxy, nextCall} = awaitInvocation(mock);
systemUnderTest(proxy); // note: no await
await nextCall();
await nextCall();
expect(mock).toHaveBeenCalledTimes(2);
👤 David Leston
- Website: https://DavidLeston.com
- Github: @davidleston
Give a ⭐️ if this project helped you!