test: add test case

This commit is contained in:
daiwei 2024-12-31 16:20:18 +08:00
parent ffbe87e7a3
commit acb325c13c
1 changed files with 27 additions and 0 deletions

View 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()