I'm trying to test my reducer, but my initial state don't change when I dispatch an action on the test.
That's my reducer:
export default function login(state = INITIAL_STATE, action) {
switch (action.type) {
case Types.SET_ERROR:
return {
...state,
error: action.error,
};
case Types.SET_LOGIN:
return {
...state,
user: {email: action.user.email, password: action.user.password},
};
default:
return state;
}
}
That's my test:
it('should handle SET_ERROR', () => {
const setErrorAction = {type: 'SET_ERROR', error: 'a'};
expect(login(INITIAL_STATE, setErrorAction)).toEqual({
...INITIAL_STATE,
error: 'a',
});
});
And that's my test result:
expect(received).toEqual(expected) // deep equality
- Expected
+ Received
Object {
- "error": "a",
+ "error": "",
"user": Object {
"email": "",
"password": "",
},
}
Aucun commentaire:
Enregistrer un commentaire