Skip to content

Commit

Permalink
test: add test for vuejs#6018
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Sep 27, 2023
1 parent 3a3b46d commit 3170eff
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/reactivity/__tests__/reactiveArray.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@ describe('reactivity/reactive/Array', () => {
expect(fn).toHaveBeenCalledTimes(2)
})

//#6018
test('edge case: avoid trigger effect in deleteProperty when array length-decrease mutation methods called', () => {
const arr = ref([1])
const fn1 = vi.fn()
const fn2 = vi.fn()
effect(() => {
fn1()
if (arr.value.length > 0) {
arr.value.slice()
fn2()
}
})
expect(fn1).toHaveBeenCalledTimes(1)
expect(fn2).toHaveBeenCalledTimes(1)
arr.value.splice(0)
expect(fn1).toHaveBeenCalledTimes(2)
expect(fn2).toHaveBeenCalledTimes(1)
})

test('add existing index on Array should not trigger length dependency', () => {
const array = new Array(3)
const observed = reactive(array)
Expand Down

0 comments on commit 3170eff

Please sign in to comment.