fix(watch): fix watching reactive array (#1656)

fixes #1655
This commit is contained in:
Tan Li Hau
2020-07-21 00:39:22 +08:00
committed by GitHub
parent d39c03771b
commit 288b4eab9e
2 changed files with 16 additions and 6 deletions

View File

@@ -69,6 +69,16 @@ describe('api: watch', () => {
expect(dummy).toMatchObject([1, 0])
})
it('watching single source: array', async () => {
const array = reactive([] as number[])
const spy = jest.fn()
watch(array, spy)
array.push(1)
await nextTick()
expect(spy).toBeCalledTimes(1)
expect(spy).toBeCalledWith([1], expect.anything(), expect.anything())
})
it('watching single source: computed ref', async () => {
const count = ref(0)
const plus = computed(() => count.value + 1)