Skip to content

Commit 1741978

Browse files
test(apiWatch): add array test
1 parent 6e50040 commit 1741978

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

packages/runtime-core/__tests__/apiWatch.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,4 +1272,41 @@ describe('api: watch', () => {
12721272
await nextTick()
12731273
expect(cb).toHaveBeenCalledTimes(2)
12741274
})
1275+
1276+
it('observation array depth', async () => {
1277+
const arr = ref([
1278+
{
1279+
a: {
1280+
b: 2
1281+
}
1282+
},
1283+
{
1284+
a: {
1285+
b: 3
1286+
}
1287+
}
1288+
])
1289+
const cb = vi.fn()
1290+
watch(arr, cb, { deep: true, depth: 2 })
1291+
1292+
arr.value[0].a.b = 3
1293+
await nextTick()
1294+
expect(cb).toHaveBeenCalledTimes(0)
1295+
1296+
arr.value[0].a = { b: 3 }
1297+
await nextTick()
1298+
expect(cb).toHaveBeenCalledTimes(1)
1299+
1300+
arr.value[1].a = { b: 4 }
1301+
await nextTick()
1302+
expect(cb).toHaveBeenCalledTimes(2)
1303+
1304+
arr.value.push({ a: { b: 5 } })
1305+
await nextTick()
1306+
expect(cb).toHaveBeenCalledTimes(3)
1307+
1308+
arr.value.pop()
1309+
await nextTick()
1310+
expect(cb).toHaveBeenCalledTimes(4)
1311+
})
12751312
})

0 commit comments

Comments
 (0)