Of course, Test with Jest.
test('inc', () => {
expect(reducer(initialState, { type: 'inc' })).toEqual({ count: 1, text: '' })
})
test('inc', () => {
expect(reducer(initialState, { type: 'inc' })).toMatchObject({ count: 1 })
})
test('inc', () => {
expect(reducer(initialState, { type: 'inc' })).toMatchSnapshot()
})
snapshot:
exports[`inc 1`] = `
Object {
"count": 1,
"text": "",
}
`;
test('inc', () => {
expect(
snapshotDiff(initialState, reducer(initialState, { type: 'inc' }))
).toMatchSnapshot()
})
snapshot:
exports[`inc 1`] = `
"Snapshot Diff:
- First value
+ Second value
Object {
- \\"count\\": 0,
+ \\"count\\": 1,
\\"text\\": \\"\\",
}"
`;
reducerTester({
reducer,
state: initialState,
tests: [{ type: 'inc' }, { type: 'dec' }] // Just add any action...
})
snapshot:
exports[`inc 1`] = `
Snapshot Diff:
- Before
+ After
Object {
- "count": 0,
+ "count": 1,
"text": "",
}
`;
MIT © akameco