From ad22879dd258b6af5a80e4a0cc6f80fafb85463d Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Fri, 28 Jun 2024 09:45:34 +0800 Subject: [PATCH] test(reactivity): add a failed test for computed (#11243) to avoid regressions like in #11135 --- packages/reactivity/__tests__/computed.spec.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/reactivity/__tests__/computed.spec.ts b/packages/reactivity/__tests__/computed.spec.ts index 10c09109fdb..20faa18a323 100644 --- a/packages/reactivity/__tests__/computed.spec.ts +++ b/packages/reactivity/__tests__/computed.spec.ts @@ -619,6 +619,22 @@ describe('reactivity/computed', () => { expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned() }) + it('should be recomputed 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') + expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned() + }) + it('debug: onTrigger (ref)', () => { let events: DebuggerEvent[] = [] const onTrigger = vi.fn((e: DebuggerEvent) => {