mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-14 11:33:51 +00:00
Removed remaining usages of sinon
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import * as sinon from 'sinon';
|
||||
import reducer, {
|
||||
CREATE_SHORT_URL_START,
|
||||
CREATE_SHORT_URL_ERROR,
|
||||
@@ -48,12 +47,12 @@ describe('shortUrlCreationReducer', () => {
|
||||
|
||||
describe('createShortUrl', () => {
|
||||
const createApiClientMock = (result) => ({
|
||||
createShortUrl: sinon.fake.returns(result),
|
||||
createShortUrl: jest.fn(() => result),
|
||||
});
|
||||
const dispatch = sinon.spy();
|
||||
const dispatch = jest.fn();
|
||||
const getState = () => ({});
|
||||
|
||||
afterEach(() => dispatch.resetHistory());
|
||||
afterEach(() => dispatch.mockReset());
|
||||
|
||||
it('calls API on success', async () => {
|
||||
const expectedDispatchCalls = 2;
|
||||
@@ -62,12 +61,12 @@ describe('shortUrlCreationReducer', () => {
|
||||
const dispatchable = createShortUrl(() => apiClientMock)({});
|
||||
|
||||
await dispatchable(dispatch, getState);
|
||||
const [ firstDispatchCallArgs, secondDispatchCallArgs ] = dispatch.mock.calls;
|
||||
|
||||
expect(apiClientMock.createShortUrl.callCount).toEqual(1);
|
||||
|
||||
expect(dispatch.callCount).toEqual(expectedDispatchCalls);
|
||||
expect(dispatch.getCall(0).args).toEqual([{ type: CREATE_SHORT_URL_START }]);
|
||||
expect(dispatch.getCall(1).args).toEqual([{ type: CREATE_SHORT_URL, result }]);
|
||||
expect(apiClientMock.createShortUrl).toHaveBeenCalledTimes(1);
|
||||
expect(dispatch).toHaveBeenCalledTimes(expectedDispatchCalls);
|
||||
expect(firstDispatchCallArgs).toEqual([{ type: CREATE_SHORT_URL_START }]);
|
||||
expect(secondDispatchCallArgs).toEqual([{ type: CREATE_SHORT_URL, result }]);
|
||||
});
|
||||
|
||||
it('throws on error', async () => {
|
||||
@@ -81,12 +80,12 @@ describe('shortUrlCreationReducer', () => {
|
||||
} catch (e) {
|
||||
expect(e).toEqual(error);
|
||||
}
|
||||
const [ firstDispatchCallArgs, secondDispatchCallArgs ] = dispatch.mock.calls;
|
||||
|
||||
expect(apiClientMock.createShortUrl.callCount).toEqual(1);
|
||||
|
||||
expect(dispatch.callCount).toEqual(expectedDispatchCalls);
|
||||
expect(dispatch.getCall(0).args).toEqual([{ type: CREATE_SHORT_URL_START }]);
|
||||
expect(dispatch.getCall(1).args).toEqual([{ type: CREATE_SHORT_URL_ERROR }]);
|
||||
expect(apiClientMock.createShortUrl).toHaveBeenCalledTimes(1);
|
||||
expect(dispatch).toHaveBeenCalledTimes(expectedDispatchCalls);
|
||||
expect(firstDispatchCallArgs).toEqual([{ type: CREATE_SHORT_URL_START }]);
|
||||
expect(secondDispatchCallArgs).toEqual([{ type: CREATE_SHORT_URL_ERROR }]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import * as sinon from 'sinon';
|
||||
import reducer, {
|
||||
DELETE_SHORT_URL, DELETE_SHORT_URL_ERROR,
|
||||
DELETE_SHORT_URL_START,
|
||||
@@ -58,36 +57,37 @@ describe('shortUrlDeletionReducer', () => {
|
||||
});
|
||||
|
||||
describe('deleteShortUrl', () => {
|
||||
const dispatch = sinon.spy();
|
||||
const getState = sinon.fake.returns({ selectedServer: {} });
|
||||
const dispatch = jest.fn();
|
||||
const getState = jest.fn().mockReturnValue({ selectedServer: {} });
|
||||
|
||||
afterEach(() => {
|
||||
dispatch.resetHistory();
|
||||
getState.resetHistory();
|
||||
dispatch.mockReset();
|
||||
getState.mockClear();
|
||||
});
|
||||
|
||||
it('dispatches proper actions if API client request succeeds', async () => {
|
||||
const apiClientMock = {
|
||||
deleteShortUrl: sinon.fake.resolves(''),
|
||||
deleteShortUrl: jest.fn(() => ''),
|
||||
};
|
||||
const shortCode = 'abc123';
|
||||
const expectedDispatchCalls = 2;
|
||||
|
||||
await deleteShortUrl(() => apiClientMock)(shortCode)(dispatch, getState);
|
||||
const [ firstDispatchCallArgs, secondDispatchCallArgs ] = dispatch.mock.calls;
|
||||
|
||||
expect(dispatch.callCount).toEqual(expectedDispatchCalls);
|
||||
expect(dispatch.getCall(0).args).toEqual([{ type: DELETE_SHORT_URL_START }]);
|
||||
expect(dispatch.getCall(1).args).toEqual([{ type: DELETE_SHORT_URL, shortCode }]);
|
||||
expect(dispatch).toHaveBeenCalledTimes(expectedDispatchCalls);
|
||||
expect(firstDispatchCallArgs).toEqual([{ type: DELETE_SHORT_URL_START }]);
|
||||
expect(secondDispatchCallArgs).toEqual([{ type: DELETE_SHORT_URL, shortCode }]);
|
||||
|
||||
expect(apiClientMock.deleteShortUrl.callCount).toEqual(1);
|
||||
expect(apiClientMock.deleteShortUrl.getCall(0).args).toEqual([ shortCode ]);
|
||||
expect(apiClientMock.deleteShortUrl).toHaveBeenCalledTimes(1);
|
||||
expect(apiClientMock.deleteShortUrl.mock.calls[0]).toEqual([ shortCode ]);
|
||||
});
|
||||
|
||||
it('dispatches proper actions if API client request fails', async () => {
|
||||
const data = { foo: 'bar' };
|
||||
const error = { response: { data } };
|
||||
const apiClientMock = {
|
||||
deleteShortUrl: sinon.fake.returns(Promise.reject(error)),
|
||||
deleteShortUrl: jest.fn(() => Promise.reject(error)),
|
||||
};
|
||||
const shortCode = 'abc123';
|
||||
const expectedDispatchCalls = 2;
|
||||
@@ -97,13 +97,14 @@ describe('shortUrlDeletionReducer', () => {
|
||||
} catch (e) {
|
||||
expect(e).toEqual(error);
|
||||
}
|
||||
const [ firstDispatchCallArgs, secondDispatchCallArgs ] = dispatch.mock.calls;
|
||||
|
||||
expect(dispatch.callCount).toEqual(expectedDispatchCalls);
|
||||
expect(dispatch.getCall(0).args).toEqual([{ type: DELETE_SHORT_URL_START }]);
|
||||
expect(dispatch.getCall(1).args).toEqual([{ type: DELETE_SHORT_URL_ERROR, errorData: data }]);
|
||||
expect(dispatch).toHaveBeenCalledTimes(expectedDispatchCalls);
|
||||
expect(firstDispatchCallArgs).toEqual([{ type: DELETE_SHORT_URL_START }]);
|
||||
expect(secondDispatchCallArgs).toEqual([{ type: DELETE_SHORT_URL_ERROR, errorData: data }]);
|
||||
|
||||
expect(apiClientMock.deleteShortUrl.callCount).toEqual(1);
|
||||
expect(apiClientMock.deleteShortUrl.getCall(0).args).toEqual([ shortCode ]);
|
||||
expect(apiClientMock.deleteShortUrl).toHaveBeenCalledTimes(1);
|
||||
expect(apiClientMock.deleteShortUrl.mock.calls[0]).toEqual([ shortCode ]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import * as sinon from 'sinon';
|
||||
import reducer, {
|
||||
LIST_SHORT_URLS,
|
||||
LIST_SHORT_URLS_ERROR,
|
||||
@@ -73,42 +72,44 @@ describe('shortUrlsListReducer', () => {
|
||||
});
|
||||
|
||||
describe('listShortUrls', () => {
|
||||
const dispatch = sinon.spy();
|
||||
const getState = sinon.fake.returns({ selectedServer: {} });
|
||||
const dispatch = jest.fn();
|
||||
const getState = jest.fn().mockReturnValue({ selectedServer: {} });
|
||||
|
||||
afterEach(() => {
|
||||
dispatch.resetHistory();
|
||||
getState.resetHistory();
|
||||
dispatch.mockReset();
|
||||
getState.mockClear();
|
||||
});
|
||||
|
||||
it('dispatches proper actions if API client request succeeds', async () => {
|
||||
const apiClientMock = {
|
||||
listShortUrls: sinon.fake.resolves([]),
|
||||
listShortUrls: jest.fn().mockResolvedValue([]),
|
||||
};
|
||||
const expectedDispatchCalls = 2;
|
||||
|
||||
await listShortUrls(() => apiClientMock)()(dispatch, getState);
|
||||
const [ firstDispatchCallArgs, secondDispatchCallArgs ] = dispatch.mock.calls;
|
||||
|
||||
expect(dispatch.callCount).toEqual(expectedDispatchCalls);
|
||||
expect(dispatch.getCall(0).args).toEqual([{ type: LIST_SHORT_URLS_START }]);
|
||||
expect(dispatch.getCall(1).args).toEqual([{ type: LIST_SHORT_URLS, shortUrls: [], params: {} }]);
|
||||
expect(dispatch).toHaveBeenCalledTimes(expectedDispatchCalls);
|
||||
expect(firstDispatchCallArgs).toEqual([{ type: LIST_SHORT_URLS_START }]);
|
||||
expect(secondDispatchCallArgs).toEqual([{ type: LIST_SHORT_URLS, shortUrls: [], params: {} }]);
|
||||
|
||||
expect(apiClientMock.listShortUrls.callCount).toEqual(1);
|
||||
expect(apiClientMock.listShortUrls).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('dispatches proper actions if API client request fails', async () => {
|
||||
const apiClientMock = {
|
||||
listShortUrls: sinon.fake.rejects(),
|
||||
listShortUrls: jest.fn().mockRejectedValue(),
|
||||
};
|
||||
const expectedDispatchCalls = 2;
|
||||
|
||||
await listShortUrls(() => apiClientMock)()(dispatch, getState);
|
||||
const [ firstDispatchCallArgs, secondDispatchCallArgs ] = dispatch.mock.calls;
|
||||
|
||||
expect(dispatch.callCount).toEqual(expectedDispatchCalls);
|
||||
expect(dispatch.getCall(0).args).toEqual([{ type: LIST_SHORT_URLS_START }]);
|
||||
expect(dispatch.getCall(1).args).toEqual([{ type: LIST_SHORT_URLS_ERROR, params: {} }]);
|
||||
expect(dispatch).toHaveBeenCalledTimes(expectedDispatchCalls);
|
||||
expect(firstDispatchCallArgs).toEqual([{ type: LIST_SHORT_URLS_START }]);
|
||||
expect(secondDispatchCallArgs).toEqual([{ type: LIST_SHORT_URLS_ERROR, params: {} }]);
|
||||
|
||||
expect(apiClientMock.listShortUrls.callCount).toEqual(1);
|
||||
expect(apiClientMock.listShortUrls).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user