File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -155,12 +155,12 @@ describe('component: emit', () => {
155155 render ( ) { } ,
156156 created ( ) {
157157 // @ts -expect-error
158- this . $emit ( 'bar' )
158+ this . $emit ( 'bar-baz ' )
159159 } ,
160160 } )
161161 render ( h ( Foo ) , nodeOps . createElement ( 'div' ) )
162162 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 ` ,
164164 ) . toHaveBeenWarned ( )
165165 } )
166166
@@ -172,12 +172,12 @@ describe('component: emit', () => {
172172 render ( ) { } ,
173173 created ( ) {
174174 // @ts -expect-error
175- this . $emit ( 'bar' )
175+ this . $emit ( 'bar-baz ' )
176176 } ,
177177 } )
178178 render ( h ( Foo ) , nodeOps . createElement ( 'div' ) )
179179 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 ` ,
181181 ) . toHaveBeenWarned ( )
182182 } )
183183
@@ -197,6 +197,22 @@ describe('component: emit', () => {
197197 ) . not . toHaveBeenWarned ( )
198198 } )
199199
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+
200216 test ( 'validator warning' , ( ) => {
201217 const Foo = defineComponent ( {
202218 emits : {
Original file line number Diff line number Diff line change @@ -102,10 +102,10 @@ export function emit(
102102 event . startsWith ( compatModelEventPrefix ) )
103103 )
104104 ) {
105- if ( ! propsOptions || ! ( toHandlerKey ( event ) in propsOptions ) ) {
105+ if ( ! propsOptions || ! ( toHandlerKey ( camelize ( event ) ) in propsOptions ) ) {
106106 warn (
107107 `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.` ,
109109 )
110110 }
111111 } else {
You can’t perform that action at this time.
0 commit comments