mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-14 11:33:51 +00:00
First replacements of sinon mocks with jest mocks
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user