Skip to content

Commit bb925b4

Browse files
authored
Merge pull request #29 from adamyonk/add_tape
Add tape support and docs
2 parents c36574f + 22183db commit bb925b4

File tree

5 files changed

+114
-7
lines changed

5 files changed

+114
-7
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
- [should](https://redux-things.github.io/redux-actions-assertions/should.html)
15+
- [tape](https://redux-things.github.io/redux-actions-assertions/tape.html)
1516
- [pure javascript assertion](https://redux-things.github.io/redux-actions-assertions/javascript.html)
1617

1718
If you have not found assertion framework/library that you are using - please add comment into [this issue](https://github.com/dmitry-zaets/redux-actions-assertions/issues/3).

docs/javascript.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
## Registration
44

5-
For plain javascript assertions you don't need to register anything. Just import assertions in your tests:
6-
75
```js
86
// using ES6 modules
9-
import assertions from 'redux-actions-assertions';
7+
import { assertions } from 'redux-actions-assertions';
108

119
// using CommonJS modules
12-
var assertions = require('redux-actions-assertions');
10+
var assertions = require('redux-actions-assertions').assertions;
1311

1412
// in test
1513
assertions.toDispatchActions(/**/)
@@ -18,6 +16,8 @@ assertions.toDispatchActionsWithState(/**/);
1816
assertions.toNotDispatchActionsWithState(/**/);
1917
```
2018

19+
For plain javascript assertions you don't need to register anything. Just import assertions in your tests:
20+
2121
## Usage
2222

2323
### toDispatchActions
@@ -56,4 +56,4 @@ Same as `toNotDispatchActions` + asserts that store initialised with `state` bef
5656

5757
```js
5858
toNotDispatchActions({property: 'value'}, testActionCreator(), [{ type: 'MY_ACTION_START' }], callback);
59-
```
59+
```

docs/tape.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# [tape](https://github.com/substack/tape)
2+
3+
## Usage
4+
5+
```js
6+
// using ES6 modules
7+
import test from 'tape'
8+
import { assertions } from 'redux-actions-assertions'
9+
10+
// using CommonJS modules
11+
var test = require('tape')
12+
var assertions = require('redux-actions-assertions').assertions;
13+
```
14+
15+
Usage is the same as the [plain JavaScript assertions](https://redux-things.github.io/redux-actions-assertions/javascript.html), you just need to set up the correct `pass` and `fail` callbacks. Also, be sure to call `end` in a `Promise.then`, or `plan` with the number of assertions you're making in the test (see below).
16+
17+
### toDispatchActions
18+
> `toDispatchActions(action, expectedActions, done, fail)`
19+
20+
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.
21+
22+
```js
23+
// Using `t.plan`
24+
test('Thunk: editTag', (t) => {
25+
t.plan(1)
26+
toDispatchActions(testActionCreator(), [{ type: 'MY_ACTION_START' }], t.pass, t.fail);
27+
})
28+
29+
// Using `t.end`
30+
test('Thunk: editTag', (t) => {
31+
toDispatchActions(testActionCreator(), [{ type: 'MY_ACTION_START' }], t.pass, t.fail)
32+
.then(t.end);
33+
})
34+
```
35+
36+
### toNotDispatchActions
37+
> `toNotDispatchActions(action, expectedActions, done, fail)`
38+
39+
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.
40+
41+
```js
42+
test('Thunk: editTag', (t) => {
43+
t.plan(1)
44+
toNotDispatchActions(testActionCreator(), [{ type: 'MY_ACTION_START' }], t.pass, t.fail);
45+
})
46+
```
47+
48+
### toDispatchActionsWithState
49+
50+
> `toDispatchActionsWithState(initialState, action, expectedActions, done, fail)`
51+
52+
Same as `toDispatchActions` + asserts that store initialised with `state` before `action` is dispatched.
53+
54+
```js
55+
test('Thunk: editTag', (t) => {
56+
t.plan(1)
57+
toDispatchActions({property: 'value'}, testActionCreator(), [{ type: 'MY_ACTION_START' }], t.pass, t.fail);
58+
})
59+
```
60+
61+
### toNotDispatchActionsWithState
62+
63+
> `toNotDispatchActionsWithState(initialState, action, expectedActions, done, fail)`
64+
65+
Same as `toNotDispatchActions` + asserts that store initialised with `state` before `action` is dispatched.
66+
67+
```js
68+
test('Thunk: editTag', (t) => {
69+
t.plan(1)
70+
toNotDispatchActions({property: 'value'}, testActionCreator(), [{ type: 'MY_ACTION_START' }], t.pass, t.fail);
71+
})
72+
```

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
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:should": "mocha --compilers js:babel-register --reporter spec test/should/*.js",
11-
"test": "npm run test:index && npm run test:chai && npm run test:expect && npm run test:expectjs && npm run test:should",
11+
"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",
1213
"prepublish": "rimraf build && babel src --out-dir build --copy-files"
1314
},
1415
"repository": {
@@ -38,7 +39,8 @@
3839
"mocha": "^2.4.5",
3940
"redux-thunk": "^2.1.0",
4041
"rimraf": "^2.5.2",
41-
"should": "^8.3.2"
42+
"should": "^8.3.2",
43+
"tape": "^4.6.0"
4244
},
4345
"dependencies": {
4446
"redux-actions-assertions-js": "^1.1.0"

test/tape/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import test from 'tape';
2+
import thunk from 'redux-thunk';
3+
4+
import { assertions, registerMiddlewares } from '../../src';
5+
import actions from '../testingData/actions';
6+
7+
registerMiddlewares([thunk]);
8+
9+
test('tape', t => {
10+
t.plan(1);
11+
const msg = 'should pass with t.plan';
12+
13+
assertions.toDispatchActionsWithState(
14+
{ property: 'value' },
15+
actions.actionCreatorWithGetState(),
16+
actions.actionWithGetState({ property: 'value' }),
17+
t.pass.bind(this, msg),
18+
t.fail.bind(this, msg)
19+
);
20+
});
21+
22+
test('tape', t => {
23+
const msg = 'should pass with t.end';
24+
25+
assertions.toDispatchActionsWithState(
26+
{ property: 'value' },
27+
actions.actionCreatorWithGetState(),
28+
actions.actionWithGetState({ property: 'value' }),
29+
t.pass.bind(this, msg),
30+
t.fail.bind(this, msg)
31+
).then(t.end);
32+
});

0 commit comments

Comments
 (0)