Skip to content

Commit 6d89a4b

Browse files
committed
Add support for jasmine 2.x
1 parent e984eea commit 6d89a4b

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed

package.json

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

test/jasmine/index.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
describe('jasmine', () => {
10+
beforeEach(() => { registerAssertions(); });
11+
describe('toDispatchActionsWithState', () => {
12+
it('should accept object', (done) => {
13+
const state = { property: 'value' };
14+
expect(actions.actionCreatorWithGetState())
15+
.toDispatchActionsWithState(state, actions.actionWithGetState({ property: 'value' }), done);
16+
});
17+
});
18+
19+
describe('.toDispatchActions', () => {
20+
it('should accept single action', (done) => {
21+
expect(actions.start()).toDispatchActions(actions.start(), done);
22+
});
23+
24+
it('should accept array with one action', (done) => {
25+
expect(actions.start()).toDispatchActions([actions.start()], done);
26+
});
27+
28+
it('should accept array with multiple actions', (done) => {
29+
expect(actions.asyncActionCreator())
30+
.toDispatchActions(actions.expectedActions, done);
31+
});
32+
33+
it('should accept array with nested async action creators', (done) => {
34+
expect(actions.parentAsyncActionCreator())
35+
.toDispatchActions(actions.expectedParentActions, done);
36+
});
37+
});
38+
39+
describe('.toNotDispatchActions', () => {
40+
it('should accept single action', (done) => {
41+
expect(actions.start()).toNotDispatchActions(actions.anotherStart(), done);
42+
});
43+
44+
it('should accept array with one action', (done) => {
45+
expect(actions.start()).toNotDispatchActions([actions.anotherStart()], done);
46+
});
47+
48+
it('should accept array with multiple actions', (done) => {
49+
expect(actions.asyncActionCreator())
50+
.toNotDispatchActions(actions.anotherExpectedActions, done);
51+
});
52+
53+
it('should accept array with nested async action creators', (done) => {
54+
expect(actions.parentAsyncActionCreator())
55+
.toNotDispatchActions(actions.anotherParentExpectedActions, done);
56+
});
57+
});
58+
});

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)