Skip to content

Commit f3386af

Browse files
committed
Add should support for "not" statements
1 parent bf16a48 commit f3386af

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

src/should.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,41 @@ function withState(state) {
66
this.obj = new ActionWithInitialState(this.obj, state);
77
}
88

9-
function dispatchActions(expectedActions, done) {
9+
function dispatchActionsFunction(assert, assertWithState, expectedActions, done) {
1010
if (this.obj instanceof ActionWithInitialState) {
1111
const action = this.obj.action;
1212
const state = this.obj.state;
13-
assertions.toDispatchActionsWithState(state, action, expectedActions, done);
13+
assertWithState(state, action, expectedActions, done);
1414
} else {
15-
assertions.toDispatchActions(this.obj, expectedActions, done);
15+
assert(this.obj, expectedActions, done);
1616
}
1717
}
1818

19+
function dispatchActions(expectedActions, done) {
20+
dispatchActionsFunction.call(
21+
this,
22+
assertions.toDispatchActions,
23+
assertions.toDispatchActionsWithState,
24+
expectedActions,
25+
done
26+
);
27+
}
28+
29+
function notDispatchActions(expectedActions, done) {
30+
dispatchActionsFunction.call(
31+
this,
32+
assertions.toNotDispatchActions,
33+
assertions.toNotDispatchActionsWithState,
34+
expectedActions,
35+
done
36+
);
37+
}
38+
1939
function registerAssertions() {
2040
should.Assertion.add('withState', withState);
2141
should.Assertion.alias('withState', 'state');
2242
should.Assertion.add('dispatchActions', dispatchActions);
43+
should.Assertion.add('notDispatchActions', notDispatchActions);
2344
}
2445

2546
export {

test/should/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,29 @@ describe('should', () => {
5858
.dispatchActions(actions.expectedParentActions, done);
5959
});
6060
});
61+
62+
describe('.notDispatchActions', () => {
63+
it('should accept single action', (done) => {
64+
should(actions.start()).notDispatchActions(actions.anotherStart(), done);
65+
});
66+
67+
it('should accept array with one action', (done) => {
68+
should(actions.start()).notDispatchActions([actions.anotherStart()], done);
69+
});
70+
71+
it('should accept array with multiple actions', (done) => {
72+
should(actions.asyncActionCreator())
73+
.notDispatchActions(actions.anotherExpectedActions, done);
74+
});
75+
76+
it('should accept array with nested async action creators', (done) => {
77+
should(actions.parentAsyncActionCreator())
78+
.notDispatchActions(actions.anotherParentExpectedActions, done);
79+
});
80+
81+
it('should work with .should', (done) => {
82+
actions.parentAsyncActionCreator().should
83+
.notDispatchActions(actions.anotherParentExpectedActions, done);
84+
});
85+
});
6186
});

0 commit comments

Comments
 (0)