@@ -320,6 +320,48 @@ describe('Store', () => {
320
320
expect ( secondSubscribeSpy . calls . count ( ) ) . toBe ( 2 )
321
321
} )
322
322
323
+ it ( 'subscribe: should handle subscriptions with synchronous unsubscriptions' , ( ) => {
324
+ const subscribeSpy = jasmine . createSpy ( )
325
+ const testPayload = 2
326
+ const store = new Vuex . Store ( {
327
+ state : { } ,
328
+ mutations : {
329
+ [ TEST ] : ( ) => { }
330
+ }
331
+ } )
332
+
333
+ const unsubscribe = store . subscribe ( ( ) => unsubscribe ( ) )
334
+ store . subscribe ( subscribeSpy )
335
+ store . commit ( TEST , testPayload )
336
+
337
+ expect ( subscribeSpy ) . toHaveBeenCalledWith (
338
+ { type : TEST , payload : testPayload } ,
339
+ store . state
340
+ )
341
+ expect ( subscribeSpy . calls . count ( ) ) . toBe ( 1 )
342
+ } )
343
+
344
+ it ( 'subscribeAction: should handle subscriptions with synchronous unsubscriptions' , ( ) => {
345
+ const subscribeSpy = jasmine . createSpy ( )
346
+ const testPayload = 2
347
+ const store = new Vuex . Store ( {
348
+ state : { } ,
349
+ actions : {
350
+ [ TEST ] : ( ) => { }
351
+ }
352
+ } )
353
+
354
+ const unsubscribe = store . subscribeAction ( ( ) => unsubscribe ( ) )
355
+ store . subscribeAction ( subscribeSpy )
356
+ store . dispatch ( TEST , testPayload )
357
+
358
+ expect ( subscribeSpy ) . toHaveBeenCalledWith (
359
+ { type : TEST , payload : testPayload } ,
360
+ store . state
361
+ )
362
+ expect ( subscribeSpy . calls . count ( ) ) . toBe ( 1 )
363
+ } )
364
+
323
365
// store.watch should only be asserted in non-SSR environment
324
366
if ( ! isSSR ) {
325
367
it ( 'strict mode: warn mutations outside of handlers' , ( ) => {
0 commit comments