@@ -19,6 +19,15 @@ function counterWithBug(state = 0, action) {
1919 }
2020}
2121
22+ function counterWithAnotherBug ( state = 0 , action ) {
23+ switch ( action . type ) {
24+ case 'INCREMENT' : return mistake + 1 ; // eslint-disable-line no-undef
25+ case 'DECREMENT' : return state - 1 ;
26+ case 'SET_UNDEFINED' : return undefined ;
27+ default : return state ;
28+ }
29+ }
30+
2231function doubleCounter ( state = 0 , action ) {
2332 switch ( action . type ) {
2433 case 'INCREMENT' : return state + 2 ;
@@ -334,6 +343,45 @@ describe('instrument', () => {
334343 configuredStore . dispatch ( { type : 'INCREMENT' } ) ;
335344 expect ( configuredLiftedStore . getState ( ) . skippedActionIds ) . toExclude ( 1 ) ;
336345 } ) ;
346+
347+ it ( 'should not auto-commit errors' , ( ) => {
348+ let spy = spyOn ( console , 'error' ) ;
349+
350+ let storeWithBug = createStore ( counterWithBug , instrument ( undefined , { maxAge : 3 } ) ) ;
351+ let liftedStoreWithBug = storeWithBug . liftedStore ;
352+ storeWithBug . dispatch ( { type : 'DECREMENT' } ) ;
353+ storeWithBug . dispatch ( { type : 'INCREMENT' } ) ;
354+ expect ( liftedStoreWithBug . getState ( ) . stagedActionIds . length ) . toBe ( 3 ) ;
355+
356+ storeWithBug . dispatch ( { type : 'INCREMENT' } ) ;
357+ expect ( liftedStoreWithBug . getState ( ) . stagedActionIds . length ) . toBe ( 4 ) ;
358+
359+ spy . restore ( ) ;
360+ } ) ;
361+
362+ it ( 'should auto-commit after hot reload' , ( ) => {
363+ let spy = spyOn ( console , 'error' ) ;
364+
365+ let storeWithBug = createStore ( counterWithBug , instrument ( undefined , { maxAge : 3 } ) ) ;
366+ let liftedStoreWithBug = storeWithBug . liftedStore ;
367+ storeWithBug . dispatch ( { type : 'DECREMENT' } ) ;
368+ storeWithBug . dispatch ( { type : 'DECREMENT' } ) ;
369+ storeWithBug . dispatch ( { type : 'INCREMENT' } ) ;
370+ storeWithBug . dispatch ( { type : 'DECREMENT' } ) ;
371+ storeWithBug . dispatch ( { type : 'DECREMENT' } ) ;
372+ storeWithBug . dispatch ( { type : 'DECREMENT' } ) ;
373+ expect ( liftedStoreWithBug . getState ( ) . stagedActionIds . length ) . toBe ( 7 ) ;
374+
375+ // should auto-commit only 2 non-error actions
376+ storeWithBug . replaceReducer ( counterWithAnotherBug ) ;
377+ expect ( liftedStoreWithBug . getState ( ) . stagedActionIds . length ) . toBe ( 5 ) ;
378+
379+ // should auto-commit down to 3 actions
380+ storeWithBug . replaceReducer ( counter ) ;
381+ expect ( liftedStoreWithBug . getState ( ) . stagedActionIds . length ) . toBe ( 3 ) ;
382+
383+ spy . restore ( ) ;
384+ } ) ;
337385 } ) ;
338386
339387 describe ( 'Import State' , ( ) => {
0 commit comments