First replacements of sinon mocks with jest mocks

This commit is contained in:
Alejandro Celaya
2019-04-19 10:29:49 +02:00
parent 2cd6e52e9c
commit f8de069567
11 changed files with 666 additions and 127 deletions

View File

@@ -1,4 +1,3 @@
import * as sinon from 'sinon';
import reducer, {
selectServer,
resetSelectedServer,
@@ -31,31 +30,35 @@ describe('selectedServerReducer', () => {
id: serverId,
};
const ServersServiceMock = {
findServerById: sinon.fake.returns(selectedServer),
findServerById: jest.fn(() => selectedServer),
};
afterEach(() => {
ServersServiceMock.findServerById.resetHistory();
ServersServiceMock.findServerById.mockClear();
});
it('dispatches proper actions', () => {
const dispatch = sinon.spy();
const dispatch = jest.fn();
const expectedDispatchCalls = 2;
selectServer(ServersServiceMock)(serverId)(dispatch);
expect(dispatch.callCount).toEqual(expectedDispatchCalls);
expect(dispatch.firstCall.calledWith({ type: RESET_SHORT_URL_PARAMS })).toEqual(true);
expect(dispatch.secondCall.calledWith({
type: SELECT_SERVER,
selectedServer,
})).toEqual(true);
const [ firstCallArgs, secondCallArgs ] = dispatch.mock.calls;
expect(dispatch).toHaveBeenCalledTimes(expectedDispatchCalls);
expect(firstCallArgs).toEqual([{ type: RESET_SHORT_URL_PARAMS }]);
expect(secondCallArgs).toEqual([
{
type: SELECT_SERVER,
selectedServer,
},
]);
});
it('invokes dependencies', () => {
selectServer(ServersServiceMock)(serverId)(() => {});
expect(ServersServiceMock.findServerById.callCount).toEqual(1);
expect(ServersServiceMock.findServerById).toHaveBeenCalledTimes(1);
});
});
});