]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(reactivity): add test case for effectScope (#4239)
authorwebfansplz <308241863@qq.com>
Tue, 10 Aug 2021 17:59:58 +0000 (01:59 +0800)
committerGitHub <noreply@github.com>
Tue, 10 Aug 2021 17:59:58 +0000 (13:59 -0400)
packages/reactivity/__tests__/effectScope.spec.ts
packages/reactivity/src/effectScope.ts

index a9e4ab0c79ff3b325bac30018b7919c4ed518503..6028882772f1bfb93b468990d1bd6653d9a96115 100644 (file)
@@ -192,6 +192,25 @@ describe('reactivity/effect/scope', () => {
     expect(dummy).toBe(7)
   })
 
+  it('should warn onDispose() is called when there is no active effect scope', () => {
+    const spy = jest.fn()
+    const scope = new EffectScope()
+    scope.run(() => {
+      onScopeDispose(spy)
+    })
+
+    expect(spy).toHaveBeenCalledTimes(0)
+
+    onScopeDispose(spy)
+
+    expect(
+      '[Vue warn] onDispose() is called when there is no active effect scope to be associated with.'
+    ).toHaveBeenWarned()
+
+    scope.stop()
+    expect(spy).toHaveBeenCalledTimes(1)
+  })
+
   it('should derefence child scope from parent scope after stopping child scope (no memleaks)', async () => {
     const parent = new EffectScope()
     const child = parent.run(() => new EffectScope())!
index db1ebdea518ae125bac52411d44d119962ef779f..05a700be43e57ddf004bcade6596ec1497bdb63c 100644 (file)
@@ -98,7 +98,7 @@ export function onScopeDispose(fn: () => void) {
     activeEffectScope.cleanups.push(fn)
   } else if (__DEV__) {
     warn(
-      `onDispose() is called when there is no active effect scope ` +
+      `onDispose() is called when there is no active effect scope` +
         ` to be associated with.`
     )
   }