UNPKG

@async-fn/jest

Version:

Additional methods to jest.fn to introduce "late resolve" of promises returned by mock functions. This allows tests that read chronologically, like a story.

22 lines (17 loc) 675 B
import { asyncFnFor, mockImplementationUsageErrorMessage, } from '@async-fn/core'; export default (...args) => { const mockFunctionInstance = asyncFnFor({ mockFunctionFactory: jest.fn, })(...args); mockFunctionInstance.mockImplementation = throwMockImplementationUsageError; mockFunctionInstance.mockImplementationOnce = throwMockImplementationUsageError; mockFunctionInstance.mockReturnValue = throwMockImplementationUsageError; mockFunctionInstance.mockReturnValueOnce = throwMockImplementationUsageError; return mockFunctionInstance; }; const throwMockImplementationUsageError = () => { throw new Error(mockImplementationUsageErrorMessage); };