feat(watch): support directly watching reactive object in multiple sources with deep default (#1201)
This commit is contained in:
@@ -155,12 +155,30 @@ describe('api: watch', () => {
|
||||
expect(dummy).toMatchObject([[2, true], [1, false]])
|
||||
})
|
||||
|
||||
it('watching multiple sources: reactive object (with automatic deep: true)', async () => {
|
||||
const src = reactive({ count: 0 })
|
||||
let dummy
|
||||
watch([src], ([state]) => {
|
||||
dummy = state
|
||||
// assert types
|
||||
state.count === 1
|
||||
})
|
||||
src.count++
|
||||
await nextTick()
|
||||
expect(dummy).toMatchObject({ count: 1 })
|
||||
})
|
||||
|
||||
it('warn invalid watch source', () => {
|
||||
// @ts-ignore
|
||||
watch(1, () => {})
|
||||
expect(`Invalid watch source`).toHaveBeenWarned()
|
||||
})
|
||||
|
||||
it('warn invalid watch source: multiple sources', () => {
|
||||
watch([1], () => {})
|
||||
expect(`Invalid watch source`).toHaveBeenWarned()
|
||||
})
|
||||
|
||||
it('stopping the watcher (effect)', async () => {
|
||||
const state = reactive({ count: 0 })
|
||||
let dummy
|
||||
|
||||
Reference in New Issue
Block a user