Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Feb 9, 2022
1 parent 76acb56 commit ac58c73
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/runtime-core/__tests__/apiWatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,21 @@ describe('api: watch', () => {
expect(sideEffect).toBe(2)
})

test('should force trigger on triggerRef when watching multiple sources: shallow ref array', async () => {
const v = shallowRef([] as any)
const spy = jest.fn()
watch([v], () => {
spy()
})

v.value.push(1)
triggerRef(v)

await nextTick()
// should trigger now
expect(spy).toHaveBeenCalledTimes(1)
})

// #2125
test('watchEffect should not recursively trigger itself', async () => {
const spy = jest.fn()
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function doWatch(
deep = true
} else if (isArray(source)) {
isMultiSource = true
forceTrigger = source.some(s=>isReactive(s) || isShallow(s))
forceTrigger = source.some(s => isReactive(s) || isShallow(s))
getter = () =>
source.map(s => {
if (isRef(s)) {
Expand Down

0 comments on commit ac58c73

Please sign in to comment.