File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -353,5 +353,27 @@ describe('Subscriptions', () => {
353353 expect ( spy1 ) . toHaveBeenCalledTimes ( 1 )
354354 expect ( spy2 ) . toHaveBeenCalledTimes ( 2 )
355355 } )
356+
357+ // https://github.com/vuejs/pinia/issues/992
358+ it ( 'triggers sync subscription when state is synchronously mutated after patch' , async ( ) => {
359+ const store = useStore ( )
360+ const syncSpy = vi . fn ( )
361+ const preSpy = vi . fn ( )
362+ const postSpy = vi . fn ( )
363+ store . $subscribe ( syncSpy , { flush : 'sync' } )
364+ store . $subscribe ( preSpy , { flush : 'pre' } )
365+ store . $subscribe ( postSpy , { flush : 'post' } )
366+
367+ store . $patch ( { user : 'Edu' } )
368+ store . user = 'a'
369+ expect ( syncSpy ) . toHaveBeenCalledTimes ( 2 )
370+
371+ // FIXME: ideally, these should be 2 but we cannot use
372+ // a sync flush within the store's $subscribe method
373+ // https://github.com/vuejs/pinia/issues/610
374+ await nextTick ( )
375+ expect ( preSpy ) . toHaveBeenCalledTimes ( 1 )
376+ expect ( postSpy ) . toHaveBeenCalledTimes ( 1 )
377+ } )
356378 } )
357379} )
You can’t perform that action at this time.
0 commit comments