mirror of https://github.com/vuejs/core.git
fix(runtime-core): fix warning for missing event handler (#11489)
fix #4803 close #8268
This commit is contained in:
parent
a917c0539c
commit
e359ff0046
|
|
@ -155,12 +155,12 @@ describe('component: emit', () => {
|
|||
render() {},
|
||||
created() {
|
||||
// @ts-expect-error
|
||||
this.$emit('bar')
|
||||
this.$emit('bar-baz')
|
||||
},
|
||||
})
|
||||
render(h(Foo), nodeOps.createElement('div'))
|
||||
expect(
|
||||
`Component emitted event "bar" but it is neither declared`,
|
||||
`Component emitted event "bar-baz" but it is neither declared in the emits option nor as an "onBarBaz" prop`,
|
||||
).toHaveBeenWarned()
|
||||
})
|
||||
|
||||
|
|
@ -172,12 +172,12 @@ describe('component: emit', () => {
|
|||
render() {},
|
||||
created() {
|
||||
// @ts-expect-error
|
||||
this.$emit('bar')
|
||||
this.$emit('bar-baz')
|
||||
},
|
||||
})
|
||||
render(h(Foo), nodeOps.createElement('div'))
|
||||
expect(
|
||||
`Component emitted event "bar" but it is neither declared`,
|
||||
`Component emitted event "bar-baz" but it is neither declared in the emits option nor as an "onBarBaz" prop`,
|
||||
).toHaveBeenWarned()
|
||||
})
|
||||
|
||||
|
|
@ -197,6 +197,22 @@ describe('component: emit', () => {
|
|||
).not.toHaveBeenWarned()
|
||||
})
|
||||
|
||||
test('should not warn if has equivalent onXXX prop with kebab-cased event', () => {
|
||||
const Foo = defineComponent({
|
||||
props: ['onFooBar'],
|
||||
emits: [],
|
||||
render() {},
|
||||
created() {
|
||||
// @ts-expect-error
|
||||
this.$emit('foo-bar')
|
||||
},
|
||||
})
|
||||
render(h(Foo), nodeOps.createElement('div'))
|
||||
expect(
|
||||
`Component emitted event "foo-bar" but it is neither declared`,
|
||||
).not.toHaveBeenWarned()
|
||||
})
|
||||
|
||||
test('validator warning', () => {
|
||||
const Foo = defineComponent({
|
||||
emits: {
|
||||
|
|
|
|||
|
|
@ -102,10 +102,10 @@ export function emit(
|
|||
event.startsWith(compatModelEventPrefix))
|
||||
)
|
||||
) {
|
||||
if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
|
||||
if (!propsOptions || !(toHandlerKey(camelize(event)) in propsOptions)) {
|
||||
warn(
|
||||
`Component emitted event "${event}" but it is neither declared in ` +
|
||||
`the emits option nor as an "${toHandlerKey(event)}" prop.`,
|
||||
`the emits option nor as an "${toHandlerKey(camelize(event))}" prop.`,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue