babel-plugin-s2s-reducer-test-case
v1.0.1
Published
create reducer test using switch/case
Downloads
16
Readme
babel-plugin-s2s-reducer-test-case
s2s plugin: create reducr test case from reducer.js
Install
$ npm install --save-dev babel-plugin-s2s-state-root
Example
reducer.js
import * as Actions from './actionTypes'
export const initialState = {
count: 0,
}
export default function(state = initialState, action) {
switch (action.type) {
case Actions.INCREMENT:
return { count: state + 1 }
case Actions.DECREMENT:
return { count: state - 1 }
default:
return state
}
}
IN:
import reducer, { initialState } from './actions'
OUT:
import reducer, { initialState } from './actions'
test('handle INCREMENT', () => {
expect(actions.increment()).toEqual({ count: 0 })
})
test('handle DECREMENT', () => {
expect(actions.decrement()).toEqual({ count: 0 })
})
And, Just change {count: 0}
→ {count: 1}
.
Usage
{
['s2s-reducer-test-case']
}
from
type: string
required: true
reducer.js path
If you use s2s
, you don't use this option.