})
render(h(Foo), nodeOps.createElement('div'))
expect(
- `Component emitted event "bar" but it is not declared`
+ `Component emitted event "bar" but it is neither declared`
).toHaveBeenWarned()
})
})
render(h(Foo), nodeOps.createElement('div'))
expect(
- `Component emitted event "bar" but it is not declared`
+ `Component emitted event "bar" but it is neither declared`
).toHaveBeenWarned()
})
+ test('should not warn if has equivalent onXXX prop', () => {
+ const Foo = defineComponent({
+ props: ['onFoo'],
+ emits: [],
+ render() {},
+ created() {
+ // @ts-ignore
+ this.$emit('foo')
+ }
+ })
+ render(h(Foo), nodeOps.createElement('div'))
+ expect(
+ `Component emitted event "bar" but it is neither declared`
+ ).not.toHaveBeenWarned()
+ })
+
test('validator warning', () => {
const Foo = defineComponent({
emits: {
import { ComponentInternalInstance } from './component'
import { callWithAsyncErrorHandling, ErrorCodes } from './errorHandling'
import { warn } from './warning'
+import { normalizePropsOptions } from './componentProps'
export type ObjectEmitsOptions = Record<
string,
const options = normalizeEmitsOptions(instance.type.emits)
if (options) {
if (!(event in options)) {
- warn(
- `Component emitted event "${event}" but it is not declared in the ` +
- `emits option.`
- )
+ const propsOptions = normalizePropsOptions(instance.type.props)[0]
+ if (!propsOptions || !(`on` + capitalize(event) in propsOptions)) {
+ warn(
+ `Component emitted event "${event}" but it is neither declared in ` +
+ `the emits option nor as an "on${capitalize(event)}" prop.`
+ )
+ }
} else {
const validator = options[event]
if (isFunction(validator)) {