File tree 2 files changed +37
-5
lines changed
2 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,30 @@ describe('component: emit', () => {
196
196
expect ( fn ) . toHaveBeenCalledTimes ( 1 )
197
197
} )
198
198
199
+ test ( '.once with normal listener of the same name' , ( ) => {
200
+ const Foo = defineComponent ( {
201
+ render ( ) { } ,
202
+ emits : {
203
+ foo : null
204
+ } ,
205
+ created ( ) {
206
+ this . $emit ( 'foo' )
207
+ this . $emit ( 'foo' )
208
+ }
209
+ } )
210
+ const onFoo = jest . fn ( )
211
+ const onFooOnce = jest . fn ( )
212
+ render (
213
+ h ( Foo , {
214
+ onFoo,
215
+ onFooOnce
216
+ } ) ,
217
+ nodeOps . createElement ( 'div' )
218
+ )
219
+ expect ( onFoo ) . toHaveBeenCalledTimes ( 2 )
220
+ expect ( onFooOnce ) . toHaveBeenCalledTimes ( 1 )
221
+ } )
222
+
199
223
test ( 'isEmitListener' , ( ) => {
200
224
const options = { click : null }
201
225
expect ( isEmitListener ( options , 'onClick' ) ) . toBe ( true )
Original file line number Diff line number Diff line change @@ -105,17 +105,25 @@ export function emit(
105
105
handlerName = toHandlerKey ( hyphenate ( event ) )
106
106
handler = props [ handlerName ]
107
107
}
108
- if ( ! handler ) {
109
- handler = props [ handlerName + `Once` ]
108
+
109
+ if ( handler ) {
110
+ callWithAsyncErrorHandling (
111
+ handler ,
112
+ instance ,
113
+ ErrorCodes . COMPONENT_EVENT_HANDLER ,
114
+ args
115
+ )
116
+ }
117
+
118
+ const onceHandler = props [ handlerName + `Once` ]
119
+ if ( onceHandler ) {
110
120
if ( ! instance . emitted ) {
111
121
; ( instance . emitted = { } as Record < string , boolean > ) [ handlerName ] = true
112
122
} else if ( instance . emitted [ handlerName ] ) {
113
123
return
114
124
}
115
- }
116
- if ( handler ) {
117
125
callWithAsyncErrorHandling (
118
- handler ,
126
+ onceHandler ,
119
127
instance ,
120
128
ErrorCodes . COMPONENT_EVENT_HANDLER ,
121
129
args
You can’t perform that action at this time.
0 commit comments