From 998c400cad7dcbe44dabc2b223ab99c0557f5106 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Thu, 6 Apr 2023 16:26:39 +0800 Subject: [PATCH] chore: add test for effect() on-demand trigger --- .../reactivity/__tests__/computed.spec.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/reactivity/__tests__/computed.spec.ts b/packages/reactivity/__tests__/computed.spec.ts index c18e4367fa1..988bead0cce 100644 --- a/packages/reactivity/__tests__/computed.spec.ts +++ b/packages/reactivity/__tests__/computed.spec.ts @@ -313,6 +313,34 @@ describe('reactivity/computed', () => { expect(hourSpy).toHaveBeenCalledTimes(17) }) + it('effect callback on-demand trigger', () => { + const minSpy = vi.fn() + const hourSpy = vi.fn() + const effectSpy = vi.fn() + + const sec = ref(0) + const min = computed(() => { + minSpy() + return Math.floor(sec.value / 60) + }) + const hour = computed(() => { + hourSpy() + return Math.floor(min.value / 60) + }) + + effect(() => { + effectSpy() + min.value + hour.value + }) + + for (sec.value = 0; sec.value < 1000; sec.value++) {} + + expect(minSpy).toHaveBeenCalledTimes(1001) + expect(hourSpy).toHaveBeenCalledTimes(17) + expect(effectSpy).toHaveBeenCalledTimes(1001) + }) + it('chained computed value urgent assessment edge case', () => { const cSpy = vi.fn()