Bläddra i källkod

test: add test case

daiwei 1 år sedan
förälder
incheckning
acb325c13c
1 ändrade filer med 27 tillägg och 0 borttagningar
  1. 27 0
      packages/runtime-core/__tests__/apiWatch.spec.ts

+ 27 - 0
packages/runtime-core/__tests__/apiWatch.spec.ts

@@ -6,6 +6,7 @@ import {
   getCurrentInstance,
   getCurrentInstance,
   nextTick,
   nextTick,
   onErrorCaptured,
   onErrorCaptured,
+  onScopeDispose,
   onWatcherCleanup,
   onWatcherCleanup,
   reactive,
   reactive,
   ref,
   ref,
@@ -1362,6 +1363,32 @@ describe('api: watch', () => {
     expect(source.mock.calls.some(args => args.includes(instance)))
     expect(source.mock.calls.some(args => args.includes(instance)))
   })
   })
 
 
+  test('this.$watch w/ onScopeDispose', () => {
+    const onCleanup = vi.fn()
+    const toggle = ref(true)
+
+    const Comp = defineComponent({
+      render() {},
+      created(this: any) {
+        this.$watch(
+          () => 1,
+          function () {},
+        )
+        onScopeDispose(onCleanup)
+      },
+    })
+
+    const App = defineComponent({
+      render() {
+        return toggle.value ? h(Comp) : null
+      },
+    })
+
+    const root = nodeOps.createElement('div')
+    createApp(App).mount(root)
+    expect(onCleanup).toBeCalledTimes(0)
+  })
+
   test('should not leak `this.proxy` to setup()', () => {
   test('should not leak `this.proxy` to setup()', () => {
     const source = vi.fn()
     const source = vi.fn()