@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.
41 lines (31 loc) • 849 B
JavaScript
import sinon from 'sinon';
import itWorksAsAsyncFn from '@async-fn/core/test-utils/itWorksAsAsyncFn';
import asyncFnForSinon from './asyncFnForSinon';
const fakeTimerConfig = {
toFake: [
'setTimeout',
'setInterval',
'clearTimeout',
'clearInterval',
'Date',
],
};
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', () => {
let clock;
beforeEach(() => {
clock = sinon.useFakeTimers(fakeTimerConfig);
});
afterEach(() => {
clock.restore();
});
itWorksAsAsyncFn(asyncFnForSinon);
});
describe('given no timers', () => {
itWorksAsAsyncFn(asyncFnForSinon);
});
});