@ -266,6 +266,7 @@ describe('Directive v-on', () => {
e . keyCode = 1
} )
expect ( spy ) . toHaveBeenCalled ( )
Vue . config . keyCodes = Object . create ( null )
} )
it ( 'should override build-in keyCode' , ( ) => {
@ -288,6 +289,7 @@ describe('Directive v-on', () => {
e . keyCode = 40
} )
expect ( spy ) . toHaveBeenCalledTimes ( 3 )
Vue . config . keyCodes = Object . create ( null )
} )
it ( 'should bind to a child component' , ( ) => {
@ -483,4 +485,45 @@ describe('Directive v-on', () => {
triggerEvent ( vm . $el , 'click' )
} ) . not . toThrow ( )
} )
// Github Issue #5046
it ( 'should support keyboard modifier' , ( ) => {
const spyLeft = jasmine . createSpy ( )
const spyRight = jasmine . createSpy ( )
const spyUp = jasmine . createSpy ( )
const spyDown = jasmine . createSpy ( )
vm = new Vue ( {
el ,
template : `
< div >
< input ref = "left" @ keydown . left = "foo" > < / i n p u t >
< input ref = "right" @ keydown . right = "foo1" > < / i n p u t >
< input ref = "up" @ keydown . up = "foo2" > < / i n p u t >
< input ref = "down" @ keydown . down = "foo3" > < / i n p u t >
< / d i v >
` ,
methods : {
foo : spyLeft ,
foo1 : spyRight ,
foo2 : spyUp ,
foo3 : spyDown
}
} )
triggerEvent ( vm . $refs . left , 'keydown' , e => { e . keyCode = 37 } )
triggerEvent ( vm . $refs . left , 'keydown' , e => { e . keyCode = 39 } )
triggerEvent ( vm . $refs . right , 'keydown' , e => { e . keyCode = 39 } )
triggerEvent ( vm . $refs . right , 'keydown' , e => { e . keyCode = 38 } )
triggerEvent ( vm . $refs . up , 'keydown' , e => { e . keyCode = 38 } )
triggerEvent ( vm . $refs . up , 'keydown' , e => { e . keyCode = 37 } )
triggerEvent ( vm . $refs . down , 'keydown' , e => { e . keyCode = 40 } )
triggerEvent ( vm . $refs . down , 'keydown' , e => { e . keyCode = 39 } )
expect ( spyLeft . calls . count ( ) ) . toBe ( 1 )
expect ( spyRight . calls . count ( ) ) . toBe ( 1 )
expect ( spyUp . calls . count ( ) ) . toBe ( 1 )
expect ( spyDown . calls . count ( ) ) . toBe ( 1 )
} )
} )