|
1 | | -import { isFunction, isObject } from '../utils'; |
2 | | -import { getDispatchedActions, unrollActions, assertDispatchedActions } from './actionUtils'; |
| 1 | +import { performAssertion } from './utils/performAssertion'; |
| 2 | +import { assertDispatchedActions } from './utils/assertDispatchedActions'; |
3 | 3 |
|
4 | | -function toDispatchActionsWithState(initialState, actionUnderTest, expectedActions, done, fail) { |
5 | | - if (!isFunction(actionUnderTest) && !isObject(actionUnderTest)) { |
6 | | - throw new Error( |
7 | | - 'The "actualAction" argument must be a function or an object' |
8 | | - ); |
9 | | - } |
10 | | - |
11 | | - if (!isFunction(expectedActions) && |
12 | | - !isObject(expectedActions) && |
13 | | - !Array.isArray(expectedActions)) { |
14 | | - throw new Error( |
15 | | - 'The "expectedActions" argument must be ' + |
16 | | - 'an action creator function, an action object, or an array of them' |
17 | | - ); |
18 | | - } |
19 | | - |
20 | | - return getDispatchedActions(initialState, actionUnderTest).then((dispatchedActions) => { |
21 | | - return unrollActions(initialState, expectedActions).then((expectedUnrolledActions) => { |
22 | | - assertDispatchedActions(dispatchedActions, expectedUnrolledActions); |
23 | | - |
24 | | - if (isFunction(done)) { |
25 | | - done(); |
26 | | - } |
27 | | - }); |
28 | | - }).catch((err) => { |
29 | | - if (isFunction(fail)) { |
30 | | - fail(err); |
31 | | - return; |
32 | | - } else if (isFunction(done)) { |
33 | | - done(err); |
34 | | - return; |
35 | | - } |
36 | | - throw new Error(JSON.stringify(err)); |
37 | | - }); |
| 4 | +function toDispatchActionsWithState(initialState, action, expectedActions, done, fail) { |
| 5 | + performAssertion(assertDispatchedActions, initialState, action, expectedActions, done, fail); |
38 | 6 | } |
39 | 7 |
|
40 | | -export { |
41 | | - toDispatchActionsWithState |
42 | | -}; |
| 8 | +export { toDispatchActionsWithState }; |
0 commit comments