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

@@ -84,14 +84,12 @@ describe('shortUrlsListReducer', () => {
const apiClientMock = {
listShortUrls: jest.fn().mockResolvedValue([]),
};
const expectedDispatchCalls = 2;
await listShortUrls(() => apiClientMock)()(dispatch, getState);
const [ firstDispatchCallArgs, secondDispatchCallArgs ] = dispatch.mock.calls;
expect(dispatch).toHaveBeenCalledTimes(expectedDispatchCalls);
expect(firstDispatchCallArgs).toEqual([{ type: LIST_SHORT_URLS_START }]);
expect(secondDispatchCallArgs).toEqual([{ type: LIST_SHORT_URLS, shortUrls: [], params: {} }]);
expect(dispatch).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenNthCalledWith(1, { type: LIST_SHORT_URLS_START });
expect(dispatch).toHaveBeenNthCalledWith(2, { type: LIST_SHORT_URLS, shortUrls: [], params: {} });
expect(apiClientMock.listShortUrls).toHaveBeenCalledTimes(1);
});
@@ -100,14 +98,12 @@ describe('shortUrlsListReducer', () => {
const apiClientMock = {
listShortUrls: jest.fn().mockRejectedValue(),
};
const expectedDispatchCalls = 2;
await listShortUrls(() => apiClientMock)()(dispatch, getState);
const [ firstDispatchCallArgs, secondDispatchCallArgs ] = dispatch.mock.calls;
expect(dispatch).toHaveBeenCalledTimes(expectedDispatchCalls);
expect(firstDispatchCallArgs).toEqual([{ type: LIST_SHORT_URLS_START }]);
expect(secondDispatchCallArgs).toEqual([{ type: LIST_SHORT_URLS_ERROR, params: {} }]);
expect(dispatch).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenNthCalledWith(1, { type: LIST_SHORT_URLS_START });
expect(dispatch).toHaveBeenNthCalledWith(2, { type: LIST_SHORT_URLS_ERROR, params: {} });
expect(apiClientMock.listShortUrls).toHaveBeenCalledTimes(1);
});