Skip to content

Commit 608a98b

Browse files
authored
Merge pull request #34 from giuband/jasmine
Add support for jasmine 2.x
2 parents e984eea + f63c61e commit 608a98b

File tree

6 files changed

+211
-1
lines changed

6 files changed

+211
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ It use [redux-mock-store](https://github.com/arnaudbenard/redux-mock-store) to m
1111
- [chai](https://redux-things.github.io/redux-actions-assertions/chai.html)
1212
- [expect](https://redux-things.github.io/redux-actions-assertions/expect.html)
1313
- [expect.js](https://redux-things.github.io/redux-actions-assertions/expectjs.html)
14+
- [jasmine](https://redux-things.github.io/redux-actions-assertions/jasmine.html)
1415
- [should](https://redux-things.github.io/redux-actions-assertions/should.html)
1516
- [tape](https://redux-things.github.io/redux-actions-assertions/tape.html)
1617
- [pure javascript assertion](https://redux-things.github.io/redux-actions-assertions/javascript.html)

documentation/jasmine.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# [jasmine](https://github.com/jasmine/jasmine)
2+
3+
## Registration
4+
5+
```js
6+
// using ES6 modules
7+
import { registerAssertions } from 'redux-actions-assertions/jasmine';
8+
9+
// using CommonJS modules
10+
var registerAssertions = require('redux-actions-assertions/jasmine').registerAssertions;
11+
12+
// registration
13+
beforeEach(registerAssertions);
14+
```
15+
16+
## Usage
17+
18+
### .toDispatchActions
19+
20+
> `expect(action).toDispatchActions(expectedActions, done)`
21+
22+
Asserts that when given `action` is dispatched it will dispatch `expectedActions`. `action` can be plain object (action) or function (action creator). `expectedActions` can be can be plain object (action) or function (action creator) or array of objects/functions.
23+
24+
```js
25+
expect(myActionCreator())
26+
.toDispatchActions({ type: 'MY_ACTION_START' }, done);
27+
```
28+
29+
### .not.toDispatchActions
30+
31+
> `expect(action).not.toDispatchActions(expectedActions, done)`
32+
33+
Asserts that when given `action` is dispatched it will not dispatch `expectedActions`. `action` can be plain object (action) or function (action creator). `expectedActions` can be can be plain object (action) or function (action creator) or array of objects/functions.
34+
35+
```js
36+
expect(myActionCreator())
37+
.not.toDispatchActions({ type: 'MY_ACTION_START' }, done);
38+
```
39+
40+
### .toDispatchActionsWithState
41+
42+
> `expect(action).toDispatchActionsWithState(state, expectedActions, done)`
43+
44+
Asserts that store initialised with `state` before `action` is dispatched.
45+
46+
```js
47+
const state = {property: 'value'};
48+
const expectedActions = [{ type: 'MY_ACTION_START' }, finishActionCreator()];
49+
expect(myActionCreator())
50+
.toDispatchActionsWithState(state, expectedActions, done);
51+
```
52+
You can also use it with `.not`:
53+
54+
```js
55+
expect(myActionCreator())
56+
.not.toDispatchActionsWithState(state, expectedActions, done);
57+
```

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
"test:chai": "mocha --compilers js:babel-register --reporter spec test/chai/*.js",
88
"test:expect": "mocha --compilers js:babel-register --reporter spec test/expect/*.js",
99
"test:expectjs": "mocha --compilers js:babel-register --reporter spec test/expectjs/*.js",
10+
"test:jasmine": "jasmine JASMINE_CONFIG_PATH=test/jasmine/jasmine.json",
1011
"test:should": "mocha --compilers js:babel-register --reporter spec test/should/*.js",
1112
"test:tape": "tape --require babel-register test/tape/*.js",
12-
"test": "npm run test:index && npm run test:chai && npm run test:expect && npm run test:expectjs && npm run test:should && npm run test:tape",
13+
"test": "npm run test:index && npm run test:chai && npm run test:expect && npm run test:expectjs && npm run test:jasmine && npm run test:should && npm run test:tape",
1314
"prepublish": "rimraf build && babel src --out-dir build --copy-files"
1415
},
1516
"repository": {
@@ -36,6 +37,7 @@
3637
"eslint-plugin-import": "^1.8.0",
3738
"expect": "^1.20.1",
3839
"expect.js": "^0.3.1",
40+
"jasmine": "^2.5.2",
3941
"mocha": "^2.4.5",
4042
"redux-thunk": "^2.1.0",
4143
"rimraf": "^2.5.2",

src/jasmine.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* eslint-env jasmine */
2+
import { assertions } from 'redux-actions-assertions-js';
3+
4+
function toDispatchActions() {
5+
return {
6+
compare(action, expectedActions, done) {
7+
assertions.toDispatchActions(action, expectedActions, done, done.fail);
8+
return { pass: true };
9+
},
10+
negativeCompare(action, expectedActions, done) {
11+
assertions.toNotDispatchActions(action, expectedActions, done, done.fail);
12+
return { pass: true };
13+
}
14+
};
15+
}
16+
17+
function toNotDispatchActions() {
18+
return {
19+
compare(action, expectedActions, done) {
20+
assertions.toNotDispatchActions(action, expectedActions, done, done.fail);
21+
return { pass: true };
22+
}
23+
};
24+
}
25+
26+
function toDispatchActionsWithState() {
27+
return {
28+
compare(action, state, expectedActions, done) {
29+
assertions.toDispatchActionsWithState(state, action, expectedActions, done, done.fail);
30+
return { pass: true };
31+
},
32+
negativeCompare(action, state, expectedActions, done) {
33+
assertions.toNotDispatchActionsWithState(state, action, expectedActions, done, done.fail);
34+
return { pass: true };
35+
}
36+
};
37+
}
38+
39+
function toNotDispatchActionsWithState() {
40+
return {
41+
compare(action, state, expectedActions, done) {
42+
assertions.toNotDispatchActionsWithState(state, action, expectedActions, done, done.fail);
43+
return { pass: true };
44+
}
45+
};
46+
}
47+
48+
const matchers = {
49+
toDispatchActions,
50+
toNotDispatchActions,
51+
toDispatchActionsWithState,
52+
toNotDispatchActionsWithState
53+
};
54+
55+
function registerAssertions() {
56+
jasmine.addMatchers(matchers);
57+
}
58+
59+
export {
60+
registerAssertions,
61+
matchers
62+
};

test/jasmine/index.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* eslint-env jasmine */
2+
import thunk from 'redux-thunk';
3+
import { registerMiddlewares } from '../../src';
4+
import { registerAssertions } from '../../src/jasmine';
5+
import actions from '../testingData/actions';
6+
7+
registerMiddlewares([thunk]);
8+
9+
beforeEach(registerAssertions);
10+
11+
describe('jasmine', () => {
12+
describe('toDispatchActionsWithState', () => {
13+
it('should accept object', (done) => {
14+
const state = { property: 'value' };
15+
expect(actions.actionCreatorWithGetState())
16+
.toDispatchActionsWithState(state, actions.actionWithGetState({ property: 'value' }), done);
17+
});
18+
});
19+
20+
describe('.toDispatchActions', () => {
21+
it('should accept single action', (done) => {
22+
expect(actions.start()).toDispatchActions(actions.start(), done);
23+
});
24+
25+
it('should accept array with one action', (done) => {
26+
expect(actions.start()).toDispatchActions([actions.start()], done);
27+
});
28+
29+
it('should accept array with multiple actions', (done) => {
30+
expect(actions.asyncActionCreator())
31+
.toDispatchActions(actions.expectedActions, done);
32+
});
33+
34+
it('should accept array with nested async action creators', (done) => {
35+
expect(actions.parentAsyncActionCreator())
36+
.toDispatchActions(actions.expectedParentActions, done);
37+
});
38+
});
39+
40+
describe('.toNotDispatchActions', () => {
41+
it('should accept single action', (done) => {
42+
expect(actions.start()).toNotDispatchActions(actions.anotherStart(), done);
43+
});
44+
45+
it('should accept array with one action', (done) => {
46+
expect(actions.start()).toNotDispatchActions([actions.anotherStart()], done);
47+
});
48+
49+
it('should accept array with multiple actions', (done) => {
50+
expect(actions.asyncActionCreator())
51+
.toNotDispatchActions(actions.anotherExpectedActions, done);
52+
});
53+
54+
it('should accept array with nested async action creators', (done) => {
55+
expect(actions.parentAsyncActionCreator())
56+
.toNotDispatchActions(actions.anotherParentExpectedActions, done);
57+
});
58+
});
59+
60+
describe('.not.toDispatchActions', () => {
61+
it('should accept single action', (done) => {
62+
expect(actions.start()).not.toDispatchActions(actions.anotherStart(), done);
63+
});
64+
65+
it('should accept array with one action', (done) => {
66+
expect(actions.start()).not.toDispatchActions([actions.anotherStart()], done);
67+
});
68+
69+
it('should accept array with multiple actions', (done) => {
70+
expect(actions.asyncActionCreator())
71+
.not.toDispatchActions(actions.anotherExpectedActions, done);
72+
});
73+
74+
it('should accept array with nested async action creators', (done) => {
75+
expect(actions.parentAsyncActionCreator())
76+
.not.toDispatchActions(actions.anotherParentExpectedActions, done);
77+
});
78+
});
79+
});

test/jasmine/jasmine.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"spec_dir": "test/jasmine",
3+
"spec_files": [
4+
"*.js"
5+
],
6+
"helpers": [
7+
"../../node_modules/babel-register/lib/node.js"
8+
]
9+
}

0 commit comments

Comments
 (0)