Skip to content

Commit e04680b

Browse files
authored
test(reactivity): add test case for effectScope (#4239)
1 parent c46af8f commit e04680b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/reactivity/__tests__/effectScope.spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,25 @@ describe('reactivity/effect/scope', () => {
192192
expect(dummy).toBe(7)
193193
})
194194

195+
it('should warn onDispose() is called when there is no active effect scope', () => {
196+
const spy = jest.fn()
197+
const scope = new EffectScope()
198+
scope.run(() => {
199+
onScopeDispose(spy)
200+
})
201+
202+
expect(spy).toHaveBeenCalledTimes(0)
203+
204+
onScopeDispose(spy)
205+
206+
expect(
207+
'[Vue warn] onDispose() is called when there is no active effect scope to be associated with.'
208+
).toHaveBeenWarned()
209+
210+
scope.stop()
211+
expect(spy).toHaveBeenCalledTimes(1)
212+
})
213+
195214
it('should derefence child scope from parent scope after stopping child scope (no memleaks)', async () => {
196215
const parent = new EffectScope()
197216
const child = parent.run(() => new EffectScope())!

packages/reactivity/src/effectScope.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function onScopeDispose(fn: () => void) {
9898
activeEffectScope.cleanups.push(fn)
9999
} else if (__DEV__) {
100100
warn(
101-
`onDispose() is called when there is no active effect scope ` +
101+
`onDispose() is called when there is no active effect scope` +
102102
` to be associated with.`
103103
)
104104
}

0 commit comments

Comments
 (0)