Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fbded5f

Browse files
committed
Add support for jest
1 parent 608a98b commit fbded5f

File tree

8 files changed

+126
-3
lines changed

8 files changed

+126
-3
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ It use [redux-mock-store](https://github.com/arnaudbenard/redux-mock-store) to m
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)
1414
- [jasmine](https://redux-things.github.io/redux-actions-assertions/jasmine.html)
15+
- [jest](https://redux-things.github.io/redux-actions-assertions/jest.html)
1516
- [should](https://redux-things.github.io/redux-actions-assertions/should.html)
1617
- [tape](https://redux-things.github.io/redux-actions-assertions/tape.html)
1718
- [pure javascript assertion](https://redux-things.github.io/redux-actions-assertions/javascript.html)

‎documentation/jest.md‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# [jest](https://github.com/facebook/jest)
2+
3+
## Registration
4+
5+
```js
6+
// add these two lines in your setupTestFrameworkScriptFile:
7+
// http://facebook.github.io/jest/docs/configuration.html#setuptestframeworkscriptfile-string
8+
import { registerAssertions } from 'redux-actions-assertions/jest';
9+
10+
beforeEach(registerAssertions);
11+
```
12+
13+
## Usage
14+
15+
### .toDispatchActions
16+
17+
> `expect(action).toDispatchActions(expectedActions, done)`
18+
19+
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.
20+
21+
```js
22+
expect(myActionCreator())
23+
.toDispatchActions({ type: 'MY_ACTION_START' }, done);
24+
```
25+
26+
### .toNotDispatchActions
27+
28+
> `expect(action).toNotDispatchActions(expectedActions, done)`
29+
30+
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.
31+
32+
```js
33+
expect(myActionCreator())
34+
.toNotDispatchActions({ type: 'MY_ACTION_START' }, done);
35+
```
36+
37+
### .toDispatchActionsWithState
38+
39+
> `expect(action).toDispatchActionsWithState(state, expectedActions, done)`
40+
41+
Asserts that store initialised with `state` before `action` is dispatched.
42+
43+
```js
44+
const state = {property: 'value'};
45+
const expectedActions = [{ type: 'MY_ACTION_START' }, finishActionCreator()];
46+
expect(myActionCreator())
47+
.toDispatchActionsWithState(state, expectedActions, done);
48+
```
49+
You can also use its variant `.toNotDispatchActionsWithState`:
50+
51+
```js
52+
expect(myActionCreator())
53+
.toNotDispatchActionsWithState(state, expectedActions, done);
54+
```

‎package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
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",
1010
"test:jasmine": "jasmine JASMINE_CONFIG_PATH=test/jasmine/jasmine.json",
11+
"test:jest": "jest --config test/jest/jest.json",
1112
"test:should": "mocha --compilers js:babel-register --reporter spec test/should/*.js",
1213
"test:tape": "tape --require babel-register test/tape/*.js",
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",
14+
"test": "npm run test:index && npm run test:chai && npm run test:expect && npm run test:expectjs && npm run test:jasmine && npm run test:jest && npm run test:should && npm run test:tape",
1415
"prepublish": "rimraf build && babel src --out-dir build --copy-files"
1516
},
1617
"repository": {
@@ -38,6 +39,7 @@
3839
"expect": "^1.20.1",
3940
"expect.js": "^0.3.1",
4041
"jasmine": "^2.5.2",
42+
"jest": "^18.1.0",
4143
"mocha": "^2.4.5",
4244
"redux-thunk": "^2.1.0",
4345
"rimraf": "^2.5.2",

‎src/jasmine.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,5 @@ function registerAssertions() {
5757
}
5858

5959
export {
60-
registerAssertions,
61-
matchers
60+
registerAssertions
6261
};

‎src/jest.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { registerAssertions } from './jasmine';
2+
3+
export { registerAssertions };

‎test/jest/index.js‎

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

‎test/jest/jest.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"testPathDirs": ["<rootDir>/test/jest"],
3+
"testRegex": "index.js",
4+
"setupTestFrameworkScriptFile": "<rootDir>/test/jest/setupFramework.js"
5+
}

‎test/jest/setupFramework.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { registerAssertions } from '../../src/jest';
2+
3+
beforeEach(registerAssertions);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /