File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed
Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change 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" ,
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" ,
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments