Skip to content

Commit 5d9603c

Browse files
committed
Initial commit
0 parents  commit 5d9603c

26 files changed

+963
-0
lines changed

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"es2015"
4+
]
5+
}

.eslintrc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"extends": "airbnb/base",
3+
"parserOptions": {
4+
"ecmaVersion": 6,
5+
"sourceType": "module",
6+
"ecmaFeatures": {
7+
},
8+
},
9+
"env": {
10+
"es6": true,
11+
"mocha": true
12+
},
13+
"rules": {
14+
"arrow-body-style": ["error", "always"],
15+
"prefer-const": 1,
16+
"no-param-reassign": 0,
17+
"new-cap": 0,
18+
"comma-dangle": [2, "never"],
19+
"spaced-comment": [2, "always", { exceptions: ["*", "-"] }],
20+
"quote-props": [2, "consistent"]
21+
}
22+
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
logs
2+
*.log
3+
node_modules
4+
lib

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src
2+
test

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- stable
5+
script:
6+
- npm run test
7+
- npm run prepublish
8+
branches:
9+
only:
10+
- master

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Dmitry Zaets
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
# redux-actions-assertions
2+
3+
Assertions for redux actions testing
4+
5+
This library add assertions for [redux actions](http://redux.js.org/docs/advanced/AsyncActions.html) testing.
6+
It use [redux-mock-store](https://github.com/arnaudbenard/redux-mock-store) to mock redux store.
7+
8+
## Supported Assertion Frameworks/Libraries:
9+
- [expect](https://github.com/mjackson/expect)
10+
- [chai](https://github.com/chaijs/chai)
11+
- [In Progress] [expect.js](https://github.com/Automattic/expect.js)
12+
- [In Progress] [should](https://github.com/shouldjs/should.js)
13+
- [In Progress] [jasmine](https://github.com/jasmine/jasmine) and [jest](https://github.com/facebook/jest)
14+
15+
If you have not found assertion framework/library that you are using - you still can use [pure assertion function]().
16+
17+
## Installation
18+
19+
Using [npm](https://www.npmjs.org/):
20+
21+
$ npm install --save expect-redux-actions
22+
23+
## Register redux middlewares
24+
25+
```js
26+
// using ES6 modules
27+
import { registerMiddlewares } from 'redux-actions-assertions';
28+
29+
// using CommonJS modules
30+
var registerMiddlewares = require('redux-actions-assertions').registerMiddlewares;
31+
32+
// registration
33+
registerMiddlewares([
34+
/* Here you need to list your middlewares */
35+
]);
36+
```
37+
38+
## Register default initial store state
39+
40+
**By using state object or function:**
41+
```js
42+
// using ES6 modules
43+
import { registerInitialStoreState } from 'redux-actions-assertions';
44+
45+
// using CommonJS modules
46+
var registerInitialStoreState = require('redux-actions-assertions').registerInitialStoreState;
47+
48+
// registration
49+
registerInitialStoreState(/* default initial state object or function */);
50+
```
51+
**By using your root reducer:**
52+
```js
53+
// using ES6 modules
54+
import { buildInitialStoreState, registerInitialStoreState } from 'redux-actions-assertions';
55+
56+
// using CommonJS modules
57+
var reduxActionsAssertions = require('redux-actions-assertions');
58+
var registerInitialStoreState = reduxActionsAssertions.registerInitialStoreState;
59+
var registerInitialStoreState = reduxActionsAssertions.registerInitialStoreState;
60+
61+
// registration
62+
registerInitialStoreState(buildInitialStoreState(/* root reducer function */));
63+
```
64+
65+
## javascript
66+
67+
### Registration
68+
69+
For plain javasript assertions you dont need to register anything. Just import assertions in your tests:
70+
71+
```js
72+
// using ES6 modules
73+
import assertions from 'redux-actions-assertions/assertions';
74+
75+
// using CommonJS modules
76+
var assertions = require('redux-actions-assertions/expect').assertions;
77+
78+
// in test
79+
assertions.toDispatchActions(/**/)
80+
assertions.toDispatchActionsWithState(/**/);
81+
```
82+
83+
### Usage
84+
85+
#### toDispatchActions
86+
> `toDispatchActions(action, expectedActions, done)`
87+
88+
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.
89+
90+
```js
91+
toDispatchActions(testActionCreator(), [{type: 'MY_ACTION_START'}], callback);
92+
```
93+
94+
#### toDispatchActionsWithState
95+
96+
> `toDispatchActionsWithState(initialState, action, expectedActions, done)`
97+
98+
Same as `toDispatchActions` + asserts that store initialised with `state` before `action` is dispatched.
99+
100+
```js
101+
toDispatchActions({property: 'value'}, testActionCreator(), [{type: 'MY_ACTION_START'}], callback);
102+
```
103+
104+
## [expect](https://github.com/mjackson/expect)
105+
106+
### Registration
107+
108+
```js
109+
// using ES6 modules
110+
import { registerAssertions } from 'redux-actions-assertions/expect';
111+
112+
// using CommonJS modules
113+
var registerAssertions = require('redux-actions-assertions/expect').registerAssertions;
114+
115+
// registration
116+
registerAssertions();
117+
```
118+
### Usage
119+
120+
#### toDispatchActions
121+
122+
> `expect(action).toDispatchActions(expectedActions, callback)`
123+
124+
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.
125+
126+
```js
127+
expect(myActionCreator())
128+
.toDispatchActions({type: 'MY_ACTION_START'}, callback);
129+
```
130+
131+
#### withState
132+
133+
> `expect(action).withState(state).toDispatchActions(expectedActions)`
134+
135+
Asserts that store initialised with `state` before `action` is dispatched.
136+
137+
```js
138+
expect(myActionCreator())
139+
.withState({property: 'value'})
140+
.toDispatchActions([{type: 'MY_ACTION_START'}, finishActionCreator()], callback);
141+
```
142+
143+
## [chai](https://github.com/chaijs/chai)
144+
145+
### Registration
146+
147+
```js
148+
// using ES6 modules
149+
import { registerAssertions } from 'redux-actions-assertions/chai';
150+
151+
// using CommonJS modules
152+
var registerAssertions = require('redux-actions-assertions/chai').registerAssertions;
153+
154+
// registration
155+
registerAssertions();
156+
```
157+
158+
#### .to.dispatch.actions(assert.isDispatching)
159+
160+
> `expect(action).to.dispatch.actions(expectedActions, callback)`
161+
> `action.should.dispatch.actions(expectedActions, callback)`
162+
> `assert.isDispatching(action, expectedActions, callback)`
163+
164+
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.
165+
166+
```js
167+
expect(myActionCreator())
168+
.to.dispatch.actions({type: 'MY_ACTION_START'}, callback);
169+
170+
myActionCreator()
171+
.should.dispatch.actions({type: 'MY_ACTION_START'}, callback);
172+
173+
assert.isDispatching(
174+
myActionCreator(),
175+
{type: 'MY_ACTION_START'},
176+
callback
177+
);
178+
```
179+
180+
#### .with.state(assert.isDispatchingWithState)
181+
182+
> `expect(action).with.state(state).to.dispatch.actions(expectedActions, callback)`
183+
> `action.should.with.state(state).dispatch.actions(expectedActions, callback)`
184+
> `assert.isDispatchingWithState(action, expectedActions, state, callback)`
185+
186+
Asserts that store initialised with `state` before `action` is dispatched.
187+
```js
188+
expect(myActionCreator())
189+
.with.state({ property: 'value' })
190+
.to.dispatch.actions([{type: 'MY_ACTION_START'}, finishActionCreator()], callback);
191+
192+
myActionCreator()
193+
.should.with.({ property: 'value' })
194+
.dispatch.actions([{type: 'MY_ACTION_START'}, finishActionCreator()], callback);
195+
196+
assert.isDispatchingWithState(
197+
myActionCreator(),
198+
[{type: 'MY_ACTION_START'}, finishActionCreator()],
199+
{ property: 'value' }
200+
callback
201+
);
202+
```
203+
204+
## [expect.js](https://github.com/Automattic/expect.js)
205+
206+
### Registration
207+
208+
```js
209+
// using ES6 modules
210+
import { registerAssertions } from 'redux-actions-assertions/expect.js';
211+
212+
// using CommonJS modules
213+
var registerAssertions = require('redux-actions-assertions/expect.js').registerAssertions;
214+
215+
// registration
216+
registerAssertions();
217+
```
218+
219+
## [should](https://github.com/shouldjs/should.js)
220+
221+
### Registration
222+
223+
```js
224+
// using ES6 modules
225+
import { registerAssertions } from 'redux-actions-assertions/should';
226+
227+
// using CommonJS modules
228+
var registerAssertions = require('redux-actions-assertions/should').registerAssertions;
229+
230+
// registration
231+
registerAssertions();
232+
```
233+
## [jasmine](https://github.com/jasmine/jasmine) and [jest](https://github.com/facebook/jest)
234+
235+
### Registration
236+
237+
```js
238+
// using ES6 modules
239+
import { registerAssertions } from 'redux-actions-assertions/jasmine';
240+
241+
// using CommonJS modules
242+
var registerAssertions = require('redux-actions-assertions/jasmine').registerAssertions;
243+
244+
// registration
245+
registerAssertions();
246+
```

package.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "redux-actions-assertions",
3+
"version": "0.0.0",
4+
"description": "Assertions for redux actions testing",
5+
"main": "lib/index.js",
6+
"scripts": {
7+
"lint": "eslint src test",
8+
"test:general": "mocha --compilers js:babel-register --reporter spec test/*.js",
9+
"test:expect": "mocha --compilers js:babel-register --reporter spec test/expect/*.js",
10+
"test": "npm run test:general && npm run test:expect",
11+
"prepublish": "rimraf lib && babel src --out-dir lib"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/dmitry-zaets/redux-actions-assertions.git"
16+
},
17+
"authors": [
18+
"Dmitry Zaets",
19+
"Yann Torres"
20+
],
21+
"license": "MIT",
22+
"bugs": {
23+
"url": "https://github.com/dmitry-zaets/redux-actions-assertions/issues"
24+
},
25+
"homepage": "https://github.com/dmitry-zaets/redux-actions-assertions#readme",
26+
"devDependencies": {
27+
"babel-cli": "^6.6.5",
28+
"babel-preset-es2015": "^6.6.0",
29+
"babel-register": "^6.7.2",
30+
"chai": "^3.5.0",
31+
"eslint": "^2.6.0",
32+
"eslint-config-airbnb": "^6.2.0",
33+
"eslint-plugin-babel": "^3.1.0",
34+
"expect": "^1.16.0",
35+
"expect.js": "^0.3.1",
36+
"jasmine": "^2.4.1",
37+
"mocha": "^2.4.5",
38+
"redux-thunk": "^2.0.1",
39+
"rimraf": "^2.5.2",
40+
"should": "^8.3.0"
41+
},
42+
"dependencies": {
43+
"lodash.find": "^4.3.0",
44+
"lodash.flattendeep": "^4.1.1",
45+
"redux": "^3.3.1",
46+
"redux-mock-store": "^1.0.2"
47+
}
48+
}

src/assertions/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import toDispatchActions from './toDispatchActions';
2+
import toDispatchActionsWithState from './toDispatchActionsWithState';
3+
4+
export default { toDispatchActions, toDispatchActionsWithState };
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import getInitialStoreState from '../initialState';
2+
import toDispatchActionsWithState from './toDispatchActionsWithState';
3+
4+
function toDispatchActions(actionUnderTest, expectedActions, done, fail) {
5+
return toDispatchActionsWithState(
6+
getInitialStoreState(),
7+
actionUnderTest,
8+
expectedActions,
9+
done, fail
10+
);
11+
}
12+
13+
export default toDispatchActions;

0 commit comments

Comments
 (0)