fix(reactivity): computed should not trigger scheduler if stopped

fix #4149
This commit is contained in:
Evan You
2021-07-19 13:37:03 -04:00
parent dd0f9d1ce6
commit 6eb47f000a
2 changed files with 21 additions and 1 deletions

View File

@@ -466,5 +466,25 @@ describe('reactivity/computed', () => {
await tick
expect(effectSpy).toHaveBeenCalledTimes(2)
})
test('should not compute if deactivated before scheduler is called', async () => {
const c1Spy = jest.fn()
const src = ref(0)
const c1 = computed(() => {
c1Spy()
return src.value % 2
})
effect(() => c1.value)
expect(c1Spy).toHaveBeenCalledTimes(1)
// schedule stop
schedule(() => {
c1.effect.stop()
})
// trigger
src.value++
await tick
expect(c1Spy).toHaveBeenCalledTimes(1)
})
})
})