]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(reactivity): add a failed test for computed (#11243)
authorJohnson Chu <johnsoncodehk@gmail.com>
Fri, 28 Jun 2024 01:45:34 +0000 (09:45 +0800)
committerGitHub <noreply@github.com>
Fri, 28 Jun 2024 01:45:34 +0000 (09:45 +0800)
to avoid regressions like in #11135

packages/reactivity/__tests__/computed.spec.ts

index 10c09109fdbd8153efc2e6f1f9ad8fa417965d57..20faa18a323e4903c1b7ef638f8b03d770971fc2 100644 (file)
@@ -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) => {