From ee0e829778f4d95d70f99bd3c0a89be2d63ebc74 Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Fri, 28 Jun 2024 05:42:46 +0800 Subject: [PATCH 1/2] test: add a test case --- packages/reactivity/__tests__/computed.spec.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/reactivity/__tests__/computed.spec.ts b/packages/reactivity/__tests__/computed.spec.ts index 9a91eed6389..78c1c7c68bc 100644 --- a/packages/reactivity/__tests__/computed.spec.ts +++ b/packages/reactivity/__tests__/computed.spec.ts @@ -765,6 +765,21 @@ describe('reactivity/computed', () => { expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned() }) + it('should be recompute without being affected by side effects', () => { + const v = ref(0) + const c1 = computed(() => { + v.value = 1 + return 0 + }) + const c2 = computed(() => { + return v.value + ',' + c1.value + }) + + expect(c2.value).toBe('0,0') + v.value = 1 + expect(c2.value).toBe('1,0') + }) + it('debug: onTrigger (ref)', () => { let events: DebuggerEvent[] = [] const onTrigger = vi.fn((e: DebuggerEvent) => { From 0e230f20fea3cba01af640c70fe36ccfc66eeacd Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 28 Jun 2024 09:40:36 +0800 Subject: [PATCH 2/2] Update computed.spec.ts --- packages/reactivity/__tests__/computed.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/reactivity/__tests__/computed.spec.ts b/packages/reactivity/__tests__/computed.spec.ts index 066c29ddc6d..20faa18a323 100644 --- a/packages/reactivity/__tests__/computed.spec.ts +++ b/packages/reactivity/__tests__/computed.spec.ts @@ -619,7 +619,7 @@ describe('reactivity/computed', () => { expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned() }) - it('should be recompute without being affected by side effects', () => { + it('should be recomputed without being affected by side effects', () => { const v = ref(0) const c1 = computed(() => { v.value = 1 @@ -632,6 +632,7 @@ describe('reactivity/computed', () => { expect(c2.value).toBe('0,0') v.value = 1 expect(c2.value).toBe('1,0') + expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned() }) it('debug: onTrigger (ref)', () => {