reducer-tester
v1.1.3
Published
reducer tester
Downloads
2,286
Maintainers
Readme
reducer-tester
reducer tester
Install
$ yarn add --dev reducer-tester
Usage
// reducer.js
export const initialState = { count: 0, other: 'other' }
export default (state = initialState, action) => {
switch (action.type) {
case 'inc':
return { ...state, count: state.count + 1 }
case 'dec':
return { ...state, count: state.count - 1 }
default:
return state
}
}
// reducer.test.js
import reducerTester from 'reducer-tester'
import reducer, { initialState } from './reducer'
reducerTester({
reducer,
state: initialState,
tests: [{ type: 'inc' }, { type: 'dec' }],
})
Snapshot
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`handle initial state 1`] = `
"Snapshot Diff:
Compared values have no visual difference."
`;
exports[`dec 1`] = `
"Snapshot Diff:
- Before
+ After
Object {
- "count": 0,
+ "count": -1,
"other": "other",
}"
`;
exports[`inc 1`] = `
"Snapshot Diff:
- Before
+ After
Object {
- "count": 0,
+ "count": 1,
"other": "other",
}
`;
Full example
import reducerTester from 'reducer-tester'
import reducer, { initialState } from './reducer'
reducerTester({
reducer, // #required
state: initialState, // #required
tests: [{ type: 'inc' }, { type: 'dec' }], // #required
initialTest: false, // # optional, default: true
titlePrefix: 'handle ', // # optional, default: ''
})
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`handle dec 1`] = `
"Snapshot Diff:
- Before
+ After
Object {
- "count: 0,
+ count: -1,
}
`;
exports[`handle inc 1`] = `
"Snapshot Diff:
- Before
+ After
Object {
- count: 0,
+ count: 1,
}
`;
Tips
Atom Editor User
Install language-diff
and file-types
. And open config.json
and edit as blow.
"*":
"file-types":
"\\.js\\.snap$": "source.diff"
Hooray! Very readable!
Contributors
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
License
MIT © akameco