fix(watch): traverse refs in deep watch (#1939)

ref #1900
This commit is contained in:
Yang Mingshan
2020-08-24 02:41:11 +08:00
committed by GitHub
parent 31b99a9139
commit 10293c7a18
2 changed files with 22 additions and 1 deletions

View File

@@ -574,6 +574,25 @@ describe('api: watch', () => {
expect(dummy).toEqual([1, 2, 2, false])
})
it('watching deep ref', async () => {
const count = ref(0)
const double = computed(() => count.value * 2)
const state = reactive([count, double])
let dummy
watch(
() => state,
state => {
dummy = [state[0].value, state[1].value]
},
{ deep: true }
)
count.value++
await nextTick()
expect(dummy).toEqual([1, 2])
})
it('immediate', async () => {
const count = ref(0)
const cb = jest.fn()