@@ -29,6 +29,9 @@ describe('Reactor', () => {
29
29
} ,
30
30
31
31
initialize ( ) {
32
+ this . on ( 'storeError' , ( state , payload ) => {
33
+ throw new Error ( 'Store Error' )
34
+ } )
32
35
this . on ( 'addItem' , ( state , payload ) => {
33
36
return state . update ( 'all' , items => {
34
37
return items . push ( Map ( {
@@ -198,6 +201,36 @@ describe('Reactor', () => {
198
201
expect ( ( ) => checkoutActions . setTaxPercent ( 5 ) ) . not . toThrow (
199
202
new Error ( 'Dispatch may not be called while a dispatch is in progress' ) )
200
203
} )
204
+
205
+ it ( 'should allow subsequent dispatches if a store throws an error' , ( ) => {
206
+ try {
207
+ reactor . dispatch ( 'storeError' )
208
+ } catch ( e ) { } // eslint-disable-line
209
+
210
+ expect ( ( ) => reactor . dispatch ( 'setTax' , 5 ) ) . not . toThrow ( )
211
+ } )
212
+
213
+ it ( 'should allow subsequent dispatches if a dispatched action doesnt cause state change' , ( ) => {
214
+ reactor . dispatch ( 'noop' )
215
+
216
+ expect ( ( ) => reactor . dispatch ( 'setTax' , 5 ) ) . not . toThrow ( )
217
+ } )
218
+
219
+ it ( 'should allow subsequent dispatches if an observer throws an error' , ( ) => {
220
+ var unWatchFn = reactor . observe ( [ ] , state => {
221
+ throw new Error ( 'observer error' )
222
+ } )
223
+
224
+ try {
225
+ checkoutActions . setTaxPercent ( 1 )
226
+ } catch ( e ) { } // eslint-disable-line
227
+
228
+ unWatchFn ( )
229
+
230
+ expect ( ( ) => {
231
+ checkoutActions . setTaxPercent ( 2 )
232
+ } ) . not . toThrow ( )
233
+ } )
201
234
} ) // when dispatching a relevant action
202
235
203
236
describe ( '#observe' , ( ) => {
@@ -500,8 +533,8 @@ describe('Reactor', () => {
500
533
it ( 'should log and throw an error' , function ( ) {
501
534
expect ( function ( ) {
502
535
reactor . dispatch ( 'set' , 'foo' )
503
- } ) . toThrow ( )
504
- expect ( logging . dispatchError ) . toHaveBeenCalled ( )
536
+ } ) . toThrow ( new Error ( 'Error during action handling' ) )
537
+ expect ( logging . dispatchError ) . toHaveBeenCalledWith ( 'Error during action handling' )
505
538
} )
506
539
} )
507
540
@@ -976,6 +1009,9 @@ describe('Reactor', () => {
976
1009
} ,
977
1010
initialize ( ) {
978
1011
this . on ( 'add' , ( state , item ) => state . push ( toImmutable ( item ) ) )
1012
+ this . on ( 'error' , ( state , payload ) => {
1013
+ throw new Error ( 'store error' ) ;
1014
+ } )
979
1015
} ,
980
1016
} ) ,
981
1017
} )
@@ -1066,5 +1102,46 @@ describe('Reactor', () => {
1066
1102
} ) . not . toThrow (
1067
1103
new Error ( 'Dispatch may not be called while a dispatch is in progress' ) )
1068
1104
} )
1105
+
1106
+ it ( 'should allow subsequent dispatches if an error is raised by a store handler' , ( ) => {
1107
+ expect ( ( ) => {
1108
+ reactor . batch ( ( ) => {
1109
+ reactor . dispatch ( 'add' , 'one' )
1110
+ reactor . dispatch ( 'error' )
1111
+ } )
1112
+ } ) . toThrow ( new Error ( 'store error' ) )
1113
+
1114
+ expect ( ( ) => {
1115
+ reactor . dispatch ( 'add' , 'three' )
1116
+ } ) . not . toThrow ( )
1117
+ } )
1118
+
1119
+ it ( 'should allow subsequent dispatches if batched action doesnt cause state change' , ( ) => {
1120
+ reactor . batch ( ( ) => {
1121
+ reactor . dispatch ( 'noop' )
1122
+ } )
1123
+
1124
+ expect ( ( ) => reactor . dispatch ( 'add' , 'one' ) ) . not . toThrow ( )
1125
+ } )
1126
+
1127
+ it ( 'should allow subsequent dispatches if an error is raised in an observer' , ( ) => {
1128
+ var unWatchFn = reactor . observe ( [ ] , state => {
1129
+ throw new Error ( 'observe error' )
1130
+ } )
1131
+
1132
+ expect ( ( ) => {
1133
+ reactor . batch ( ( ) => {
1134
+ reactor . dispatch ( 'add' , 'one' )
1135
+ reactor . dispatch ( 'add' , 'two' )
1136
+ } )
1137
+ } ) . toThrow (
1138
+ new Error ( 'observe error' ) )
1139
+
1140
+ unWatchFn ( )
1141
+
1142
+ expect ( ( ) => {
1143
+ reactor . dispatch ( 'add' , 'three' )
1144
+ } ) . not . toThrow ( )
1145
+ } )
1069
1146
} )
1070
1147
} )
0 commit comments