mirror of https://github.com/vuejs/core.git
test: add failing test cases for onScopeDispose inside watchers
This commit is contained in:
parent
22dcbf3e20
commit
bf329cb35c
|
@ -5,6 +5,7 @@ import {
|
||||||
type WatchOptions,
|
type WatchOptions,
|
||||||
type WatchScheduler,
|
type WatchScheduler,
|
||||||
computed,
|
computed,
|
||||||
|
onScopeDispose,
|
||||||
onWatcherCleanup,
|
onWatcherCleanup,
|
||||||
ref,
|
ref,
|
||||||
watch,
|
watch,
|
||||||
|
@ -277,4 +278,24 @@ describe('watch', () => {
|
||||||
|
|
||||||
expect(dummy).toEqual([1, 2, 3])
|
expect(dummy).toEqual([1, 2, 3])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #12681
|
||||||
|
test('onScopeDispose inside non-immediate watcher', () => {
|
||||||
|
const cleanupSpy = vi.fn()
|
||||||
|
const cbSpy = vi.fn(() => {
|
||||||
|
onScopeDispose(cleanupSpy)
|
||||||
|
})
|
||||||
|
const scope = new EffectScope()
|
||||||
|
|
||||||
|
scope.run(() => {
|
||||||
|
const signal = ref(false)
|
||||||
|
watch(signal, cbSpy)
|
||||||
|
signal.value = true
|
||||||
|
})
|
||||||
|
|
||||||
|
scope.stop()
|
||||||
|
|
||||||
|
expect(cbSpy).toBeCalledTimes(1)
|
||||||
|
expect(cleanupSpy).toBeCalledTimes(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -2010,4 +2010,24 @@ describe('api: watch', () => {
|
||||||
createApp(App).mount(root)
|
createApp(App).mount(root)
|
||||||
expect(onCleanup).toBeCalledTimes(0)
|
expect(onCleanup).toBeCalledTimes(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #12681
|
||||||
|
test('onScopeDispose inside non-immediate watcher that ran', () => {
|
||||||
|
const cleanupSpy = vi.fn()
|
||||||
|
const cbSpy = vi.fn(() => {
|
||||||
|
onScopeDispose(cleanupSpy)
|
||||||
|
})
|
||||||
|
const scope = effectScope()
|
||||||
|
|
||||||
|
scope.run(() => {
|
||||||
|
const signal = ref(false)
|
||||||
|
watch(signal, cbSpy)
|
||||||
|
signal.value = true
|
||||||
|
})
|
||||||
|
|
||||||
|
scope.stop()
|
||||||
|
|
||||||
|
expect(cbSpy).toBeCalledTimes(1)
|
||||||
|
expect(cleanupSpy).toBeCalledTimes(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue