Last active
March 21, 2016 20:03
-
-
Save josser/c705c9aa744370be8189 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
import { ADD_TODO } from 'constants/ActionTypes' | |
export const initialState = [ | |
{ | |
text: 'Use Redux', | |
completed: false, | |
id: 0 | |
} | |
] | |
export default function todos(state = initialState, action) { | |
switch (action.type) { | |
case ADD_TODO: | |
return [ | |
{ | |
id: state.reduce((maxId, todo) => Math.max(todo.id, maxId), -1) + 1, | |
completed: false, | |
text: action.text | |
}, | |
...state | |
] | |
default: | |
return state | |
} | |
} |
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
import expect from 'expect' | |
import reducer from 'reducers_todos' | |
import { initialState as stub } from 'reducers_todos' | |
import * as types from 'constants/ActionTypes' | |
var expectedState = { ...stub } | |
expectedState.push({ | |
text: 'Run the tests', | |
completed: false, | |
id: 0 | |
}) | |
it('should handle ADD_TODO', () => { | |
expect( | |
reducer(initialState, { | |
type: types.ADD_TODO, | |
text: 'Run the tests' | |
}) | |
).toEqual(expectedState) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment