mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-19 22:13:47 +00:00
Refactor of redux tests to avoid covering RTK implementation details
This commit is contained in:
@@ -16,21 +16,21 @@ describe('mercureInfoReducer', () => {
|
||||
|
||||
describe('reducer', () => {
|
||||
it('returns loading on GET_MERCURE_INFO_START', () => {
|
||||
expect(reducer(undefined, { type: loadMercureInfo.pending.toString() })).toEqual({
|
||||
expect(reducer(undefined, loadMercureInfo.pending(''))).toEqual({
|
||||
loading: true,
|
||||
error: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('returns error on GET_MERCURE_INFO_ERROR', () => {
|
||||
expect(reducer(undefined, { type: loadMercureInfo.rejected.toString() })).toEqual({
|
||||
expect(reducer(undefined, loadMercureInfo.rejected(null, ''))).toEqual({
|
||||
loading: false,
|
||||
error: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('returns mercure info on GET_MERCURE_INFO', () => {
|
||||
expect(reducer(undefined, { type: loadMercureInfo.fulfilled.toString(), payload: mercureInfo })).toEqual(
|
||||
expect(reducer(undefined, loadMercureInfo.fulfilled(mercureInfo, ''))).toEqual(
|
||||
expect.objectContaining({ ...mercureInfo, loading: false, error: false }),
|
||||
);
|
||||
});
|
||||
@@ -52,11 +52,8 @@ describe('mercureInfoReducer', () => {
|
||||
|
||||
expect(getMercureInfo).not.toHaveBeenCalled();
|
||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||
expect(dispatch).toHaveBeenNthCalledWith(1, expect.objectContaining({
|
||||
type: loadMercureInfo.pending.toString(),
|
||||
}));
|
||||
expect(dispatch).toHaveBeenNthCalledWith(2, expect.objectContaining({
|
||||
type: loadMercureInfo.rejected.toString(),
|
||||
expect(dispatch).toHaveBeenLastCalledWith(expect.objectContaining({
|
||||
error: new Error('Real time updates not enabled'),
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -68,31 +65,7 @@ describe('mercureInfoReducer', () => {
|
||||
|
||||
expect(getMercureInfo).toHaveBeenCalledTimes(1);
|
||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||
expect(dispatch).toHaveBeenNthCalledWith(1, expect.objectContaining({
|
||||
type: loadMercureInfo.pending.toString(),
|
||||
}));
|
||||
expect(dispatch).toHaveBeenNthCalledWith(2, expect.objectContaining({
|
||||
type: loadMercureInfo.fulfilled.toString(),
|
||||
payload: mercureInfo,
|
||||
}));
|
||||
});
|
||||
|
||||
it('throws error on failure', async () => {
|
||||
const error = 'Error';
|
||||
const getState = createGetStateMock(true);
|
||||
|
||||
getMercureInfo.mockRejectedValue(error);
|
||||
|
||||
await loadMercureInfo()(dispatch, getState, {});
|
||||
|
||||
expect(getMercureInfo).toHaveBeenCalledTimes(1);
|
||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||
expect(dispatch).toHaveBeenNthCalledWith(1, expect.objectContaining({
|
||||
type: loadMercureInfo.pending.toString(),
|
||||
}));
|
||||
expect(dispatch).toHaveBeenNthCalledWith(2, expect.objectContaining({
|
||||
type: loadMercureInfo.rejected.toString(),
|
||||
}));
|
||||
expect(dispatch).toHaveBeenLastCalledWith(expect.objectContaining({ payload: mercureInfo }));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user