UNPKG

react-redux-with-path

Version:

A version of react-redux designed for cases that want to access sub-tree of the state. and take it as state in mapStateToProps and mapDispatchToProps

80 lines (63 loc) 2.17 kB
import expect from 'expect'; import { wrapActionCreatorWithPath, bindActionCreator } from '../bindActionCreators'; describe('bindActionCreators', () => { let actionCreatorA; let actionCreatorB; let actionCreators; const path = 'd9729feb74992cc3482b350163a1a010'; before(() => { actionCreatorA = (payload) => ({ type: 'ACTION_TYPE_A', payload, }); actionCreatorB = (payload) => ({ type: 'ACTION_TYPE_B', payload, }); actionCreators = { actionCreatorA, actionCreatorB }; }); describe('actionCreator should return action', () => { it('actioncreators should return as expected', () => { const actionA = actionCreatorA(8); const actionB = actionCreatorB(['a', 'b']); expect(actionA).toEqual({ type: 'ACTION_TYPE_A', payload: 8 }); expect(actionB).toEqual({ type: 'ACTION_TYPE_B', payload: ['a', 'b'] }); }); }); describe('wrapActionCreatorWithPath', () => { it('should wrap actionCreator with path', () => { const wrappedActionCreatorA = wrapActionCreatorWithPath( actionCreatorA, path ); const wrappedActionCreatorB = wrapActionCreatorWithPath( actionCreatorB, path ); const wrappedActionA = wrappedActionCreatorA(8); const wrappedActionB = wrappedActionCreatorB(['a', 'b']); expect(wrappedActionA.path).toEqual(path); expect(wrappedActionB.path).toEqual(path); }); }); describe('bindActionCreator', () => { let dispatch; before(() => { dispatch = action => action; }) it('should return as normal when path is not provided', () => { const boundActionCreatorA = bindActionCreator(actionCreatorA, dispatch); const res = boundActionCreatorA(8); expect(Object.keys(res)).toEqual(['type', 'payload']); }); it('should return as expected when path is provided', () => { const boundActionCreatorA = bindActionCreator(actionCreatorA, dispatch, path); const res = boundActionCreatorA(8); expect(Object.keys(res)).toEqual(['type', 'payload', 'path']); expect(res.path).toBe(path); }); }); });