Skip to content

Commit 92582f6

Browse files
committed
Add chai support for "not" statements
1 parent 28e0e66 commit 92582f6

File tree

2 files changed

+119
-2
lines changed

2 files changed

+119
-2
lines changed

src/chai.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,46 @@ function registerAssertions() {
1818

1919
const state = utils.flag(this, 'state');
2020
if (state) {
21+
if (utils.flag(this, 'negate')) {
22+
return assertions.toNotDispatchActionsWithState(state, this._obj, expectedActions, done);
23+
}
2124
return assertions.toDispatchActionsWithState(state, this._obj, expectedActions, done);
2225
}
26+
if (utils.flag(this, 'negate')) {
27+
return assertions.toNotDispatchActions(this._obj, expectedActions, done);
28+
}
2329
return assertions.toDispatchActions(this._obj, expectedActions, done);
2430
}
2531

32+
function isDispatching(actualAction, expectedActions, done) {
33+
new _chai.Assertion(actualAction)
34+
.to.dispatch.actions(expectedActions, done);
35+
}
36+
2637
function isDispatchingWithState(actualAction, expectedActions, state, done) {
2738
new _chai.Assertion(actualAction)
2839
.with.state(state)
2940
.to.dispatch.actions(expectedActions, done);
3041
}
3142

32-
function isDispatching(actualAction, expectedActions, done) {
43+
function isNotDispatching(actualAction, expectedActions, done) {
3344
new _chai.Assertion(actualAction)
34-
.to.dispatch.actions(expectedActions, done);
45+
.to.not.dispatch.actions(expectedActions, done);
46+
}
47+
48+
function isNotDispatchingWithState(actualAction, expectedActions, state, done) {
49+
new _chai.Assertion(actualAction)
50+
.with.state(state)
51+
.to.not.dispatch.actions(expectedActions, done);
3552
}
3653

3754
_chai.Assertion.addChainableMethod('state', stateMethod);
3855
_chai.Assertion.addProperty('dispatch', dispatchProperty);
3956
_chai.Assertion.addMethod('actions', dispatchActionsMethod);
4057
_chai.assert.isDispatching = isDispatching;
4158
_chai.assert.isDispatchingWithState = isDispatchingWithState;
59+
_chai.assert.isNotDispatching = isNotDispatching;
60+
_chai.assert.isNotDispatchingWithState = isNotDispatchingWithState;
4261
});
4362
}
4463

test/chai/index.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,28 @@ describe('chai', () => {
4545
.to.dispatch.actions(actions.expectedParentActions, done);
4646
});
4747
});
48+
49+
describe('.not.dispatch.actions', () => {
50+
it('should accept single action', (done) => {
51+
expect(actions.start())
52+
.to.not.dispatch.actions(actions.anotherStart(), done);
53+
});
54+
55+
it('should accept array with one action', (done) => {
56+
expect(actions.start())
57+
.to.not.dispatch.actions([actions.anotherStart()], done);
58+
});
59+
60+
it('should accept array with multiple actions', (done) => {
61+
expect(actions.asyncActionCreator())
62+
.to.not.dispatch.actions(actions.anotherExpectedActions, done);
63+
});
64+
65+
it('should accept array with nested async action creators', (done) => {
66+
expect(actions.parentAsyncActionCreator())
67+
.to.not.dispatch.actions(actions.anotherParentExpectedActions, done);
68+
});
69+
});
4870
});
4971

5072
describe('should', () => {
@@ -83,6 +105,28 @@ describe('chai', () => {
83105
.dispatch.actions(actions.expectedParentActions, done);
84106
});
85107
});
108+
109+
describe('.not.dispath.actions', () => {
110+
it('should accept single action', (done) => {
111+
actions.start().should
112+
.not.dispatch.actions(actions.anotherStart(), done);
113+
});
114+
115+
it('should accept array with one action', (done) => {
116+
actions.start().should
117+
.not.dispatch.actions([actions.anotherStart()], done);
118+
});
119+
120+
it('should accept array with multiple actions', (done) => {
121+
actions.asyncActionCreator().should
122+
.not.dispatch.actions(actions.anotherExpectedActions, done);
123+
});
124+
125+
it('should accept array with nested async action creators', (done) => {
126+
actions.parentAsyncActionCreator().should
127+
.not.dispatch.actions(actions.anotherParentExpectedActions, done);
128+
});
129+
});
86130
});
87131

88132
describe('assert', () => {
@@ -106,6 +150,26 @@ describe('chai', () => {
106150
});
107151
});
108152

153+
describe('isNotDispatchingWithState', () => {
154+
it('should accept object as third argument', (done) => {
155+
assert.isNotDispatchingWithState(
156+
actions.actionCreatorWithGetState(),
157+
actions.actionWithGetState({ property: 'anotherParentAsyncActionCreator' }),
158+
{ property: 'value' },
159+
done
160+
);
161+
});
162+
163+
it('should accept function as third argument', (done) => {
164+
assert.isNotDispatchingWithState(
165+
actions.actionCreatorWithGetState(),
166+
actions.actionWithGetState({ property: 'anotherValue' }),
167+
() => { return { property: 'value' }; },
168+
done
169+
);
170+
});
171+
});
172+
109173
describe('isDispatching', () => {
110174
it('should accept single action', (done) => {
111175
assert.isDispatching(
@@ -139,5 +203,39 @@ describe('chai', () => {
139203
);
140204
});
141205
});
206+
207+
describe('isNotDispatching', () => {
208+
it('should accept single action', (done) => {
209+
assert.isNotDispatching(
210+
actions.start(),
211+
actions.anotherStart(),
212+
done
213+
);
214+
});
215+
216+
it('should accept array with one action', (done) => {
217+
assert.isNotDispatching(
218+
actions.start(),
219+
[actions.anotherStart()],
220+
done
221+
);
222+
});
223+
224+
it('should accept array with multiple actions', (done) => {
225+
assert.isNotDispatching(
226+
actions.asyncActionCreator(),
227+
actions.anotherExpectedActions,
228+
done
229+
);
230+
});
231+
232+
it('should accept array with nested async action creators', (done) => {
233+
assert.isNotDispatching(
234+
actions.parentAsyncActionCreator(),
235+
actions.anotherParentExpectedActions,
236+
done
237+
);
238+
});
239+
});
142240
});
143241
});

0 commit comments

Comments
 (0)