Skip to content

Commit

Permalink
test(effectScope): add test case for effectScope (#784)
Browse files Browse the repository at this point in the history
Co-authored-by: webfansplz <>
  • Loading branch information
webfansplz committed Aug 11, 2021
1 parent e68df99 commit 1b63186
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/apis/effectScope.ts
Expand Up @@ -102,7 +102,7 @@ export function onScopeDispose(fn: () => void) {
activeEffectScope.cleanups.push(fn)
} else if (__DEV__) {
warn(
`onDispose() is called when there is no active effect scope ` +
`onDispose() is called when there is no active effect scope` +
` to be associated with.`
)
}
Expand Down
19 changes: 19 additions & 0 deletions test/v3/reactivity/effectScope.spec.ts
Expand Up @@ -209,6 +209,25 @@ describe('reactivity/effect/scope', () => {
expect(dummy).toBe(7)
})

it('should warn onDispose() is called when there is no active effect scope', () => {
const spy = jest.fn()
const scope = new EffectScope()
scope.run(() => {
onScopeDispose(spy)
})

expect(spy).toHaveBeenCalledTimes(0)

onScopeDispose(spy)

expect(
'[Vue warn]: onDispose() is called when there is no active effect scope to be associated with.'
).toHaveBeenWarned()

scope.stop()
expect(spy).toHaveBeenCalledTimes(1)
})

it('test with higher level APIs', async () => {
const r = ref(1)

Expand Down

0 comments on commit 1b63186

Please sign in to comment.