From acb325c13cd393472e0d2561ce220953e5af939d Mon Sep 17 00:00:00 2001 From: daiwei Date: Tue, 31 Dec 2024 16:20:18 +0800 Subject: [PATCH] test: add test case --- .../runtime-core/__tests__/apiWatch.spec.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/runtime-core/__tests__/apiWatch.spec.ts b/packages/runtime-core/__tests__/apiWatch.spec.ts index 7d2a1e73c0..40b4592237 100644 --- a/packages/runtime-core/__tests__/apiWatch.spec.ts +++ b/packages/runtime-core/__tests__/apiWatch.spec.ts @@ -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() -- 2.47.2