File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
packages/runtime-core/__tests__ Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 55 defineComponent ,
66 getCurrentInstance ,
77 nextTick ,
8+ onEffectCleanup ,
89 reactive ,
910 ref ,
1011 watch ,
@@ -320,6 +321,35 @@ describe('api: watch', () => {
320321 expect ( cleanup ) . toHaveBeenCalledTimes ( 2 )
321322 } )
322323
324+ it ( 'onEffectCleanup' , async ( ) => {
325+ const count = ref ( 0 )
326+ const cleanupEffect = vi . fn ( )
327+ const cleanupWatch = vi . fn ( )
328+
329+ const stopEffect = watchEffect ( ( ) => {
330+ onEffectCleanup ( cleanupEffect )
331+ count . value
332+ } )
333+ const stopWatch = watch ( count , ( ) => {
334+ onEffectCleanup ( cleanupWatch )
335+ } )
336+
337+ count . value ++
338+ await nextTick ( )
339+ expect ( cleanupEffect ) . toHaveBeenCalledTimes ( 1 )
340+ expect ( cleanupWatch ) . toHaveBeenCalledTimes ( 0 )
341+
342+ count . value ++
343+ await nextTick ( )
344+ expect ( cleanupEffect ) . toHaveBeenCalledTimes ( 2 )
345+ expect ( cleanupWatch ) . toHaveBeenCalledTimes ( 1 )
346+
347+ stopEffect ( )
348+ expect ( cleanupEffect ) . toHaveBeenCalledTimes ( 3 )
349+ stopWatch ( )
350+ expect ( cleanupWatch ) . toHaveBeenCalledTimes ( 2 )
351+ } )
352+
323353 it ( 'flush timing: pre (default)' , async ( ) => {
324354 const count = ref ( 0 )
325355 const count2 = ref ( 0 )
You can’t perform that action at this time.
0 commit comments