File tree 2 files changed +33
-2
lines changed
2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -78,16 +78,42 @@ describe('renderer: component', () => {
78
78
setup ( ) {
79
79
return ( ) =>
80
80
h ( Child , {
81
+ // emit triggering single handler
81
82
onBar : ( ) => 1 ,
83
+ // emit triggering multiple handlers
82
84
onBaz : [ ( ) => Promise . resolve ( 2 ) , ( ) => Promise . resolve ( 3 ) ]
83
85
} )
84
86
}
85
87
}
86
88
87
89
render ( h ( App ) , nodeOps . createElement ( 'div' ) )
88
90
91
+ // assert return values from emit
89
92
expect ( noMatchEmitResult ) . toMatchObject ( [ ] )
90
93
expect ( singleEmitResult ) . toMatchObject ( [ 1 ] )
91
94
expect ( await Promise . all ( multiEmitResult ) ) . toMatchObject ( [ 2 , 3 ] )
92
95
} )
96
+
97
+ // for v-model:foo-bar usage in DOM templates
98
+ test ( 'emit update:xxx events should trigger kebab-case equivalent' , ( ) => {
99
+ const Child = defineComponent ( {
100
+ setup ( _ , { emit } ) {
101
+ emit ( 'update:fooBar' , 1 )
102
+ return ( ) => h ( 'div' )
103
+ }
104
+ } )
105
+
106
+ const handler = jest . fn ( )
107
+ const App = {
108
+ setup ( ) {
109
+ return ( ) =>
110
+ h ( Child , {
111
+ 'onUpdate:foo-bar' : handler
112
+ } )
113
+ }
114
+ }
115
+
116
+ render ( h ( App ) , nodeOps . createElement ( 'div' ) )
117
+ expect ( handler ) . toHaveBeenCalled ( )
118
+ } )
93
119
} )
Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ import {
25
25
NO ,
26
26
makeMap ,
27
27
isPromise ,
28
- isArray
28
+ isArray ,
29
+ hyphenate
29
30
} from '@vue/shared'
30
31
import { SuspenseBoundary } from './components/Suspense'
31
32
import { CompilerOptions } from '@vue/compiler-core'
@@ -221,7 +222,11 @@ export function defineComponentInstance(
221
222
222
223
emit : ( event , ...args ) : any [ ] => {
223
224
const props = instance . vnode . props || EMPTY_OBJ
224
- const handler = props [ `on${ event } ` ] || props [ `on${ capitalize ( event ) } ` ]
225
+ let handler = props [ `on${ event } ` ] || props [ `on${ capitalize ( event ) } ` ]
226
+ if ( ! handler && event . indexOf ( 'update:' ) === 0 ) {
227
+ event = hyphenate ( event )
228
+ handler = props [ `on${ event } ` ] || props [ `on${ capitalize ( event ) } ` ]
229
+ }
225
230
if ( handler ) {
226
231
const res = callWithAsyncErrorHandling (
227
232
handler ,
You can’t perform that action at this time.
0 commit comments