UNPKG

@async-fn/sinon

Version:

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

25 lines (18 loc) 619 B
import sinon from 'sinon'; import itWorksAsAsyncFn from '@async-fn/core/test-utils/itWorksAsAsyncFn'; import asyncFnForSinon from './asyncFnForSinon'; describe('asyncFn with sinon spies', () => { it('returns a sinon spy function', async () => { const mockFunctionInstance = asyncFnForSinon(); expect(mockFunctionInstance.constructor).toBe(sinon.spy().constructor); }); describe('given fake timers', () => { beforeEach(() => { sinon.useFakeTimers(); }); itWorksAsAsyncFn(asyncFnForSinon); }); describe('given no timers', () => { itWorksAsAsyncFn(asyncFnForSinon); }); });