mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-17 04:53:49 +00:00
Removed remaining usages of sinon
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import * as sinon from 'sinon';
|
||||
import reducer, {
|
||||
getShortUrlDetail,
|
||||
GET_SHORT_URL_DETAIL_START,
|
||||
@@ -36,49 +35,34 @@ describe('shortUrlDetailReducer', () => {
|
||||
|
||||
describe('getShortUrlDetail', () => {
|
||||
const buildApiClientMock = (returned) => ({
|
||||
getShortUrl: sinon.fake.returns(returned),
|
||||
getShortUrl: jest.fn(() => returned),
|
||||
});
|
||||
const dispatchMock = sinon.spy();
|
||||
const dispatchMock = jest.fn();
|
||||
const getState = () => ({});
|
||||
|
||||
beforeEach(() => dispatchMock.resetHistory());
|
||||
beforeEach(() => dispatchMock.mockReset());
|
||||
|
||||
it('dispatches start and error when promise is rejected', async () => {
|
||||
const ShlinkApiClient = buildApiClientMock(Promise.reject());
|
||||
const expectedDispatchCalls = 2;
|
||||
|
||||
await getShortUrlDetail(() => ShlinkApiClient)('abc123')(dispatchMock, getState);
|
||||
|
||||
const [ firstCallArg ] = dispatchMock.getCall(0).args;
|
||||
const { type: firstCallType } = firstCallArg;
|
||||
|
||||
const [ secondCallArg ] = dispatchMock.getCall(1).args;
|
||||
const { type: secondCallType } = secondCallArg;
|
||||
|
||||
expect(dispatchMock.callCount).toEqual(expectedDispatchCalls);
|
||||
expect(ShlinkApiClient.getShortUrl.callCount).toEqual(1);
|
||||
expect(firstCallType).toEqual(GET_SHORT_URL_DETAIL_START);
|
||||
expect(secondCallType).toEqual(GET_SHORT_URL_DETAIL_ERROR);
|
||||
expect(dispatchMock).toHaveBeenCalledTimes(2);
|
||||
expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_SHORT_URL_DETAIL_START });
|
||||
expect(dispatchMock).toHaveBeenNthCalledWith(2, { type: GET_SHORT_URL_DETAIL_ERROR });
|
||||
expect(ShlinkApiClient.getShortUrl).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('dispatches start and success when promise is resolved', async () => {
|
||||
const resolvedShortUrl = { longUrl: 'foo', shortCode: 'bar' };
|
||||
const ShlinkApiClient = buildApiClientMock(Promise.resolve(resolvedShortUrl));
|
||||
const expectedDispatchCalls = 2;
|
||||
|
||||
await getShortUrlDetail(() => ShlinkApiClient)('abc123')(dispatchMock, getState);
|
||||
|
||||
const [ firstCallArg ] = dispatchMock.getCall(0).args;
|
||||
const { type: firstCallType } = firstCallArg;
|
||||
|
||||
const [ secondCallArg ] = dispatchMock.getCall(1).args;
|
||||
const { type: secondCallType, shortUrl } = secondCallArg;
|
||||
|
||||
expect(dispatchMock.callCount).toEqual(expectedDispatchCalls);
|
||||
expect(ShlinkApiClient.getShortUrl.callCount).toEqual(1);
|
||||
expect(firstCallType).toEqual(GET_SHORT_URL_DETAIL_START);
|
||||
expect(secondCallType).toEqual(GET_SHORT_URL_DETAIL);
|
||||
expect(shortUrl).toEqual(resolvedShortUrl);
|
||||
expect(dispatchMock).toHaveBeenCalledTimes(2);
|
||||
expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_SHORT_URL_DETAIL_START });
|
||||
expect(dispatchMock).toHaveBeenNthCalledWith(2, { type: GET_SHORT_URL_DETAIL, shortUrl: resolvedShortUrl });
|
||||
expect(ShlinkApiClient.getShortUrl).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user