@@ -2,23 +2,26 @@ import expect from 'expect';
22import * as performAssertionObj from '../../src/asserts/utils/performAssertion' ;
33import * as assertDispatchedActionsObj from '../../src/asserts/utils/assertDispatchedActions' ;
44import { toDispatchActionsWithState } from '../../src/asserts/toDispatchActionsWithState' ;
5- import { getInitialStoreState } from '../../src/initialState' ;
5+ import { registerInitialStoreState , getInitialStoreState } from '../../src/initialState' ;
66
77describe ( 'toDispatchActionsWithState' , ( ) => {
8- const initialState = getInitialStoreState ( ) ;
8+ let initialState ;
99 const actualAction = { actualAction : 'actualAction' } ;
1010 const expectedAction = { expectedAction : 'expectedAction' } ;
1111 const spyDone = expect . createSpy ( ) ;
1212 const spyFail = expect . createSpy ( ) ;
1313 const performAssertionResult = { result : 'result' } ;
1414
1515 beforeEach ( ( ) => {
16+ registerInitialStoreState ( { result : 'result' } ) ;
17+ initialState = getInitialStoreState ( ) ;
1618 expect . spyOn ( performAssertionObj , 'performAssertion' )
1719 . andReturn ( performAssertionResult ) ;
1820 expect . spyOn ( assertDispatchedActionsObj , 'assertDispatchedActions' ) ;
1921 } ) ;
2022
2123 afterEach ( ( ) => {
24+ registerInitialStoreState ( null ) ;
2225 expect . restoreSpies ( ) ;
2326 } ) ;
2427
@@ -47,4 +50,42 @@ describe('toDispatchActionsWithState', () => {
4750
4851 expect ( result ) . toBe ( performAssertionResult ) ;
4952 } ) ;
53+
54+ describe ( 'when state is a function' , ( ) => {
55+ const stateFunctionResult = { newResult : 'newResult' } ;
56+ let stateFunction ;
57+
58+ beforeEach ( ( ) => {
59+ stateFunction = expect . createSpy ( ) . andReturn ( stateFunctionResult ) ;
60+ } ) ;
61+
62+ it ( 'should execute it with initial state as argument' , ( ) => {
63+ toDispatchActionsWithState (
64+ stateFunction ,
65+ actualAction ,
66+ expectedAction ,
67+ spyDone , spyFail
68+ ) ;
69+
70+ expect ( stateFunction ) . toHaveBeenCalledWith ( initialState ) ;
71+ } ) ;
72+
73+ it ( 'should call performAssertion with result from state function as initial state' , ( ) => {
74+ toDispatchActionsWithState (
75+ stateFunction ,
76+ actualAction ,
77+ expectedAction ,
78+ spyDone , spyFail
79+ ) ;
80+
81+ expect ( performAssertionObj . performAssertion ) . toHaveBeenCalledWith (
82+ assertDispatchedActionsObj . assertDispatchedActions ,
83+ stateFunctionResult ,
84+ actualAction ,
85+ expectedAction ,
86+ spyDone ,
87+ spyFail
88+ ) ;
89+ } ) ;
90+ } ) ;
5091} ) ;
0 commit comments