Explorar el Código

test(reactivity): add a failed test for computed (#11243)

to avoid regressions like in #11135
Johnson Chu hace 1 año
padre
commit
ad22879dd2
Se han modificado 1 ficheros con 16 adiciones y 0 borrados
  1. 16 0
      packages/reactivity/__tests__/computed.spec.ts

+ 16 - 0
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) => {