Skip to content

Commit dd9cf35

Browse files
committed
attempt on tests
1 parent f161a5b commit dd9cf35

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"clean": "rimraf lib",
99
"lint": "eslint src",
1010
"prepublish": "npm run lint && npm run clean && npm run build",
11-
"test": "echo \"Error: no test specified\" && exit 1"
11+
"test": "babel-node test/index.js"
1212
},
1313
"keywords": [
1414
"redux",
@@ -36,7 +36,9 @@
3636
"eslint": "^3.13.1",
3737
"eslint-config-airbnb-base": "^11.0.1",
3838
"eslint-plugin-import": "^2.2.0",
39-
"rimraf": "^2.5.4"
39+
"rimraf": "^2.5.4",
40+
"sinon": "^5.0.10",
41+
"tape": "^4.9.0"
4042
},
4143
"files": [
4244
"README.md",

test/index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import test from 'tape';
2+
import sinon from 'sinon';
3+
import createApiMiddleware, {
4+
CALL_API,
5+
CALL_API_PHASE,
6+
callApiPhases,
7+
actionWith,
8+
} from '../src/index';
9+
10+
function sleep(ms, shouldResolve, response) {
11+
return new Promise((resolve, reject) => (
12+
shouldResolve ? resolve(response) : reject(response)
13+
));
14+
}
15+
16+
// test('Tests ara running', (t) => {
17+
// t.end();
18+
// });
19+
20+
test('Calls fetch function', (t) => {
21+
const spy = sinon.spy();
22+
const apiMiddleware = createApiMiddleware({ callApi: spy });
23+
const doGetState = () => {};
24+
const doDispatch = () => {};
25+
const nextHandler = apiMiddleware({ getState: doGetState, dispatch: doDispatch });
26+
const doNext = () => {};
27+
const actionHandler = nextHandler(doNext);
28+
actionHandler({
29+
[CALL_API]: {
30+
types: ['REQUEST', 'SUCCESS', 'FAILURE'],
31+
endpoint: 'endpoint',
32+
options: {},
33+
},
34+
});
35+
console.log(spy.args);
36+
t.true(spy.calledOnce);
37+
t.end();
38+
});

0 commit comments

Comments
 (0)