mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-23 06:56:22 +00:00
First replacements of sinon mocks with jest mocks
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { shallow } from 'enzyme';
|
||||
import { values } from 'ramda';
|
||||
import React from 'react';
|
||||
import * as sinon from 'sinon';
|
||||
import Home from '../../src/common/Home';
|
||||
|
||||
describe('<Home />', () => {
|
||||
@@ -28,11 +27,11 @@ describe('<Home />', () => {
|
||||
});
|
||||
|
||||
it('resets selected server when mounted', () => {
|
||||
const resetSelectedServer = sinon.spy();
|
||||
const resetSelectedServer = jest.fn();
|
||||
|
||||
expect(resetSelectedServer.called).toEqual(false);
|
||||
expect(resetSelectedServer).not.toHaveBeenCalled();
|
||||
createComponent({ resetSelectedServer });
|
||||
expect(resetSelectedServer.called).toEqual(true);
|
||||
expect(resetSelectedServer).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('shows link to create server when no servers exist', () => {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import * as sinon from 'sinon';
|
||||
import createScrollToTop from '../../src/common/ScrollToTop';
|
||||
|
||||
describe('<ScrollToTop />', () => {
|
||||
let wrapper;
|
||||
const window = {
|
||||
scrollTo: sinon.spy(),
|
||||
scrollTo: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -17,13 +16,13 @@ describe('<ScrollToTop />', () => {
|
||||
|
||||
afterEach(() => {
|
||||
wrapper.unmount();
|
||||
window.scrollTo.resetHistory();
|
||||
window.scrollTo.mockReset();
|
||||
});
|
||||
|
||||
it('just renders children', () => expect(wrapper.text()).toEqual('Foobar'));
|
||||
|
||||
it('scrolls to top when location changes', () => {
|
||||
wrapper.instance().componentDidUpdate({ location: { href: 'bar' } });
|
||||
expect(window.scrollTo.calledOnce).toEqual(true);
|
||||
expect(window.scrollTo).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { identity } from 'ramda';
|
||||
import sinon from 'sinon';
|
||||
import createServerConstruct from '../../src/servers/CreateServer';
|
||||
|
||||
describe('<CreateServer />', () => {
|
||||
let wrapper;
|
||||
const ImportServersBtn = () => '';
|
||||
const createServerMock = sinon.fake();
|
||||
const createServerMock = jest.fn();
|
||||
const historyMock = {
|
||||
push: sinon.fake(),
|
||||
push: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
createServerMock.resetHistory();
|
||||
historyMock.push.resetHistory();
|
||||
createServerMock.mockReset();
|
||||
|
||||
const CreateServer = createServerConstruct(ImportServersBtn);
|
||||
|
||||
@@ -44,8 +42,8 @@ describe('<CreateServer />', () => {
|
||||
return '';
|
||||
} });
|
||||
|
||||
expect(createServerMock.callCount).toEqual(1);
|
||||
expect(historyMock.push.callCount).toEqual(1);
|
||||
expect(createServerMock).toHaveBeenCalledTimes(1);
|
||||
expect(historyMock.push).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('updates state when inputs are changed', () => {
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import sinon from 'sinon';
|
||||
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
|
||||
import DeleteServerModal from '../../src/servers/DeleteServerModal';
|
||||
|
||||
describe('<DeleteServerModal />', () => {
|
||||
let wrapper;
|
||||
const deleteServerMock = sinon.fake();
|
||||
const historyMock = { push: sinon.fake() };
|
||||
const toggleMock = sinon.fake();
|
||||
const deleteServerMock = jest.fn();
|
||||
const historyMock = { push: jest.fn() };
|
||||
const toggleMock = jest.fn();
|
||||
const serverName = 'the_server_name';
|
||||
|
||||
beforeEach(() => {
|
||||
toggleMock.resetHistory();
|
||||
deleteServerMock.resetHistory();
|
||||
historyMock.push.resetHistory();
|
||||
deleteServerMock.mockReset();
|
||||
toggleMock.mockReset();
|
||||
historyMock.push.mockReset();
|
||||
|
||||
wrapper = shallow(
|
||||
<DeleteServerModal
|
||||
@@ -48,9 +47,9 @@ describe('<DeleteServerModal />', () => {
|
||||
|
||||
cancelBtn.simulate('click');
|
||||
|
||||
expect(toggleMock.callCount).toEqual(1);
|
||||
expect(deleteServerMock.callCount).toEqual(0);
|
||||
expect(historyMock.push.callCount).toEqual(0);
|
||||
expect(toggleMock).toHaveBeenCalledTimes(1);
|
||||
expect(deleteServerMock).not.toHaveBeenCalled();
|
||||
expect(historyMock.push).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('deletes server when clicking accept button', () => {
|
||||
@@ -58,8 +57,8 @@ describe('<DeleteServerModal />', () => {
|
||||
|
||||
acceptBtn.simulate('click');
|
||||
|
||||
expect(toggleMock.callCount).toEqual(1);
|
||||
expect(deleteServerMock.callCount).toEqual(1);
|
||||
expect(historyMock.push.callCount).toEqual(1);
|
||||
expect(toggleMock).toHaveBeenCalledTimes(1);
|
||||
expect(deleteServerMock).toHaveBeenCalledTimes(1);
|
||||
expect(historyMock.push).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
import React from 'react';
|
||||
import sinon from 'sinon';
|
||||
import { shallow } from 'enzyme';
|
||||
import { UncontrolledTooltip } from 'reactstrap';
|
||||
import importServersBtnConstruct from '../../../src/servers/helpers/ImportServersBtn';
|
||||
|
||||
describe('<ImportServersBtn />', () => {
|
||||
let wrapper;
|
||||
const onImportMock = sinon.fake();
|
||||
const createServersMock = sinon.fake();
|
||||
const onImportMock = jest.fn();
|
||||
const createServersMock = jest.fn();
|
||||
const serversImporterMock = {
|
||||
importServersFromFile: sinon.fake.returns(Promise.resolve([])),
|
||||
importServersFromFile: jest.fn().mockResolvedValue([]),
|
||||
};
|
||||
const fileRef = {
|
||||
current: { click: sinon.fake() },
|
||||
current: { click: jest.fn() },
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
onImportMock.resetHistory();
|
||||
createServersMock.resetHistory();
|
||||
serversImporterMock.importServersFromFile.resetHistory();
|
||||
fileRef.current.click.resetHistory();
|
||||
onImportMock.mockReset();
|
||||
createServersMock.mockReset();
|
||||
serversImporterMock.importServersFromFile.mockClear();
|
||||
fileRef.current.click.mockReset();
|
||||
|
||||
const ImportServersBtn = importServersBtnConstruct(serversImporterMock);
|
||||
|
||||
@@ -40,7 +39,7 @@ describe('<ImportServersBtn />', () => {
|
||||
|
||||
btn.simulate('click');
|
||||
|
||||
expect(fileRef.current.click.callCount).toEqual(1);
|
||||
expect(fileRef.current.click).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('imports servers when file input changes', (done) => {
|
||||
@@ -49,9 +48,9 @@ describe('<ImportServersBtn />', () => {
|
||||
file.simulate('change', { target: { files: [ '' ] } });
|
||||
|
||||
setImmediate(() => {
|
||||
expect(serversImporterMock.importServersFromFile.callCount).toEqual(1);
|
||||
expect(createServersMock.callCount).toEqual(1);
|
||||
expect(onImportMock.callCount).toEqual(1);
|
||||
expect(serversImporterMock.importServersFromFile).toHaveBeenCalledTimes(1);
|
||||
expect(createServersMock).toHaveBeenCalledTimes(1);
|
||||
expect(onImportMock).toHaveBeenCalledTimes(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import * as sinon from 'sinon';
|
||||
import { values } from 'ramda';
|
||||
import reducer, {
|
||||
createServer,
|
||||
@@ -15,10 +14,10 @@ describe('serverReducer', () => {
|
||||
};
|
||||
const expectedFetchServersResult = { type: FETCH_SERVERS, payload };
|
||||
const ServersServiceMock = {
|
||||
listServers: sinon.fake.returns(payload),
|
||||
createServer: sinon.fake(),
|
||||
deleteServer: sinon.fake(),
|
||||
createServers: sinon.fake(),
|
||||
listServers: jest.fn(() => payload),
|
||||
createServer: jest.fn(),
|
||||
deleteServer: jest.fn(),
|
||||
createServers: jest.fn(),
|
||||
};
|
||||
|
||||
describe('reducer', () => {
|
||||
@@ -28,10 +27,10 @@ describe('serverReducer', () => {
|
||||
|
||||
describe('action creators', () => {
|
||||
beforeEach(() => {
|
||||
ServersServiceMock.listServers.resetHistory();
|
||||
ServersServiceMock.createServer.resetHistory();
|
||||
ServersServiceMock.deleteServer.resetHistory();
|
||||
ServersServiceMock.createServers.resetHistory();
|
||||
ServersServiceMock.listServers.mockClear();
|
||||
ServersServiceMock.createServer.mockReset();
|
||||
ServersServiceMock.deleteServer.mockReset();
|
||||
ServersServiceMock.createServers.mockReset();
|
||||
});
|
||||
|
||||
describe('listServers', () => {
|
||||
@@ -39,10 +38,10 @@ describe('serverReducer', () => {
|
||||
const result = listServers(ServersServiceMock)();
|
||||
|
||||
expect(result).toEqual(expectedFetchServersResult);
|
||||
expect(ServersServiceMock.listServers.calledOnce).toEqual(true);
|
||||
expect(ServersServiceMock.createServer.called).toEqual(false);
|
||||
expect(ServersServiceMock.deleteServer.called).toEqual(false);
|
||||
expect(ServersServiceMock.createServers.called).toEqual(false);
|
||||
expect(ServersServiceMock.listServers).toHaveBeenCalledTimes(1);
|
||||
expect(ServersServiceMock.createServer).not.toHaveBeenCalled();
|
||||
expect(ServersServiceMock.deleteServer).not.toHaveBeenCalled();
|
||||
expect(ServersServiceMock.createServers).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -52,11 +51,11 @@ describe('serverReducer', () => {
|
||||
const result = createServer(ServersServiceMock, () => expectedFetchServersResult)(serverToCreate);
|
||||
|
||||
expect(result).toEqual(expectedFetchServersResult);
|
||||
expect(ServersServiceMock.createServer.calledOnce).toEqual(true);
|
||||
expect(ServersServiceMock.createServer.firstCall.calledWith(serverToCreate)).toEqual(true);
|
||||
expect(ServersServiceMock.listServers.called).toEqual(false);
|
||||
expect(ServersServiceMock.deleteServer.called).toEqual(false);
|
||||
expect(ServersServiceMock.createServers.called).toEqual(false);
|
||||
expect(ServersServiceMock.createServer).toHaveBeenCalledTimes(1);
|
||||
expect(ServersServiceMock.createServer.mock.calls[0]).toEqual([ serverToCreate ]);
|
||||
expect(ServersServiceMock.listServers).not.toHaveBeenCalled();
|
||||
expect(ServersServiceMock.deleteServer).not.toHaveBeenCalled();
|
||||
expect(ServersServiceMock.createServers).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -66,11 +65,11 @@ describe('serverReducer', () => {
|
||||
const result = deleteServer(ServersServiceMock, () => expectedFetchServersResult)(serverToDelete);
|
||||
|
||||
expect(result).toEqual(expectedFetchServersResult);
|
||||
expect(ServersServiceMock.listServers.called).toEqual(false);
|
||||
expect(ServersServiceMock.createServer.called).toEqual(false);
|
||||
expect(ServersServiceMock.createServers.called).toEqual(false);
|
||||
expect(ServersServiceMock.deleteServer.calledOnce).toEqual(true);
|
||||
expect(ServersServiceMock.deleteServer.firstCall.calledWith(serverToDelete)).toEqual(true);
|
||||
expect(ServersServiceMock.listServers).not.toHaveBeenCalled();
|
||||
expect(ServersServiceMock.createServer).not.toHaveBeenCalled();
|
||||
expect(ServersServiceMock.createServers).not.toHaveBeenCalled();
|
||||
expect(ServersServiceMock.deleteServer).toHaveBeenCalledTimes(1);
|
||||
expect(ServersServiceMock.deleteServer.mock.calls[0]).toEqual([ serverToDelete ]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -80,11 +79,11 @@ describe('serverReducer', () => {
|
||||
const result = createServers(ServersServiceMock, () => expectedFetchServersResult)(serversToCreate);
|
||||
|
||||
expect(result).toEqual(expectedFetchServersResult);
|
||||
expect(ServersServiceMock.listServers.called).toEqual(false);
|
||||
expect(ServersServiceMock.createServer.called).toEqual(false);
|
||||
expect(ServersServiceMock.createServers.calledOnce).toEqual(true);
|
||||
expect(ServersServiceMock.createServers.firstCall.calledWith(serversToCreate)).toEqual(true);
|
||||
expect(ServersServiceMock.deleteServer.called).toEqual(false);
|
||||
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.deleteServer).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
import sinon from 'sinon';
|
||||
import ServersExporter from '../../../src/servers/services/ServersExporter';
|
||||
|
||||
describe('ServersExporter', () => {
|
||||
const createLinkMock = () => ({
|
||||
setAttribute: sinon.fake(),
|
||||
click: sinon.fake(),
|
||||
setAttribute: jest.fn(),
|
||||
click: jest.fn(),
|
||||
style: {},
|
||||
});
|
||||
const createWindowMock = (isIe10 = true) => ({
|
||||
navigator: {
|
||||
msSaveBlob: isIe10 ? sinon.fake() : undefined,
|
||||
msSaveBlob: isIe10 ? jest.fn() : undefined,
|
||||
},
|
||||
document: {
|
||||
createElement: sinon.fake.returns(createLinkMock()),
|
||||
createElement: jest.fn(() => createLinkMock()),
|
||||
body: {
|
||||
appendChild: sinon.fake(),
|
||||
removeChild: sinon.fake(),
|
||||
appendChild: jest.fn(),
|
||||
removeChild: jest.fn(),
|
||||
},
|
||||
},
|
||||
});
|
||||
const serversServiceMock = {
|
||||
listServers: sinon.fake.returns({
|
||||
listServers: jest.fn(() => ({
|
||||
abc123: {
|
||||
id: 'abc123',
|
||||
name: 'foo',
|
||||
@@ -29,10 +28,16 @@ describe('ServersExporter', () => {
|
||||
id: 'def456',
|
||||
name: 'bar',
|
||||
},
|
||||
}),
|
||||
})),
|
||||
};
|
||||
const createCsvjsonMock = (throwError = false) => ({
|
||||
toCSV: throwError ? sinon.fake.throws('') : sinon.fake.returns(''),
|
||||
toCSV: jest.fn(() => {
|
||||
if (throwError) {
|
||||
throw new Error('');
|
||||
}
|
||||
|
||||
return '';
|
||||
}),
|
||||
});
|
||||
|
||||
describe('exportServers', () => {
|
||||
@@ -40,10 +45,10 @@ describe('ServersExporter', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
originalConsole = global.console;
|
||||
global.console = { error: sinon.fake() };
|
||||
global.console = { error: jest.fn() };
|
||||
global.Blob = class Blob {};
|
||||
global.URL = { createObjectURL: () => '' };
|
||||
serversServiceMock.listServers.resetHistory();
|
||||
serversServiceMock.listServers.mockReset();
|
||||
});
|
||||
afterEach(() => {
|
||||
global.console = originalConsole;
|
||||
@@ -59,8 +64,8 @@ describe('ServersExporter', () => {
|
||||
|
||||
exporter.exportServers();
|
||||
|
||||
expect(global.console.error.callCount).toEqual(1);
|
||||
expect(csvjsonMock.toCSV.callCount).toEqual(1);
|
||||
expect(global.console.error).toHaveBeenCalledTimes(1);
|
||||
expect(csvjsonMock.toCSV).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('makes use of msSaveBlob API when available', () => {
|
||||
@@ -73,9 +78,9 @@ describe('ServersExporter', () => {
|
||||
|
||||
exporter.exportServers();
|
||||
|
||||
expect(serversServiceMock.listServers.callCount).toEqual(1);
|
||||
expect(windowMock.navigator.msSaveBlob.callCount).toEqual(1);
|
||||
expect(windowMock.document.createElement.callCount).toEqual(0);
|
||||
expect(serversServiceMock.listServers).toHaveBeenCalledTimes(1);
|
||||
expect(windowMock.navigator.msSaveBlob).toHaveBeenCalledTimes(1);
|
||||
expect(windowMock.document.createElement).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('makes use of download link API when available', () => {
|
||||
@@ -88,10 +93,10 @@ describe('ServersExporter', () => {
|
||||
|
||||
exporter.exportServers();
|
||||
|
||||
expect(serversServiceMock.listServers.callCount).toEqual(1);
|
||||
expect(windowMock.document.createElement.callCount).toEqual(1);
|
||||
expect(windowMock.document.body.appendChild.callCount).toEqual(1);
|
||||
expect(windowMock.document.body.removeChild.callCount).toEqual(1);
|
||||
expect(serversServiceMock.listServers).toHaveBeenCalledTimes(1);
|
||||
expect(windowMock.document.createElement).toHaveBeenCalledTimes(1);
|
||||
expect(windowMock.document.body.appendChild).toHaveBeenCalledTimes(1);
|
||||
expect(windowMock.document.body.removeChild).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import sinon from 'sinon';
|
||||
import ServersImporter from '../../../src/servers/services/ServersImporter';
|
||||
|
||||
describe('ServersImporter', () => {
|
||||
const servers = [{ name: 'foo' }, { name: 'bar' }];
|
||||
const csvjsonMock = {
|
||||
toObject: sinon.fake.returns(servers),
|
||||
toObject: jest.fn(() => servers),
|
||||
};
|
||||
const importer = new ServersImporter(csvjsonMock);
|
||||
|
||||
beforeEach(() => csvjsonMock.toObject.resetHistory());
|
||||
beforeEach(() => csvjsonMock.toObject.mockClear());
|
||||
|
||||
describe('importServersFromFile', () => {
|
||||
it('rejects with error if no file was provided', async () => {
|
||||
@@ -28,7 +27,7 @@ describe('ServersImporter', () => {
|
||||
});
|
||||
|
||||
it('reads file when a CSV is provided', async () => {
|
||||
const readAsText = sinon.fake.returns('');
|
||||
const readAsText = jest.fn(() => '');
|
||||
|
||||
global.FileReader = class FileReader {
|
||||
constructor() {
|
||||
@@ -40,8 +39,8 @@ describe('ServersImporter', () => {
|
||||
|
||||
await importer.importServersFromFile({ type: 'text/csv' });
|
||||
|
||||
expect(readAsText.callCount).toEqual(1);
|
||||
expect(csvjsonMock.toObject.callCount).toEqual(1);
|
||||
expect(readAsText).toHaveBeenCalledTimes(1);
|
||||
expect(csvjsonMock.toObject).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import sinon from 'sinon';
|
||||
import { last } from 'ramda';
|
||||
import ServersService from '../../../src/servers/services/ServersService';
|
||||
|
||||
@@ -8,8 +7,8 @@ describe('ServersService', () => {
|
||||
def456: { id: 'def456' },
|
||||
};
|
||||
const createStorageMock = (returnValue) => ({
|
||||
set: sinon.fake(),
|
||||
get: sinon.fake.returns(returnValue),
|
||||
set: jest.fn(),
|
||||
get: jest.fn(() => returnValue),
|
||||
});
|
||||
|
||||
describe('listServers', () => {
|
||||
@@ -20,8 +19,8 @@ describe('ServersService', () => {
|
||||
const result = service.listServers();
|
||||
|
||||
expect(result).toEqual({});
|
||||
expect(storageMock.get.callCount).toEqual(1);
|
||||
expect(storageMock.set.callCount).toEqual(0);
|
||||
expect(storageMock.get).toHaveBeenCalledTimes(1);
|
||||
expect(storageMock.set).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns value from storage when found', () => {
|
||||
@@ -31,8 +30,8 @@ describe('ServersService', () => {
|
||||
const result = service.listServers();
|
||||
|
||||
expect(result).toEqual(servers);
|
||||
expect(storageMock.get.callCount).toEqual(1);
|
||||
expect(storageMock.set.callCount).toEqual(0);
|
||||
expect(storageMock.get).toHaveBeenCalledTimes(1);
|
||||
expect(storageMock.set).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,8 +43,8 @@ describe('ServersService', () => {
|
||||
const result = service.findServerById('ghi789');
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
expect(storageMock.get.callCount).toEqual(1);
|
||||
expect(storageMock.set.callCount).toEqual(0);
|
||||
expect(storageMock.get).toHaveBeenCalledTimes(1);
|
||||
expect(storageMock.set).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns server from list when found', () => {
|
||||
@@ -55,8 +54,8 @@ describe('ServersService', () => {
|
||||
const result = service.findServerById('abc123');
|
||||
|
||||
expect(result).toEqual({ id: 'abc123' });
|
||||
expect(storageMock.get.callCount).toEqual(1);
|
||||
expect(storageMock.set.callCount).toEqual(0);
|
||||
expect(storageMock.get).toHaveBeenCalledTimes(1);
|
||||
expect(storageMock.set).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -67,9 +66,12 @@ describe('ServersService', () => {
|
||||
|
||||
service.createServer({ id: 'ghi789' });
|
||||
|
||||
expect(storageMock.get.callCount).toEqual(1);
|
||||
expect(storageMock.set.callCount).toEqual(1);
|
||||
expect(last(storageMock.set.lastCall.args)).toEqual({
|
||||
expect(storageMock.get).toHaveBeenCalledTimes(1);
|
||||
expect(storageMock.set).toHaveBeenCalledTimes(1);
|
||||
|
||||
const setLastCallLastArg = last(last(storageMock.set.mock.calls));
|
||||
|
||||
expect(setLastCallLastArg).toEqual({
|
||||
abc123: { id: 'abc123' },
|
||||
def456: { id: 'def456' },
|
||||
ghi789: { id: 'ghi789' },
|
||||
@@ -84,9 +86,12 @@ describe('ServersService', () => {
|
||||
|
||||
service.createServers([{ id: 'ghi789' }, { id: 'jkl123' }]);
|
||||
|
||||
expect(storageMock.get.callCount).toEqual(1);
|
||||
expect(storageMock.set.callCount).toEqual(1);
|
||||
expect(last(storageMock.set.lastCall.args)).toEqual({
|
||||
expect(storageMock.get).toHaveBeenCalledTimes(1);
|
||||
expect(storageMock.set).toHaveBeenCalledTimes(1);
|
||||
|
||||
const setLastCallLastArg = last(last(storageMock.set.mock.calls));
|
||||
|
||||
expect(setLastCallLastArg).toEqual({
|
||||
abc123: { id: 'abc123' },
|
||||
def456: { id: 'def456' },
|
||||
ghi789: { id: 'ghi789' },
|
||||
@@ -102,9 +107,12 @@ describe('ServersService', () => {
|
||||
|
||||
service.deleteServer({ id: 'abc123' });
|
||||
|
||||
expect(storageMock.get.callCount).toEqual(1);
|
||||
expect(storageMock.set.callCount).toEqual(1);
|
||||
expect(last(storageMock.set.lastCall.args)).toEqual({
|
||||
expect(storageMock.get).toHaveBeenCalledTimes(1);
|
||||
expect(storageMock.set).toHaveBeenCalledTimes(1);
|
||||
|
||||
const setLastCallLastArg = last(last(storageMock.set.mock.calls));
|
||||
|
||||
expect(setLastCallLastArg).toEqual({
|
||||
def456: { id: 'def456' },
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user