Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add failing test cases for #12681 #12693

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/reactivity/__tests__/watch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type WatchOptions,
type WatchScheduler,
computed,
onScopeDispose,
onWatcherCleanup,
ref,
watch,
Expand Down Expand Up @@ -277,4 +278,24 @@ describe('watch', () => {

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)
})
})
20 changes: 20 additions & 0 deletions packages/runtime-core/__tests__/apiWatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2010,4 +2010,24 @@
createApp(App).mount(root)
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)

Check failure on line 2030 in packages/runtime-core/__tests__/apiWatch.spec.ts

View workflow job for this annotation

GitHub Actions / test / unit-test

packages/runtime-core/__tests__/apiWatch.spec.ts > api: watch > onScopeDispose inside non-immediate watcher that ran

AssertionError: expected "spy" to be called 1 times, but got 0 times ❯ packages/runtime-core/__tests__/apiWatch.spec.ts:2030:19
expect(cleanupSpy).toBeCalledTimes(1)
})
})
Loading