bonham000 / fcc-react-tests-module

The original freeCodeCamp React/Redux alpha curriculum.
http://hysterical-amusement.surge.sh/
BSD 3-Clause "New" or "Revised" License
77 stars 38 forks source link

Redux 09 tests #215

Closed dhcodes closed 7 years ago

dhcodes commented 7 years ago

I think there's an issue with the tests for Redux 09 in that the tests don't seem to ensure that the action is correctly logged. Below is my code that passes the test but results in undefined being logged 3 times:

const ADD = 'ADD';

const reducer = (state = 0, action) => {
    switch(action.type) {
        case ADD:
            return state + 1;
        default:
            return state;
    }
};

const store = Redux.createStore(reducer);

function hello(action) {
console.log(action)
}
// change code below this line
store.subscribe(hello)
// change code above this line

store.dispatch({type: ADD});
store.dispatch({type: ADD});
store.dispatch({type: ADD});
bonham000 commented 7 years ago

@dhcodes It's because store.subscribe doesn't receive the action object as an argument. The callback you pass to the subscribe method just gets called every time a store update occurs, so in this case when hello is called action is undefined.

dhcodes commented 7 years ago

@bonham000 sorry for not replying sooner; I guess I was asking if there'd be a way to use a test that ensured the callback returned 1, 2, and 3 and a string message per the instructions.

bonham000 commented 7 years ago

@dhcodes cool! I just modified the test to verify that at least the user is console.loging a string. Based on the instructions I don't think we can verify anything beyond that.