Removed remaining usages of sinon

This commit is contained in:
Alejandro Celaya
2019-04-19 12:41:59 +02:00
parent f8de069567
commit 28ca54547e
24 changed files with 231 additions and 402 deletions

View File

@@ -1,4 +1,3 @@
import * as sinon from 'sinon';
import reducer, {
CREATE_SHORT_URL_START,
CREATE_SHORT_URL_ERROR,
@@ -48,12 +47,12 @@ describe('shortUrlCreationReducer', () => {
describe('createShortUrl', () => {
const createApiClientMock = (result) => ({
createShortUrl: sinon.fake.returns(result),
createShortUrl: jest.fn(() => result),
});
const dispatch = sinon.spy();
const dispatch = jest.fn();
const getState = () => ({});
afterEach(() => dispatch.resetHistory());
afterEach(() => dispatch.mockReset());
it('calls API on success', async () => {
const expectedDispatchCalls = 2;
@@ -62,12 +61,12 @@ describe('shortUrlCreationReducer', () => {
const dispatchable = createShortUrl(() => apiClientMock)({});
await dispatchable(dispatch, getState);
const [ firstDispatchCallArgs, secondDispatchCallArgs ] = dispatch.mock.calls;
expect(apiClientMock.createShortUrl.callCount).toEqual(1);
expect(dispatch.callCount).toEqual(expectedDispatchCalls);
expect(dispatch.getCall(0).args).toEqual([{ type: CREATE_SHORT_URL_START }]);
expect(dispatch.getCall(1).args).toEqual([{ type: CREATE_SHORT_URL, result }]);
expect(apiClientMock.createShortUrl).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledTimes(expectedDispatchCalls);
expect(firstDispatchCallArgs).toEqual([{ type: CREATE_SHORT_URL_START }]);
expect(secondDispatchCallArgs).toEqual([{ type: CREATE_SHORT_URL, result }]);
});
it('throws on error', async () => {
@@ -81,12 +80,12 @@ describe('shortUrlCreationReducer', () => {
} catch (e) {
expect(e).toEqual(error);
}
const [ firstDispatchCallArgs, secondDispatchCallArgs ] = dispatch.mock.calls;
expect(apiClientMock.createShortUrl.callCount).toEqual(1);
expect(dispatch.callCount).toEqual(expectedDispatchCalls);
expect(dispatch.getCall(0).args).toEqual([{ type: CREATE_SHORT_URL_START }]);
expect(dispatch.getCall(1).args).toEqual([{ type: CREATE_SHORT_URL_ERROR }]);
expect(apiClientMock.createShortUrl).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledTimes(expectedDispatchCalls);
expect(firstDispatchCallArgs).toEqual([{ type: CREATE_SHORT_URL_START }]);
expect(secondDispatchCallArgs).toEqual([{ type: CREATE_SHORT_URL_ERROR }]);
});
});
});