Simplified code making it easier to read

This commit is contained in:
Alejandro Celaya
2019-04-19 12:52:55 +02:00
parent 28ca54547e
commit 33d67cbe3d
8 changed files with 40 additions and 74 deletions

View File

@@ -39,20 +39,12 @@ describe('selectedServerReducer', () => {
it('dispatches proper actions', () => {
const dispatch = jest.fn();
const expectedDispatchCalls = 2;
selectServer(ServersServiceMock)(serverId)(dispatch);
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,
},
]);
expect(dispatch).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenNthCalledWith(1, { type: RESET_SHORT_URL_PARAMS });
expect(dispatch).toHaveBeenNthCalledWith(2, { type: SELECT_SERVER, selectedServer });
});
it('invokes dependencies', () => {

View File

@@ -52,7 +52,7 @@ describe('serverReducer', () => {
expect(result).toEqual(expectedFetchServersResult);
expect(ServersServiceMock.createServer).toHaveBeenCalledTimes(1);
expect(ServersServiceMock.createServer.mock.calls[0]).toEqual([ serverToCreate ]);
expect(ServersServiceMock.createServer).toHaveBeenCalledWith(serverToCreate);
expect(ServersServiceMock.listServers).not.toHaveBeenCalled();
expect(ServersServiceMock.deleteServer).not.toHaveBeenCalled();
expect(ServersServiceMock.createServers).not.toHaveBeenCalled();
@@ -69,7 +69,7 @@ describe('serverReducer', () => {
expect(ServersServiceMock.createServer).not.toHaveBeenCalled();
expect(ServersServiceMock.createServers).not.toHaveBeenCalled();
expect(ServersServiceMock.deleteServer).toHaveBeenCalledTimes(1);
expect(ServersServiceMock.deleteServer.mock.calls[0]).toEqual([ serverToDelete ]);
expect(ServersServiceMock.deleteServer).toHaveBeenCalledWith(serverToDelete);
});
});
@@ -82,7 +82,7 @@ describe('serverReducer', () => {
expect(ServersServiceMock.listServers).not.toHaveBeenCalled();
expect(ServersServiceMock.createServer).not.toHaveBeenCalled();
expect(ServersServiceMock.createServers).toHaveBeenCalledTimes(1);
expect(ServersServiceMock.createServers.mock.calls[0]).toEqual([ serversToCreate ]);
expect(ServersServiceMock.createServers).toHaveBeenCalledWith(serversToCreate);
expect(ServersServiceMock.deleteServer).not.toHaveBeenCalled();
});
});

View File

@@ -1,4 +1,3 @@
import { last } from 'ramda';
import ServersService from '../../../src/servers/services/ServersService';
describe('ServersService', () => {
@@ -68,10 +67,7 @@ describe('ServersService', () => {
expect(storageMock.get).toHaveBeenCalledTimes(1);
expect(storageMock.set).toHaveBeenCalledTimes(1);
const setLastCallLastArg = last(last(storageMock.set.mock.calls));
expect(setLastCallLastArg).toEqual({
expect(storageMock.set).toHaveBeenCalledWith(expect.anything(), {
abc123: { id: 'abc123' },
def456: { id: 'def456' },
ghi789: { id: 'ghi789' },
@@ -88,10 +84,7 @@ describe('ServersService', () => {
expect(storageMock.get).toHaveBeenCalledTimes(1);
expect(storageMock.set).toHaveBeenCalledTimes(1);
const setLastCallLastArg = last(last(storageMock.set.mock.calls));
expect(setLastCallLastArg).toEqual({
expect(storageMock.set).toHaveBeenCalledWith(expect.anything(), {
abc123: { id: 'abc123' },
def456: { id: 'def456' },
ghi789: { id: 'ghi789' },
@@ -109,10 +102,7 @@ describe('ServersService', () => {
expect(storageMock.get).toHaveBeenCalledTimes(1);
expect(storageMock.set).toHaveBeenCalledTimes(1);
const setLastCallLastArg = last(last(storageMock.set.mock.calls));
expect(setLastCallLastArg).toEqual({
expect(storageMock.set).toHaveBeenCalledWith(expect.anything(), {
def456: { id: 'def456' },
});
});