Skip to content

Commit 409cc4c

Browse files
authored
Merge pull request #2 from dmitry-zaets/return-promise-from-assertion
Return Promise from Assertions
2 parents b2e9148 + eb66a73 commit 409cc4c

File tree

4 files changed

+54
-16
lines changed

4 files changed

+54
-16
lines changed

src/asserts/toDispatchActionsWithState.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { performAssertion } from './utils/performAssertion';
22
import { assertDispatchedActions } from './utils/assertDispatchedActions';
33

44
function toDispatchActionsWithState(initialState, action, expectedActions, done, fail) {
5-
performAssertion(assertDispatchedActions, initialState, action, expectedActions, done, fail);
5+
return performAssertion(
6+
assertDispatchedActions,
7+
initialState,
8+
action,
9+
expectedActions,
10+
done, fail
11+
);
612
}
713

814
export { toDispatchActionsWithState };

src/asserts/toNotDispatchActionsWithState.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { performAssertion } from './utils/performAssertion';
22
import { assertNotDispatchedActions } from './utils/assertNotDispatchedActions';
33

44
function toNotDispatchActionsWithState(initialState, action, expectedActions, done, fail) {
5-
performAssertion(assertNotDispatchedActions, initialState, action, expectedActions, done, fail);
5+
return performAssertion(
6+
assertNotDispatchedActions,
7+
initialState,
8+
action,
9+
expectedActions,
10+
done, fail
11+
);
612
}
713

814
export { toNotDispatchActionsWithState };

test/asserts/toDispatchActionsWithState.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ describe('toDispatchActionsWithState', () => {
1010
const expectedAction = { expectedAction: 'expectedAction' };
1111
const spyDone = expect.createSpy();
1212
const spyFail = expect.createSpy();
13+
const performAssertionResult = { result: 'result' };
1314

1415
beforeEach(() => {
15-
expect.spyOn(performAssertionObj, 'performAssertion');
16+
expect.spyOn(performAssertionObj, 'performAssertion')
17+
.andReturn(performAssertionResult);
1618
expect.spyOn(assertDispatchedActionsObj, 'assertDispatchedActions');
1719
});
1820

@@ -26,12 +28,23 @@ describe('toDispatchActionsWithState', () => {
2628
toDispatchActionsWithState(initialState, actualAction, expectedAction, spyDone, spyFail);
2729

2830
expect(performAssertionObj.performAssertion).toHaveBeenCalledWith(
29-
assertDispatchedActionsObj.assertDispatchedActions,
30-
initialState,
31-
actualAction,
32-
expectedAction,
33-
spyDone,
34-
spyFail
31+
assertDispatchedActionsObj.assertDispatchedActions,
32+
initialState,
33+
actualAction,
34+
expectedAction,
35+
spyDone,
36+
spyFail
3537
);
3638
});
39+
40+
it('should return result of performAssertion', () => {
41+
const result = toDispatchActionsWithState(
42+
initialState,
43+
actualAction,
44+
expectedAction,
45+
spyDone, spyFail
46+
);
47+
48+
expect(result).toBe(performAssertionResult);
49+
});
3750
});

test/asserts/toNotDispatchActionsWithState.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ describe('toNotDispatchActionsWithState', () => {
1010
const expectedAction = { expectedAction: 'expectedAction' };
1111
const spyDone = expect.createSpy();
1212
const spyFail = expect.createSpy();
13+
const performAssertionResult = { result: 'result' };
1314

1415
beforeEach(() => {
15-
expect.spyOn(performAssertionObj, 'performAssertion');
16+
expect.spyOn(performAssertionObj, 'performAssertion')
17+
.andReturn(performAssertionResult);
1618
expect.spyOn(assertNotDispatchedActionsObj, 'assertNotDispatchedActions');
1719
});
1820

@@ -26,12 +28,23 @@ describe('toNotDispatchActionsWithState', () => {
2628
toNotDispatchActionsWithState(initialState, actualAction, expectedAction, spyDone, spyFail);
2729

2830
expect(performAssertionObj.performAssertion).toHaveBeenCalledWith(
29-
assertNotDispatchedActionsObj.assertNotDispatchedActions,
30-
initialState,
31-
actualAction,
32-
expectedAction,
33-
spyDone,
34-
spyFail
31+
assertNotDispatchedActionsObj.assertNotDispatchedActions,
32+
initialState,
33+
actualAction,
34+
expectedAction,
35+
spyDone,
36+
spyFail
3537
);
3638
});
39+
40+
it('should return result of performAssertion', () => {
41+
const result = toNotDispatchActionsWithState(
42+
initialState,
43+
actualAction,
44+
expectedAction,
45+
spyDone, spyFail
46+
);
47+
48+
expect(result).toBe(performAssertionResult);
49+
});
3750
});

0 commit comments

Comments
 (0)