Skip to content

Commit c4a5347

Browse files
committed
Change folder structure. Use files for import instead of folders
1 parent 2a8dd4b commit c4a5347

20 files changed

+375
-23
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
logs
22
*.log
33
node_modules
4-
lib
4+
build

.npmignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import { buildInitialStoreState, registerInitialStoreState } from 'redux-actions
5757
// using CommonJS modules
5858
var reduxActionsAssertions = require('redux-actions-assertions');
5959
var registerInitialStoreState = reduxActionsAssertions.registerInitialStoreState;
60-
var registerInitialStoreState = reduxActionsAssertions.registerInitialStoreState;
6160

6261
// registration
6362
registerInitialStoreState(buildInitialStoreState(/* root reducer function */));
@@ -212,10 +211,10 @@ expect(myActionCreator())
212211

213212
```js
214213
// using ES6 modules
215-
import { registerAssertions } from 'redux-actions-assertions/expect.js';
214+
import { registerAssertions } from 'redux-actions-assertions/expectjs';
216215

217216
// using CommonJS modules
218-
var registerAssertions = require('redux-actions-assertions/expect.js').registerAssertions;
217+
var registerAssertions = require('redux-actions-assertions/expectjs').registerAssertions;
219218

220219
// registration
221220
registerAssertions();

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
{
2-
"name": "redux-actions-assertions",
3-
"version": "1.0.0",
2+
"name": "redux-actions-assertions-src",
43
"description": "Assertions for redux actions testing",
5-
"main": "lib/index.js",
64
"scripts": {
75
"lint": "eslint src test",
86
"test:general": "mocha --compilers js:babel-register --reporter spec test/general/*.js test/assertions/*.js",
97
"test:chai": "mocha --compilers js:babel-register --reporter spec test/chai/*.js",
108
"test:expect": "mocha --compilers js:babel-register --reporter spec test/expect/*.js",
11-
"test:expectjs": "mocha --compilers js:babel-register --reporter spec test/expect.js/*.js",
9+
"test:expectjs": "mocha --compilers js:babel-register --reporter spec test/expectjs/*.js",
1210
"test:should": "mocha --compilers js:babel-register --reporter spec test/should/*.js",
1311
"test": "npm run test:general && npm run test:chai && npm run test:expect && npm run test:expectjs && npm run test:should",
14-
"prepublish": "rimraf lib && babel src --out-dir lib"
12+
"prepublish": "rimraf lib && babel src --out-dir build --copy-files"
1513
},
1614
"repository": {
1715
"type": "git",

src/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.

src/README.md

Lines changed: 306 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,306 @@
1+
# redux-actions-assertions
2+
Assertions for redux actions testing
3+
4+
This library add assertions for [redux actions](http://redux.js.org/docs/advanced/AsyncActions.html) testing.
5+
It use [redux-mock-store](https://github.com/arnaudbenard/redux-mock-store) to mock redux store.
6+
7+
[![build status](https://img.shields.io/travis/dmitry-zaets/redux-actions-assertions/master.svg?style=flat-square)](https://travis-ci.org/dmitry-zaets/redux-actions-assertions)
8+
[![npm version](https://img.shields.io/npm/v/redux-actions-assertions.svg?style=flat-square)](https://www.npmjs.com/package/redux-actions-assertions)
9+
10+
## Supported Assertion Frameworks/Libraries:
11+
- [chai](#chai)
12+
- [expect](#expect)
13+
- [expect.js](#expectjs)
14+
- [should](#should)
15+
16+
If you have not found assertion framework/library that you are using - you can use [pure javascript assertion](#javascript) or create an issue.
17+
18+
## Installation
19+
20+
Using [npm](https://www.npmjs.org/):
21+
22+
$ npm install --save expect-redux-actions
23+
24+
## Register redux middlewares
25+
26+
```js
27+
// using ES6 modules
28+
import { registerMiddlewares } from 'redux-actions-assertions';
29+
30+
// using CommonJS modules
31+
var registerMiddlewares = require('redux-actions-assertions').registerMiddlewares;
32+
33+
// registration
34+
registerMiddlewares([
35+
/* Here you need to list your middlewares */
36+
]);
37+
```
38+
39+
## Register default initial store state
40+
41+
**By using state object or function:**
42+
```js
43+
// using ES6 modules
44+
import { registerInitialStoreState } from 'redux-actions-assertions';
45+
46+
// using CommonJS modules
47+
var registerInitialStoreState = require('redux-actions-assertions').registerInitialStoreState;
48+
49+
// registration
50+
registerInitialStoreState(/* default initial state object or function */);
51+
```
52+
**By using your root reducer:**
53+
```js
54+
// using ES6 modules
55+
import { buildInitialStoreState, registerInitialStoreState } from 'redux-actions-assertions';
56+
57+
// using CommonJS modules
58+
var reduxActionsAssertions = require('redux-actions-assertions');
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/assertions');
77+
78+
// in test
79+
assertions.toDispatchActions(/**/)
80+
assertions.toDispatchActionsWithState(/**/);
81+
```
82+
83+
### Usage
84+
85+
#### toDispatchActions
86+
> `toDispatchActions(action, expectedActions, callback)`
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, callback)`
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+
## [chai](https://github.com/chaijs/chai)
105+
106+
### Registration
107+
108+
```js
109+
// using ES6 modules
110+
import { registerAssertions } from 'redux-actions-assertions/chai';
111+
112+
// using CommonJS modules
113+
var registerAssertions = require('redux-actions-assertions/chai').registerAssertions;
114+
115+
// registration
116+
registerAssertions();
117+
```
118+
119+
#### .to.dispatch.actions or assert.isDispatching
120+
121+
> `expect(action).to.dispatch.actions(expectedActions, callback)`
122+
123+
> `action.should.dispatch.actions(expectedActions, callback)`
124+
125+
> `assert.isDispatching(action, expectedActions, callback)`
126+
127+
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.
128+
129+
```js
130+
expect(myActionCreator())
131+
.to.dispatch.actions({type: 'MY_ACTION_START'}, callback);
132+
133+
myActionCreator()
134+
.should.dispatch.actions({type: 'MY_ACTION_START'}, callback);
135+
136+
assert.isDispatching(
137+
myActionCreator(),
138+
{type: 'MY_ACTION_START'},
139+
callback
140+
);
141+
```
142+
143+
#### .with.state or assert.isDispatchingWithState
144+
145+
> `expect(action).with.state(state).to.dispatch.actions(expectedActions, callback)`
146+
147+
> `action.should.with.state(state).dispatch.actions(expectedActions, callback)`
148+
149+
> `assert.isDispatchingWithState(action, expectedActions, state, callback)`
150+
151+
Asserts that store initialised with `state` before `action` is dispatched.
152+
```js
153+
expect(myActionCreator())
154+
.with.state({ property: 'value' })
155+
.to.dispatch.actions([{type: 'MY_ACTION_START'}, finishActionCreator()], callback);
156+
157+
myActionCreator()
158+
.should.with.({ property: 'value' })
159+
.dispatch.actions([{type: 'MY_ACTION_START'}, finishActionCreator()], callback);
160+
161+
assert.isDispatchingWithState(
162+
myActionCreator(),
163+
[{type: 'MY_ACTION_START'}, finishActionCreator()],
164+
{ property: 'value' }
165+
callback
166+
);
167+
```
168+
169+
## [expect](https://github.com/mjackson/expect)
170+
171+
### Registration
172+
173+
```js
174+
// using ES6 modules
175+
import { registerAssertions } from 'redux-actions-assertions/expect';
176+
177+
// using CommonJS modules
178+
var registerAssertions = require('redux-actions-assertions/expect').registerAssertions;
179+
180+
// registration
181+
registerAssertions();
182+
```
183+
### Usage
184+
185+
#### .toDispatchActions
186+
187+
> `expect(action).toDispatchActions(expectedActions, callback)`
188+
189+
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.
190+
191+
```js
192+
expect(myActionCreator())
193+
.toDispatchActions({type: 'MY_ACTION_START'}, callback);
194+
```
195+
196+
#### .withState
197+
198+
> `expect(action).withState(state).toDispatchActions(expectedActions, callback)`
199+
200+
Asserts that store initialised with `state` before `action` is dispatched.
201+
202+
```js
203+
expect(myActionCreator())
204+
.withState({property: 'value'})
205+
.toDispatchActions([{type: 'MY_ACTION_START'}, finishActionCreator()], callback);
206+
```
207+
208+
## [expect.js](https://github.com/Automattic/expect.js)
209+
210+
### Registration
211+
212+
```js
213+
// using ES6 modules
214+
import { registerAssertions } from 'redux-actions-assertions/expectjs';
215+
216+
// using CommonJS modules
217+
var registerAssertions = require('redux-actions-assertions/expectjs').registerAssertions;
218+
219+
// registration
220+
registerAssertions();
221+
```
222+
223+
### Usage
224+
225+
#### .dispatchActions
226+
227+
> `expect(action).to.dispatchActions(expectedActions, callback)`
228+
229+
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.
230+
231+
```js
232+
expect(myActionCreator())
233+
.to.dispatchActions({type: 'MY_ACTION_START'}, callback);
234+
```
235+
236+
#### .withState
237+
238+
> `expect(action).withState(state).to.dispatchActions(expectedActions, callback)`
239+
240+
Asserts that store initialised with `state` before `action` is dispatched.
241+
242+
```js
243+
expect(myActionCreator())
244+
.withState({property: 'value'})
245+
.to.dispatchActions([{type: 'MY_ACTION_START'}, finishActionCreator()], callback);
246+
```
247+
248+
## [should](https://github.com/shouldjs/should.js)
249+
250+
### Registration
251+
252+
```js
253+
// using ES6 modules
254+
import { registerAssertions } from 'redux-actions-assertions/should';
255+
256+
// using CommonJS modules
257+
var registerAssertions = require('redux-actions-assertions/should').registerAssertions;
258+
259+
// registration
260+
registerAssertions();
261+
```
262+
263+
### Usage
264+
265+
#### .dispatchActions
266+
267+
> `should(action).dispatchActions(expectedActions, callback)`
268+
> `action.should.dispatchActions(expectedActions, callback)`
269+
270+
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.
271+
272+
```js
273+
should(myActionCreator())
274+
.dispatchActions({type: 'MY_ACTION_START'}, callback);
275+
276+
myActionCreator().should
277+
.dispatchActions({type: 'MY_ACTION_START'}, callback);
278+
```
279+
280+
#### .withState or with.state
281+
282+
> `should(action).withState(state).dispatchActions(expectedActions, callback)`
283+
> `should(action).with.state(state).dispatchActions(expectedActions, callback)`
284+
285+
> `action.should.withState(state).dispatchActions(expectedActions, callback)`
286+
> `action.should.with.state(state).dispatchActions(expectedActions, callback)`
287+
288+
Asserts that store initialised with `state` before `action` is dispatched.
289+
290+
```js
291+
should(myActionCreator())
292+
.withState({property: 'value'})
293+
.dispatchActions({type: 'MY_ACTION_START'}, callback);
294+
295+
should(myActionCreator())
296+
.with.state({property: 'value'})
297+
.dispatchActions({type: 'MY_ACTION_START'}, callback);
298+
299+
myActionCreator().should
300+
.withState({property: 'value'})
301+
.dispatchActions({type: 'MY_ACTION_START'}, callback);
302+
303+
myActionCreator().should
304+
.with.state({property: 'value'})
305+
.dispatchActions({type: 'MY_ACTION_START'}, callback);
306+
```

src/assertions.js

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

0 commit comments

Comments
 (0)