Skip to content

Commit

Permalink
chore: improve event value validation message
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 15, 2024
1 parent 9da34d7 commit f26d566
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions packages/runtime-dom/__tests__/patchEvents.spec.ts
Expand Up @@ -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()
})
})
7 changes: 3 additions & 4 deletions 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,
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit f26d566

Please sign in to comment.