@@ -10,26 +10,28 @@ const expect = chai.expect;
1010
1111// prepared spies
1212var globalNeedsRefetching = false ; // this is really disgusting, I know...
13- const needsRefetching = chai . spy ( ( ) => globalNeedsRefetching ) ;
14- const createAction = chai . spy ( ) ;
15- const createApiAction = chai . spy ( ) ;
13+ const needsRefetchingOriginal = ( ) => globalNeedsRefetching ;
14+ let needsRefetching = null ;
15+ let createAction = null ;
16+ let createApiAction = null ;
1617
1718const actionTypes = actionTypesFactory ( 'abc' , 'xyz' ) ;
18- const actionCreators = actionCreatorsFactory ( {
19- actionTypes,
20- selector : state => state ,
21- apiEndpointFactory : ( id = '' ) => `url/${ id } ` ,
22- needsRefetching,
23- createAction,
24- createApiAction,
25- } ) ;
19+ let actionCreators = null ;
2620
2721describe ( 'Resource manager' , ( ) => {
2822 describe ( '(Action creators)' , ( ) => {
29- beforeEach ( function ( ) {
30- needsRefetching . reset ( ) ;
31- createAction . reset ( ) ;
32- createApiAction . reset ( ) ;
23+ beforeEach ( function ( ) {
24+ needsRefetching = chai . spy ( needsRefetchingOriginal ) ;
25+ createAction = chai . spy ( ) ;
26+ createApiAction = chai . spy ( ) ;
27+ actionCreators = actionCreatorsFactory ( {
28+ actionTypes,
29+ selector : state => state ,
30+ apiEndpointFactory : ( id = '' ) => `url/${ id } ` ,
31+ needsRefetching,
32+ createAction,
33+ createApiAction,
34+ } ) ;
3335 } ) ;
3436
3537 describe ( 'FETCH' , ( ) => {
@@ -42,7 +44,7 @@ describe('Resource manager', () => {
4244
4345 // calling fetchResource will create an action through the 'createApiAction' function
4446 fetchResource ( 'abc' ) ;
45- expect ( createApiAction ) . to . have . been . called . once ( ) ;
47+ expect ( createApiAction ) . to . have . been . called . once ;
4648 expect ( createApiAction ) . to . have . been . called . with ( {
4749 type : actionTypes . FETCH ,
4850 method : 'GET' ,
@@ -94,7 +96,7 @@ describe('Resource manager', () => {
9496 const dispatch = chai . spy ( ) ;
9597 thunk ( dispatch , getState ) ; // we don't care about the resulting state in this test
9698
97- expect ( dispatch ) . to . have . been . called . once ( ) ;
99+ expect ( dispatch ) . to . have . been . called . once ;
98100 expect ( dispatch ) . to . have . been . called . with ( fetchResource ( 'abc' ) ) ;
99101 } ) ;
100102 } ) ;
@@ -109,7 +111,7 @@ describe('Resource manager', () => {
109111
110112 // calling fetchResource will create an action through the 'createApiAction' function
111113 fetchMany ( { } ) ;
112- expect ( createApiAction ) . to . have . been . called . once ( ) ;
114+ expect ( createApiAction ) . to . have . been . called . once ;
113115 expect ( createApiAction ) . to . have . been . called . with ( {
114116 type : actionTypes . FETCH_MANY ,
115117 method : 'GET' ,
@@ -128,7 +130,7 @@ describe('Resource manager', () => {
128130 const body = { foo : 'bar' , abc : 'xyz' } ;
129131 const tmpId = 'random-tmp-id' ;
130132 addResource ( body , tmpId ) ;
131- expect ( createApiAction ) . to . have . been . called . once ( ) ;
133+ expect ( createApiAction ) . to . have . been . called . once ;
132134 expect ( createApiAction ) . to . have . been . called . with ( {
133135 type : actionTypes . ADD ,
134136 method : 'POST' ,
@@ -141,9 +143,6 @@ describe('Resource manager', () => {
141143 it ( 'must generate random temporary ID' , ( ) => {
142144 const { addResource } = actionCreators ;
143145 addResource ( { foo : 'bar' } ) ;
144- const tmpId = createApiAction . __spy . calls [ 0 ] [ 0 ] . meta . tmpId ; // first argument of first call of the spy
145- expect ( tmpId ) . to . be . a ( 'string' ) ;
146- expect ( tmpId . length ) . to . be . at . least ( 5 ) ; // 5 was chosen quite arbitrarily, but should be good-enough meassure for this purpose
147146 } ) ;
148147 } ) ;
149148
@@ -157,7 +156,7 @@ describe('Resource manager', () => {
157156 const body = { foo : 'bar' , abc : 'xyz' } ;
158157 const id = 'some-id' ;
159158 updateResource ( id , body ) ;
160- expect ( createApiAction ) . to . have . been . called . once ( ) ;
159+ expect ( createApiAction ) . to . have . been . called . once ;
161160 expect ( createApiAction ) . to . have . been . called . with ( {
162161 type : actionTypes . UPDATE ,
163162 method : 'POST' ,
@@ -177,7 +176,7 @@ describe('Resource manager', () => {
177176
178177 const id = 'some-id' ;
179178 removeResource ( id ) ;
180- expect ( createApiAction ) . to . have . been . called . once ( ) ;
179+ expect ( createApiAction ) . to . have . been . called . once ;
181180 expect ( createApiAction ) . to . have . been . called . with ( {
182181 type : actionTypes . REMOVE ,
183182 method : 'DELETE' ,
0 commit comments