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