From: lidlanca <8693091+lidlanca@users.noreply.github.com> Date: Thu, 29 Aug 2024 06:20:04 +0000 (-0400) Subject: test(reactivity): test case for #6358 (#6376) X-Git-Tag: v3.5.0-rc.1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d988b5b99a4be6ac45ff6e0338b38cad1747a85;p=thirdparty%2Fvuejs%2Fcore.git test(reactivity): test case for #6358 (#6376) --- diff --git a/packages/reactivity/__tests__/ref.spec.ts b/packages/reactivity/__tests__/ref.spec.ts index 0158ca0f64..56863471ad 100644 --- a/packages/reactivity/__tests__/ref.spec.ts +++ b/packages/reactivity/__tests__/ref.spec.ts @@ -43,6 +43,32 @@ describe('reactivity/ref', () => { expect(fn).toHaveBeenCalledTimes(2) }) + it('ref wrapped in reactive should not track internal _value access', () => { + const a = ref(1) + const b = reactive(a) + let calls = 0 + let dummy + + effect(() => { + calls++ + dummy = b.value // this will observe both b.value and a.value access + }) + expect(calls).toBe(1) + expect(dummy).toBe(1) + + // mutating a.value should only trigger effect once + calls = 0 + a.value = 3 + expect(calls).toBe(1) + expect(dummy).toBe(3) + + // mutating b.value should trigger the effect twice. (once for a.value change and once for b.value change) + calls = 0 + b.value = 5 + expect(calls).toBe(2) + expect(dummy).toBe(5) + }) + it('should make nested properties reactive', () => { const a = ref({ count: 1,