From f26d56601ca0d2726ad4350e1ddb7b95fbb1c31a Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 15 Apr 2024 23:39:59 +0800 Subject: [PATCH] chore: improve event value validation message --- packages/runtime-dom/__tests__/patchEvents.spec.ts | 5 ++--- packages/runtime-dom/src/modules/events.ts | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/runtime-dom/__tests__/patchEvents.spec.ts b/packages/runtime-dom/__tests__/patchEvents.spec.ts index b7a5af0ed0e..f70bf327aff 100644 --- a/packages/runtime-dom/__tests__/patchEvents.spec.ts +++ b/packages/runtime-dom/__tests__/patchEvents.spec.ts @@ -198,9 +198,8 @@ describe(`runtime-dom: events patching`, () => { patchProp(el, 'onClick', null, 'test') el.dispatchEvent(new Event('click')) expect( - '[Vue warn]: Wrong type passed to the event invoker, ' + - 'did you maybe forget @ or : in front of your prop?' + - '\nReceived onClick="test"', + `Wrong type passed as event handler to onClick - did you forget @ or : ` + + `in front of your prop?\nExpected function or array of functions, received type string.`, ).toHaveBeenWarned() }) }) diff --git a/packages/runtime-dom/src/modules/events.ts b/packages/runtime-dom/src/modules/events.ts index 09e4a22a84c..fd049a88f0d 100644 --- a/packages/runtime-dom/src/modules/events.ts +++ b/packages/runtime-dom/src/modules/events.ts @@ -1,4 +1,4 @@ -import { NOOP, hyphenate, isArray, isFunction, isString } from '@vue/shared' +import { NOOP, hyphenate, isArray, isFunction } from '@vue/shared' import { type ComponentInternalInstance, ErrorCodes, @@ -129,9 +129,8 @@ function sanitizeEventValue(value: unknown, propName: string): EventValue { return value as EventValue } warn( - `Wrong type passed to the event invoker, did you maybe forget @ or : ` + - `in front of your prop?\nReceived ` + - `${propName}=${isString(value) ? JSON.stringify(value) : `[${typeof value}]`}`, + `Wrong type passed as event handler to ${propName} - did you forget @ or : ` + + `in front of your prop?\nExpected function or array of functions, received type ${typeof value}.`, ) return NOOP }