Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Copy tests to todos slice
- Loading branch information
1 parent
48ce059
commit b603312
Showing
1 changed file
with
123 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import todos from './todosSlice' | ||
|
||
describe('todos reducer', () => { | ||
it('should handle initial state', () => { | ||
expect(todos(undefined, {})).toEqual([]) | ||
}) | ||
|
||
it('should handle ADD_TODO', () => { | ||
expect( | ||
todos([], { | ||
type: 'ADD_TODO', | ||
text: 'Run the tests', | ||
id: 0 | ||
}) | ||
).toEqual([ | ||
{ | ||
text: 'Run the tests', | ||
completed: false, | ||
id: 0 | ||
} | ||
]) | ||
|
||
expect( | ||
todos( | ||
[ | ||
{ | ||
text: 'Run the tests', | ||
completed: false, | ||
id: 0 | ||
} | ||
], | ||
{ | ||
type: 'ADD_TODO', | ||
text: 'Use Redux', | ||
id: 1 | ||
} | ||
) | ||
).toEqual([ | ||
{ | ||
text: 'Run the tests', | ||
completed: false, | ||
id: 0 | ||
}, | ||
{ | ||
text: 'Use Redux', | ||
completed: false, | ||
id: 1 | ||
} | ||
]) | ||
|
||
expect( | ||
todos( | ||
[ | ||
{ | ||
text: 'Run the tests', | ||
completed: false, | ||
id: 0 | ||
}, | ||
{ | ||
text: 'Use Redux', | ||
completed: false, | ||
id: 1 | ||
} | ||
], | ||
{ | ||
type: 'ADD_TODO', | ||
text: 'Fix the tests', | ||
id: 2 | ||
} | ||
) | ||
).toEqual([ | ||
{ | ||
text: 'Run the tests', | ||
completed: false, | ||
id: 0 | ||
}, | ||
{ | ||
text: 'Use Redux', | ||
completed: false, | ||
id: 1 | ||
}, | ||
{ | ||
text: 'Fix the tests', | ||
completed: false, | ||
id: 2 | ||
} | ||
]) | ||
}) | ||
|
||
it('should handle TOGGLE_TODO', () => { | ||
expect( | ||
todos( | ||
[ | ||
{ | ||
text: 'Run the tests', | ||
completed: false, | ||
id: 1 | ||
}, | ||
{ | ||
text: 'Use Redux', | ||
completed: false, | ||
id: 0 | ||
} | ||
], | ||
{ | ||
type: 'TOGGLE_TODO', | ||
id: 1 | ||
} | ||
) | ||
).toEqual([ | ||
{ | ||
text: 'Run the tests', | ||
completed: true, | ||
id: 1 | ||
}, | ||
{ | ||
text: 'Use Redux', | ||
completed: false, | ||
id: 0 | ||
} | ||
]) | ||
}) | ||
}) |