mirror of https://github.com/vuejs/core.git
chore: improve event value validation message
This commit is contained in:
parent
9da34d7af8
commit
f26d56601c
|
@ -198,9 +198,8 @@ describe(`runtime-dom: events patching`, () => {
|
||||||
patchProp(el, 'onClick', null, 'test')
|
patchProp(el, 'onClick', null, 'test')
|
||||||
el.dispatchEvent(new Event('click'))
|
el.dispatchEvent(new Event('click'))
|
||||||
expect(
|
expect(
|
||||||
'[Vue warn]: Wrong type passed to the event invoker, ' +
|
`Wrong type passed as event handler to onClick - did you forget @ or : ` +
|
||||||
'did you maybe forget @ or : in front of your prop?' +
|
`in front of your prop?\nExpected function or array of functions, received type string.`,
|
||||||
'\nReceived onClick="test"',
|
|
||||||
).toHaveBeenWarned()
|
).toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { NOOP, hyphenate, isArray, isFunction, isString } from '@vue/shared'
|
import { NOOP, hyphenate, isArray, isFunction } from '@vue/shared'
|
||||||
import {
|
import {
|
||||||
type ComponentInternalInstance,
|
type ComponentInternalInstance,
|
||||||
ErrorCodes,
|
ErrorCodes,
|
||||||
|
@ -129,9 +129,8 @@ function sanitizeEventValue(value: unknown, propName: string): EventValue {
|
||||||
return value as EventValue
|
return value as EventValue
|
||||||
}
|
}
|
||||||
warn(
|
warn(
|
||||||
`Wrong type passed to the event invoker, did you maybe forget @ or : ` +
|
`Wrong type passed as event handler to ${propName} - did you forget @ or : ` +
|
||||||
`in front of your prop?\nReceived ` +
|
`in front of your prop?\nExpected function or array of functions, received type ${typeof value}.`,
|
||||||
`${propName}=${isString(value) ? JSON.stringify(value) : `[${typeof value}]`}`,
|
|
||||||
)
|
)
|
||||||
return NOOP
|
return NOOP
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue