What's wrong ? can't pass

BUG?


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:
    // don't mutate state here or the tests will fail
    let x=[...todos];
   x.push(action.todo);
   return x;
  default:
    return state;
}
};

// an example todo argument would be 'Learn React',
const addToDo = (todo) => {
return {
  type: ADD_TO_DO,
  todo
}
}

const store = Redux.createStore(immutableReducer);
store.dispatch(addToDo("Learn React"));



Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362.

Challenge: Never Mutate State

Link to the challenge:

Hello there,

You cannot pass, because of this line:

store.dispatch(addToDo("Learn React"));

If you are dispatching an action, you are changing the state in a way where it does not equal the initial state. So, the test fails.

Here is the test:

assert((function() { const todos = [ 'Go to the store', 'Clean the house', 'Cook dinner', 'Learn to code' ]; const initialState = store.getState(); return Array.isArray(initialState) && initialState.join(',') === todos.join(','); })());

Hope this clarifies.

thx it works
…………………