-
Notifications
You must be signed in to change notification settings - Fork 247
Closed
Description
Simple sugar function for:
jest.fn().mockReturnValue(Promise.resolve(value));Useful to mock async functions in async tests:
test('async test', async () => { const asyncMock = jest.fn().mockResolvedValue(43); await asyncMock(); // 43 });
Refs:
- https://facebook.github.io/jest/docs/en/mock-function-api.html#mockfnmockresolvedvaluevalue
- https://facebook.github.io/jest/docs/en/mock-function-api.html#mockfnmockresolvedvalueoncevalue
- https://facebook.github.io/jest/docs/en/mock-function-api.html#mockfnmockrejectedvaluevalue
- https://facebook.github.io/jest/docs/en/mock-function-api.html#mockfnmockrejectedvalueoncevalue
innay, kWozniak-tt, SchroederSteffen, ivdma and ahilke