Skip to content

Commit 1d988b5

Browse files
authored
test(reactivity): test case for #6358 (#6376)
1 parent 313e4bf commit 1d988b5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

packages/reactivity/__tests__/ref.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,32 @@ describe('reactivity/ref', () => {
4343
expect(fn).toHaveBeenCalledTimes(2)
4444
})
4545

46+
it('ref wrapped in reactive should not track internal _value access', () => {
47+
const a = ref(1)
48+
const b = reactive(a)
49+
let calls = 0
50+
let dummy
51+
52+
effect(() => {
53+
calls++
54+
dummy = b.value // this will observe both b.value and a.value access
55+
})
56+
expect(calls).toBe(1)
57+
expect(dummy).toBe(1)
58+
59+
// mutating a.value should only trigger effect once
60+
calls = 0
61+
a.value = 3
62+
expect(calls).toBe(1)
63+
expect(dummy).toBe(3)
64+
65+
// mutating b.value should trigger the effect twice. (once for a.value change and once for b.value change)
66+
calls = 0
67+
b.value = 5
68+
expect(calls).toBe(2)
69+
expect(dummy).toBe(5)
70+
})
71+
4672
it('should make nested properties reactive', () => {
4773
const a = ref({
4874
count: 1,

0 commit comments

Comments
 (0)