Skip to content

Commit 1b63186

Browse files
authored
test(effectScope): add test case for effectScope (#784)
Co-authored-by: webfansplz <>
1 parent e68df99 commit 1b63186

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/apis/effectScope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function onScopeDispose(fn: () => void) {
102102
activeEffectScope.cleanups.push(fn)
103103
} else if (__DEV__) {
104104
warn(
105-
`onDispose() is called when there is no active effect scope ` +
105+
`onDispose() is called when there is no active effect scope` +
106106
` to be associated with.`
107107
)
108108
}

test/v3/reactivity/effectScope.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,25 @@ describe('reactivity/effect/scope', () => {
209209
expect(dummy).toBe(7)
210210
})
211211

212+
it('should warn onDispose() is called when there is no active effect scope', () => {
213+
const spy = jest.fn()
214+
const scope = new EffectScope()
215+
scope.run(() => {
216+
onScopeDispose(spy)
217+
})
218+
219+
expect(spy).toHaveBeenCalledTimes(0)
220+
221+
onScopeDispose(spy)
222+
223+
expect(
224+
'[Vue warn]: onDispose() is called when there is no active effect scope to be associated with.'
225+
).toHaveBeenWarned()
226+
227+
scope.stop()
228+
expect(spy).toHaveBeenCalledTimes(1)
229+
})
230+
212231
it('test with higher level APIs', async () => {
213232
const r = ref(1)
214233

0 commit comments

Comments
 (0)