File tree Expand file tree Collapse file tree 2 files changed +40
-41
lines changed
packages/reactivity/__tests__ Expand file tree Collapse file tree 2 files changed +40
-41
lines changed Original file line number Diff line number Diff line change @@ -322,4 +322,44 @@ describe('reactivity/effect/scope', () => {
322
322
scope . resume ( )
323
323
expect ( fnSpy ) . toHaveBeenCalledTimes ( 3 )
324
324
} )
325
+
326
+ test ( 'clean up watchers during effect scope stop' , async ( ) => {
327
+ const count = ref ( 0 )
328
+ const scope = effectScope ( )
329
+ let watcherCalls = 0
330
+ let cleanupCalls = 0
331
+
332
+ scope . run ( ( ) => {
333
+ const stop1 = watch ( count , ( ) => {
334
+ watcherCalls ++
335
+ } )
336
+ watch ( count , ( val , old , onCleanup ) => {
337
+ watcherCalls ++
338
+ onCleanup ( ( ) => {
339
+ cleanupCalls ++
340
+ stop1 ( )
341
+ } )
342
+ } )
343
+ watch ( count , ( ) => {
344
+ watcherCalls ++
345
+ } )
346
+ } )
347
+
348
+ expect ( watcherCalls ) . toBe ( 0 )
349
+ expect ( cleanupCalls ) . toBe ( 0 )
350
+
351
+ count . value ++
352
+ await nextTick ( )
353
+ expect ( watcherCalls ) . toBe ( 3 )
354
+ expect ( cleanupCalls ) . toBe ( 0 )
355
+
356
+ scope . stop ( )
357
+ count . value ++
358
+ await nextTick ( )
359
+ expect ( watcherCalls ) . toBe ( 3 )
360
+ expect ( cleanupCalls ) . toBe ( 1 )
361
+
362
+ expect ( scope . effects . length ) . toBe ( 0 )
363
+ expect ( scope . cleanups . length ) . toBe ( 0 )
364
+ } )
325
365
} )
Original file line number Diff line number Diff line change 5
5
type WatchOptions ,
6
6
type WatchScheduler ,
7
7
computed ,
8
- effectScope ,
9
8
onWatcherCleanup ,
10
9
ref ,
11
10
watch ,
@@ -278,44 +277,4 @@ describe('watch', () => {
278
277
279
278
expect ( dummy ) . toEqual ( [ 1 , 2 , 3 ] )
280
279
} )
281
-
282
- test ( 'clean up watchers during effect scope stop' , async ( ) => {
283
- const count = ref ( 0 )
284
- const scope = effectScope ( )
285
- let watcherCalls = 0
286
- let cleanupCalls = 0
287
-
288
- scope . run ( ( ) => {
289
- const stop1 = watch ( count , ( ) => {
290
- watcherCalls ++
291
- } )
292
- watch ( count , ( val , old , onCleanup ) => {
293
- watcherCalls ++
294
- onCleanup ( ( ) => {
295
- cleanupCalls ++
296
- stop1 ( )
297
- } )
298
- } )
299
- watch ( count , ( ) => {
300
- watcherCalls ++
301
- } )
302
- } )
303
-
304
- expect ( watcherCalls ) . toBe ( 0 )
305
- expect ( cleanupCalls ) . toBe ( 0 )
306
-
307
- count . value ++
308
- await nextTick ( )
309
- expect ( watcherCalls ) . toBe ( 3 )
310
- expect ( cleanupCalls ) . toBe ( 0 )
311
-
312
- scope . stop ( )
313
- count . value ++
314
- await nextTick ( )
315
- expect ( watcherCalls ) . toBe ( 3 )
316
- expect ( cleanupCalls ) . toBe ( 1 )
317
-
318
- expect ( scope . effects . length ) . toBe ( 0 )
319
- expect ( scope . cleanups . length ) . toBe ( 0 )
320
- } )
321
280
} )
You can’t perform that action at this time.
0 commit comments