Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vzaidman committed Jul 9, 2017
1 parent 62c5ae8 commit 06d2341
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import recycleState from '../src'

describe('recycleState', () => {
let reducer = function (state = 'INITIAL_STATE', action) {
if (['KNOWN_ACTION', '@@redux-recycle/INIT'].indexOf(action.type) > -1) {
if (['KNOWN_ACTION', '@@redux-recycle/INIT', 'SPECIAL_RECYCLE_ACTION_NAME'].indexOf(action.type) > -1) {
return {
state,
type: action.type
Expand Down Expand Up @@ -35,4 +35,32 @@ describe('recycleState', () => {
let recycleableReducer = recycleState(reducer, ['RECYCLE'], resetReducer)
expect(recycleableReducer('A', { type: 'RECYCLE' })).to.deep.equal({ state: {oldState: 'A'}, type: '@@redux-recycle/INIT' })
})

it('special recycle action name', () => {
let recycleableReducer = recycleState(reducer, ['RECYCLE'], 'A', {recycleActionType: 'SPECIAL_RECYCLE_ACTION_NAME'})
expect(recycleableReducer('A', { type: 'RECYCLE' })).to.deep.equal({ state: 'A', type: 'SPECIAL_RECYCLE_ACTION_NAME' })
})

it('special recycle action name and initial state reducer', () => {
const resetReducer = (state, action) => {
return {oldState: state}
}

let recycleableReducer = recycleState(reducer, ['RECYCLE'], resetReducer, {recycleActionType: 'SPECIAL_RECYCLE_ACTION_NAME'})
expect(recycleableReducer('A', { type: 'RECYCLE' })).to.deep.equal({ state: {oldState: 'A'}, type: 'SPECIAL_RECYCLE_ACTION_NAME' })
})

it('no recycle action', () => {
let recycleableReducer = recycleState(reducer, ['RECYCLE'], 'A', {recycleActionType: false})
expect(recycleableReducer('A', { type: 'RECYCLE' })).to.deep.equal('A')
})

it('no recycle action and initial state reducer', () => {
const resetReducer = (state, action) => {
return {oldState: state}
}

let recycleableReducer = recycleState(reducer, ['RECYCLE'], resetReducer, {recycleActionType: false})
expect(recycleableReducer('A', { type: 'RECYCLE' })).to.deep.equal({oldState: 'A'})
})
})

0 comments on commit 06d2341

Please sign in to comment.