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()
})
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()
})
).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: {
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 {