Skip to content

Commit 3170eff

Browse files
committed
test: add test for vuejs#6018
1 parent 3a3b46d commit 3170eff

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/reactivity/__tests__/reactiveArray.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,25 @@ describe('reactivity/reactive/Array', () => {
113113
expect(fn).toHaveBeenCalledTimes(2)
114114
})
115115

116+
//#6018
117+
test('edge case: avoid trigger effect in deleteProperty when array length-decrease mutation methods called', () => {
118+
const arr = ref([1])
119+
const fn1 = vi.fn()
120+
const fn2 = vi.fn()
121+
effect(() => {
122+
fn1()
123+
if (arr.value.length > 0) {
124+
arr.value.slice()
125+
fn2()
126+
}
127+
})
128+
expect(fn1).toHaveBeenCalledTimes(1)
129+
expect(fn2).toHaveBeenCalledTimes(1)
130+
arr.value.splice(0)
131+
expect(fn1).toHaveBeenCalledTimes(2)
132+
expect(fn2).toHaveBeenCalledTimes(1)
133+
})
134+
116135
test('add existing index on Array should not trigger length dependency', () => {
117136
const array = new Array(3)
118137
const observed = reactive(array)

0 commit comments

Comments
 (0)