Skip to content

Commit

Permalink
test(apiWatch): add array test
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfred-Skyblue committed Nov 21, 2023
1 parent 6e50040 commit 1741978
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/runtime-core/__tests__/apiWatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1272,4 +1272,41 @@ describe('api: watch', () => {
await nextTick()
expect(cb).toHaveBeenCalledTimes(2)
})

it('observation array depth', async () => {
const arr = ref([
{
a: {
b: 2
}
},
{
a: {
b: 3
}
}
])
const cb = vi.fn()
watch(arr, cb, { deep: true, depth: 2 })

arr.value[0].a.b = 3
await nextTick()
expect(cb).toHaveBeenCalledTimes(0)

arr.value[0].a = { b: 3 }
await nextTick()
expect(cb).toHaveBeenCalledTimes(1)

arr.value[1].a = { b: 4 }
await nextTick()
expect(cb).toHaveBeenCalledTimes(2)

arr.value.push({ a: { b: 5 } })
await nextTick()
expect(cb).toHaveBeenCalledTimes(3)

arr.value.pop()
await nextTick()
expect(cb).toHaveBeenCalledTimes(4)
})
})

0 comments on commit 1741978

Please sign in to comment.