diff --git a/packages/runtime-core/__tests__/apiWatch.spec.ts b/packages/runtime-core/__tests__/apiWatch.spec.ts index 029146b5205..f6bad14ddb9 100644 --- a/packages/runtime-core/__tests__/apiWatch.spec.ts +++ b/packages/runtime-core/__tests__/apiWatch.spec.ts @@ -745,7 +745,7 @@ describe('api: watch', () => { const state = ref() const spy = jest.fn() watch(() => state.value, spy, { immediate: true }) - expect(spy).toHaveBeenCalled() + expect(spy).toHaveBeenCalledWith(undefined, undefined, expect.any(Function)) state.value = 3 await nextTick() expect(spy).toHaveBeenCalledTimes(2) diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 99445be77d2..4999e11f0c9 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -333,10 +333,11 @@ function doWatch( callWithAsyncErrorHandling(cb, instance, ErrorCodes.WATCH_CALLBACK, [ newValue, // pass undefined as the old value when it's changed for the first time - oldValue === INITIAL_WATCHER_VALUE || - (isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE) - ? [] - : oldValue, + oldValue === INITIAL_WATCHER_VALUE + ? undefined + : (isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE) + ? [] + : oldValue, onCleanup ]) oldValue = newValue