File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -163,4 +163,16 @@ describe('runtime-dom: v-on directive', () => {
163163 triggerEvent ( el2 , 'click' , e => ( e . shiftKey = true ) )
164164 expect ( fn ) . toBeCalledTimes ( 2 )
165165 } )
166+
167+ it ( 'withModifiers should handle null or undefined handler' , ( ) => {
168+ expect ( ( ) => {
169+ const handler1 = withModifiers ( null as any , [ 'ctrl' ] )
170+ expect ( handler1 ) . toBe ( null )
171+ } ) . not . toThrow ( )
172+
173+ expect ( ( ) => {
174+ const handler2 = withModifiers ( undefined as any , [ 'shift' ] )
175+ expect ( handler2 ) . toBe ( undefined )
176+ } ) . not . toThrow ( )
177+ } )
166178} )
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ export const withModifiers = <
5555 fn : T & { _withMods ?: { [ key : string ] : T } } ,
5656 modifiers : VOnModifiers [ ] ,
5757) : T => {
58+ if ( ! fn ) return fn
5859 const cache = fn . _withMods || ( fn . _withMods = { } )
5960 const cacheKey = modifiers . join ( '.' )
6061 return (
You can’t perform that action at this time.
0 commit comments