File tree 2 files changed +22
-6
lines changed 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -155,12 +155,12 @@ describe('component: emit', () => {
155
155
render ( ) { } ,
156
156
created ( ) {
157
157
// @ts -expect-error
158
- this . $emit ( 'bar' )
158
+ this . $emit ( 'bar-baz ' )
159
159
} ,
160
160
} )
161
161
render ( h ( Foo ) , nodeOps . createElement ( 'div' ) )
162
162
expect (
163
- `Component emitted event "bar" but it is neither declared` ,
163
+ `Component emitted event "bar-baz " but it is neither declared in the emits option nor as an "onBarBaz" prop ` ,
164
164
) . toHaveBeenWarned ( )
165
165
} )
166
166
@@ -172,12 +172,12 @@ describe('component: emit', () => {
172
172
render ( ) { } ,
173
173
created ( ) {
174
174
// @ts -expect-error
175
- this . $emit ( 'bar' )
175
+ this . $emit ( 'bar-baz ' )
176
176
} ,
177
177
} )
178
178
render ( h ( Foo ) , nodeOps . createElement ( 'div' ) )
179
179
expect (
180
- `Component emitted event "bar" but it is neither declared` ,
180
+ `Component emitted event "bar-baz " but it is neither declared in the emits option nor as an "onBarBaz" prop ` ,
181
181
) . toHaveBeenWarned ( )
182
182
} )
183
183
@@ -197,6 +197,22 @@ describe('component: emit', () => {
197
197
) . not . toHaveBeenWarned ( )
198
198
} )
199
199
200
+ test ( 'should not warn if has equivalent onXXX prop with kebab-cased event' , ( ) => {
201
+ const Foo = defineComponent ( {
202
+ props : [ 'onFooBar' ] ,
203
+ emits : [ ] ,
204
+ render ( ) { } ,
205
+ created ( ) {
206
+ // @ts -expect-error
207
+ this . $emit ( 'foo-bar' )
208
+ } ,
209
+ } )
210
+ render ( h ( Foo ) , nodeOps . createElement ( 'div' ) )
211
+ expect (
212
+ `Component emitted event "foo-bar" but it is neither declared` ,
213
+ ) . not . toHaveBeenWarned ( )
214
+ } )
215
+
200
216
test ( 'validator warning' , ( ) => {
201
217
const Foo = defineComponent ( {
202
218
emits : {
Original file line number Diff line number Diff line change @@ -102,10 +102,10 @@ export function emit(
102
102
event . startsWith ( compatModelEventPrefix ) )
103
103
)
104
104
) {
105
- if ( ! propsOptions || ! ( toHandlerKey ( event ) in propsOptions ) ) {
105
+ if ( ! propsOptions || ! ( toHandlerKey ( camelize ( event ) ) in propsOptions ) ) {
106
106
warn (
107
107
`Component emitted event "${ event } " but it is neither declared in ` +
108
- `the emits option nor as an "${ toHandlerKey ( event ) } " prop.` ,
108
+ `the emits option nor as an "${ toHandlerKey ( camelize ( event ) ) } " prop.` ,
109
109
)
110
110
}
111
111
} else {
You can’t perform that action at this time.
0 commit comments