Fixed tests

This commit is contained in:
Alejandro Celaya 2018-12-18 10:23:09 +01:00
parent 4f54e3315f
commit 79a0a5e4ea
6 changed files with 23 additions and 23 deletions

View file

@ -29,9 +29,6 @@ describe('selectedServerReducer', () => {
});
describe('selectServer', () => {
const ShlinkApiClientMock = {
setConfig: sinon.spy(),
};
const serverId = 'abc123';
const selectedServer = {
id: serverId,
@ -41,7 +38,6 @@ describe('selectedServerReducer', () => {
};
afterEach(() => {
ShlinkApiClientMock.setConfig.resetHistory();
ServersServiceMock.findServerById.resetHistory();
});
@ -49,7 +45,7 @@ describe('selectedServerReducer', () => {
const dispatch = sinon.spy();
const expectedDispatchCalls = 2;
_selectServer(ShlinkApiClientMock, ServersServiceMock)(serverId)(dispatch);
_selectServer(ServersServiceMock)(serverId)(dispatch);
expect(dispatch.callCount).toEqual(expectedDispatchCalls);
expect(dispatch.firstCall.calledWith({ type: RESET_SHORT_URL_PARAMS })).toEqual(true);
@ -60,9 +56,8 @@ describe('selectedServerReducer', () => {
});
it('invokes dependencies', () => {
_selectServer(ShlinkApiClientMock, ServersServiceMock)(serverId)(() => {});
_selectServer(ServersServiceMock)(serverId)(() => {});
expect(ShlinkApiClientMock.setConfig.callCount).toEqual(1);
expect(ServersServiceMock.findServerById.callCount).toEqual(1);
});
});

View file

@ -54,6 +54,7 @@ describe('shortUrlCreationReducer', () => {
createShortUrl: sinon.fake.returns(result),
});
const dispatch = sinon.spy();
const getState = () => ({});
afterEach(() => dispatch.resetHistory());
@ -61,9 +62,9 @@ describe('shortUrlCreationReducer', () => {
const expectedDispatchCalls = 2;
const result = 'foo';
const apiClientMock = createApiClientMock(Promise.resolve(result));
const dispatchable = _createShortUrl(apiClientMock, {});
const dispatchable = _createShortUrl(() => apiClientMock, {});
await dispatchable(dispatch);
await dispatchable(dispatch, getState);
expect(apiClientMock.createShortUrl.callCount).toEqual(1);
@ -76,10 +77,10 @@ describe('shortUrlCreationReducer', () => {
const expectedDispatchCalls = 2;
const error = 'Error';
const apiClientMock = createApiClientMock(Promise.reject(error));
const dispatchable = _createShortUrl(apiClientMock, {});
const dispatchable = _createShortUrl(() => apiClientMock, {});
try {
await dispatchable(dispatch);
await dispatchable(dispatch, getState);
} catch (e) {
expect(e).toEqual(error);
}

View file

@ -48,6 +48,7 @@ describe('tagDeleteReducer', () => {
deleteTags: sinon.fake.returns(result),
});
const dispatch = sinon.spy();
const getState = () => ({});
afterEach(() => dispatch.resetHistory());
@ -55,9 +56,9 @@ describe('tagDeleteReducer', () => {
const expectedDispatchCalls = 2;
const tag = 'foo';
const apiClientMock = createApiClientMock(Promise.resolve());
const dispatchable = _deleteTag(apiClientMock, tag);
const dispatchable = _deleteTag(() => apiClientMock, tag);
await dispatchable(dispatch);
await dispatchable(dispatch, getState);
expect(apiClientMock.deleteTags.callCount).toEqual(1);
expect(apiClientMock.deleteTags.getCall(0).args).toEqual([[ tag ]]);
@ -72,10 +73,10 @@ describe('tagDeleteReducer', () => {
const error = 'Error';
const tag = 'foo';
const apiClientMock = createApiClientMock(Promise.reject(error));
const dispatchable = _deleteTag(apiClientMock, tag);
const dispatchable = _deleteTag(() => apiClientMock, tag);
try {
await dispatchable(dispatch);
await dispatchable(dispatch, getState);
} catch (e) {
expect(e).toEqual(error);
}

View file

@ -55,6 +55,7 @@ describe('tagEditReducer', () => {
setColorForKey: sinon.spy(),
};
const dispatch = sinon.spy();
const getState = () => ({});
afterEach(() => {
colorGenerator.setColorForKey.resetHistory();
@ -67,9 +68,9 @@ describe('tagEditReducer', () => {
const newName = 'bar';
const color = '#ff0000';
const apiClientMock = createApiClientMock(Promise.resolve());
const dispatchable = _editTag(apiClientMock, colorGenerator, oldName, newName, color);
const dispatchable = _editTag(() => apiClientMock, colorGenerator, oldName, newName, color);
await dispatchable(dispatch);
await dispatchable(dispatch, getState);
expect(apiClientMock.editTag.callCount).toEqual(1);
expect(apiClientMock.editTag.getCall(0).args).toEqual([ oldName, newName ]);
@ -89,10 +90,10 @@ describe('tagEditReducer', () => {
const newName = 'bar';
const color = '#ff0000';
const apiClientMock = createApiClientMock(Promise.reject(error));
const dispatchable = _editTag(apiClientMock, colorGenerator, oldName, newName, color);
const dispatchable = _editTag(() => apiClientMock, colorGenerator, oldName, newName, color);
try {
await dispatchable(dispatch);
await dispatchable(dispatch, getState);
} catch (e) {
expect(e).toEqual(error);
}

View file

@ -50,6 +50,7 @@ describe('shortUrlDetailReducer', () => {
getShortUrl: sinon.fake.returns(returned),
});
const dispatchMock = sinon.spy();
const getState = () => ({});
beforeEach(() => dispatchMock.resetHistory());
@ -57,7 +58,7 @@ describe('shortUrlDetailReducer', () => {
const ShlinkApiClient = buildApiClientMock(Promise.reject());
const expectedDispatchCalls = 2;
await _getShortUrlDetail(ShlinkApiClient, 'abc123')(dispatchMock);
await _getShortUrlDetail(() => ShlinkApiClient, 'abc123')(dispatchMock, getState);
const [ firstCallArg ] = dispatchMock.getCall(0).args;
const { type: firstCallType } = firstCallArg;
@ -76,7 +77,7 @@ describe('shortUrlDetailReducer', () => {
const ShlinkApiClient = buildApiClientMock(Promise.resolve(resolvedShortUrl));
const expectedDispatchCalls = 2;
await _getShortUrlDetail(ShlinkApiClient, 'abc123')(dispatchMock);
await _getShortUrlDetail(() => ShlinkApiClient, 'abc123')(dispatchMock, getState);
const [ firstCallArg ] = dispatchMock.getCall(0).args;
const { type: firstCallType } = firstCallArg;

View file

@ -50,6 +50,7 @@ describe('shortUrlVisitsReducer', () => {
getShortUrlVisits: sinon.fake.returns(returned),
});
const dispatchMock = sinon.spy();
const getState = () => ({});
beforeEach(() => dispatchMock.resetHistory());
@ -57,7 +58,7 @@ describe('shortUrlVisitsReducer', () => {
const ShlinkApiClient = buildApiClientMock(Promise.reject());
const expectedDispatchCalls = 2;
await _getShortUrlVisits(ShlinkApiClient, 'abc123')(dispatchMock);
await _getShortUrlVisits(() => ShlinkApiClient, 'abc123')(dispatchMock, getState);
const [ firstCallArg ] = dispatchMock.getCall(0).args;
const { type: firstCallType } = firstCallArg;
@ -76,7 +77,7 @@ describe('shortUrlVisitsReducer', () => {
const ShlinkApiClient = buildApiClientMock(Promise.resolve(resolvedVisits));
const expectedDispatchCalls = 2;
await _getShortUrlVisits(ShlinkApiClient, 'abc123')(dispatchMock);
await _getShortUrlVisits(() => ShlinkApiClient, 'abc123')(dispatchMock, getState);
const [ firstCallArg ] = dispatchMock.getCall(0).args;
const { type: firstCallType } = firstCallArg;