Skip to content

Commit aa31073

Browse files
Merge pull request #3002 from OneCommunityGlobal/aaryaneil-Unit-Test-errorsReducer
Aaryaneil - Unit Tests errorsReducer component
2 parents 23f729b + a3a07e9 commit aa31073

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { errorsReducer } from '../errorsReducer';
2+
import { GET_ERRORS, CLEAR_ERRORS } from '../../constants/errors';
3+
4+
describe('errorsReducer', () => {
5+
const initialState = {};
6+
7+
it('should return the initial state when no action is passed', () => {
8+
expect(errorsReducer(undefined, {})).toEqual(initialState);
9+
});
10+
11+
it('should handle GET_ERRORS', () => {
12+
const errorPayload = { msg: 'An error occurred', status: 500 };
13+
const action = {
14+
type: GET_ERRORS,
15+
payload: errorPayload,
16+
};
17+
const expectedState = errorPayload;
18+
expect(errorsReducer(initialState, action)).toEqual(expectedState);
19+
});
20+
21+
it('should handle CLEAR_ERRORS', () => {
22+
const currentState = { msg: 'Some error message', status: 400 };
23+
const action = { type: CLEAR_ERRORS };
24+
const expectedState = {};
25+
expect(errorsReducer(currentState, action)).toEqual(expectedState);
26+
});
27+
28+
it('should return current state for unknown action types', () => {
29+
const currentState = { msg: 'Some error message', status: 400 };
30+
const action = { type: 'UNKNOWN_ACTION_TYPE' };
31+
const expectedState = currentState;
32+
expect(errorsReducer(currentState, action)).toEqual(expectedState);
33+
});
34+
});

0 commit comments

Comments
 (0)