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 5
5
defineComponent ,
6
6
getCurrentInstance ,
7
7
nextTick ,
8
+ onEffectCleanup ,
8
9
reactive ,
9
10
ref ,
10
11
watch ,
@@ -320,6 +321,35 @@ describe('api: watch', () => {
320
321
expect ( cleanup ) . toHaveBeenCalledTimes ( 2 )
321
322
} )
322
323
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
+
323
353
it ( 'flush timing: pre (default)' , async ( ) => {
324
354
const count = ref ( 0 )
325
355
const count2 = ref ( 0 )
You can’t perform that action at this time.
0 commit comments