Tell us what’s happening:
Hello, I’m trying to not mutate state but I keep getting this alert when I run the test : “Dispatching an action of type ADD_TO_DO
on the Redux store should add a todo
item and should NOT mutate state.”
Someone can tell me what’s wrong please ?
**Your code so far**
const ADD_TO_DO = 'ADD_TO_DO';
// A list of strings representing tasks to do:
const todos = [
'Go to the store',
'Clean the house',
'Cook dinner',
'Learn to code',
];
const immutableReducer = (state = todos, action) => {
switch(action.type) {
case ADD_TO_DO:
return {
type: state.concat([
'Go to the store',
'Clean the house',
'Cook dinner',
'Learn to code',])
}
// Don't mutate state here or the tests will fail
return
default:
return state;
}
};
const addToDo = (todo) => {
return {
type: ADD_TO_DO,
todo
}
}
const store = Redux.createStore(immutableReducer);
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15
Challenge: Redux - Never Mutate State
Link to the challenge: