Skip to content

Instantly share code, notes, and snippets.

@RocketPuppy
Created June 4, 2016 04:00
Show Gist options
  • Save RocketPuppy/1b4052bde2d5297c0b62996706df6c5e to your computer and use it in GitHub Desktop.
Save RocketPuppy/1b4052bde2d5297c0b62996706df6c5e to your computer and use it in GitHub Desktop.
function deleteTodo(text) {
return {
type: DELETE_TODO,
text: text
};
}
const initialState = []
function todoReducer(state = initialState, action) {
switch(action.type) {
case(DELETE_TODO):
return _.filter(todos, (todo) => todo.text = action.text);
}
}
describe('deleting a todo', () => {
describe('when there are no todos', () => {
const state = [];
it('returns the state unchanged', () => {
assertEqual(todoReducer(state, deleteTodo('foo')), state)
});
});
describe('when the todo exists alone', () => {
const theTodo = { text: 'foo' };
const state = [theTodo];
it('removes the todo', () => {
const newState = todoReducer(state, deleteTodo('foo'));
assert(!_.includes(newState, theTodo));
});
});
describe('when the todo exists with other todos', () => {
const firstTodo = { text: 'foo' };
const secondTodo = { text: 'bar' };
const state = [firstTodo, secondTodo];
it('removes the target todo', () => {
const newState = todoReducer(state, deleteTodo('foo'));
assert(!_.includes(newState, firstTodo));
});
it('leaves the other todos', () => {
const newState = todoReducer(state, deleteTodo('foo'));
assert(_.includes(newState, secondTodo));
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment