Last active
August 25, 2016 07:18
-
-
Save piq9117/54cab79b83a8f5afad210bfe3c42756f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person = { | |
name: 'ken', | |
favoriteFood: [] | |
} | |
function addFood (state, action) { | |
return Object.assign({}, state, { | |
favorite: state.favoriteFood.concat(action.data.food) | |
}) | |
} | |
function reducer (state = person, action) { | |
switch (action.type) { | |
case 'ADD_FOOD', | |
return addFood(state, action) | |
// if it doesnt match any action type it will | |
// just return the state | |
default: | |
return state | |
} | |
} | |
describe('reducer', () => { | |
it('handles ADD_FOOD', () => { | |
const action = { | |
type: 'ADD_FOOD', | |
data: { | |
food: 'apple' | |
} | |
} | |
const result = reducer(person, action) | |
expect(result).to.deep.equal({ | |
name: 'ken', | |
favoriteFood: ['apple'] | |
}) | |
}) | |
// when I test the person object here it will come | |
// out the same | |
it('will not have a side effect', () => { | |
expect(person).to.deep.equal({ | |
name: 'ken', | |
favoriteFood: [] | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment