Skip to content
/ core Public
  • Sponsor vuejs/core

  • Notifications You must be signed in to change notification settings
  • Fork 8.6k
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
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
test: add failing test cases for onScopeDispose inside watchers
ferferga authored Jan 11, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit bf329cb35c0e9daab60cf22de9c73807794c7f37
21 changes: 21 additions & 0 deletions packages/reactivity/__tests__/watch.spec.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import {
type WatchOptions,
type WatchScheduler,
computed,
onScopeDispose,
onWatcherCleanup,
ref,
watch,
@@ -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
@@ -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

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)
})
})