Skip to content

Instantly share code, notes, and snippets.

@piq9117
Created August 30, 2016 19:52
Show Gist options
  • Save piq9117/2323e8ec09551d64062678d9cf98288a to your computer and use it in GitHub Desktop.
Save piq9117/2323e8ec09551d64062678d9cf98288a to your computer and use it in GitHub Desktop.
'use strict'
/* global describe, it */
import { expect } from 'chai'
import reducer from './index'
const initialState = {
'developer1': {
name: 'ken',
hairColor: 'black',
iceCreamFlavor: '',
favoriteFood: [
'apple',
'chips',
'car'
]
},
'developer2': {
name: 'tony',
hairColor: 'blonde',
iceCreamFlavor: '',
favoriteFood: [
'bacon',
'siomai'
]
}
}
describe('reducer', () => {
it('handles ADD_FOOD', () => {
const action = {
type: 'ADD_FOOD',
data: {
id: 'developer1',
prop: 'favoriteFood',
food: ['more food']
}
}
const nextState = reducer(initialState, action)
expect(nextState).to.deep.equal({
'developer1': {
name: 'ken',
hairColor: 'black',
iceCreamFlavor: '',
favoriteFood: [
'apple',
'chips',
'car',
'more food'
]
},
'developer2': {
name: 'tony',
hairColor: 'blonde',
iceCreamFlavor: '',
favoriteFood: [
'bacon',
'siomai'
]
}
})
})
it('handles ICE_CREAM_FLAVOR', () => {
const action = {
type: 'ICE_CREAM_FLAVOR',
data: {
id: 'developer2',
prop: 'iceCreamFlavor',
flavor: 'wasabi'
}
}
const nextState = reducer(initialState, action)
expect(nextState).to.deep.equal({
'developer1': {
name: 'ken',
hairColor: 'black',
iceCreamFlavor: '',
favoriteFood: [
'apple',
'chips',
'car'
]
},
'developer2': {
name: 'tony',
hairColor: 'blonde',
iceCreamFlavor: 'wasabi',
favoriteFood: [
'bacon',
'siomai'
]
}
})
})
it(`doesn't have side effect`, () => {
expect(initialState).to.deep.equal({
'developer1': {
name: 'ken',
hairColor: 'black',
iceCreamFlavor: '',
favoriteFood: [
'apple',
'chips',
'car'
]
},
'developer2': {
name: 'tony',
hairColor: 'blonde',
iceCreamFlavor: '',
favoriteFood: [
'bacon',
'siomai'
]
}
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment