]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: add test case edison/fix/12631 12632/head
authordaiwei <daiwei521@126.com>
Tue, 31 Dec 2024 08:20:18 +0000 (16:20 +0800)
committerdaiwei <daiwei521@126.com>
Tue, 31 Dec 2024 08:20:18 +0000 (16:20 +0800)
packages/runtime-core/__tests__/apiWatch.spec.ts

index 7d2a1e73c0830e3c3bc63aedc0bc44654d92b081..40b45922375271f0114708dcefd8ea41b367144c 100644 (file)
@@ -6,6 +6,7 @@ import {
   getCurrentInstance,
   nextTick,
   onErrorCaptured,
+  onScopeDispose,
   onWatcherCleanup,
   reactive,
   ref,
@@ -1362,6 +1363,32 @@ describe('api: watch', () => {
     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()', () => {
     const source = vi.fn()