@@ -205,6 +205,96 @@ describe('Directive v-on', () => {
205
205
expect ( spy ) . toHaveBeenCalled ( )
206
206
} )
207
207
208
+ // ctrl, shift, alt, meta
209
+ it ( 'should support system modifers' , ( ) => {
210
+ vm = new Vue ( {
211
+ el,
212
+ template : `
213
+ <div>
214
+ <input ref="ctrl" @keyup.ctrl="foo">
215
+ <input ref="shift" @keyup.shift="foo">
216
+ <input ref="alt" @keyup.alt="foo">
217
+ <input ref="meta" @keyup.meta="foo">
218
+ </div>
219
+ ` ,
220
+ methods : { foo : spy }
221
+ } )
222
+
223
+ triggerEvent ( vm . $refs . ctrl , 'keyup' )
224
+ expect ( spy . calls . count ( ) ) . toBe ( 0 )
225
+ triggerEvent ( vm . $refs . ctrl , 'keyup' , e => { e . ctrlKey = true } )
226
+ expect ( spy . calls . count ( ) ) . toBe ( 1 )
227
+
228
+ triggerEvent ( vm . $refs . shift , 'keyup' )
229
+ expect ( spy . calls . count ( ) ) . toBe ( 1 )
230
+ triggerEvent ( vm . $refs . shift , 'keyup' , e => { e . shiftKey = true } )
231
+ expect ( spy . calls . count ( ) ) . toBe ( 2 )
232
+
233
+ triggerEvent ( vm . $refs . alt , 'keyup' )
234
+ expect ( spy . calls . count ( ) ) . toBe ( 2 )
235
+ triggerEvent ( vm . $refs . alt , 'keyup' , e => { e . altKey = true } )
236
+ expect ( spy . calls . count ( ) ) . toBe ( 3 )
237
+
238
+ triggerEvent ( vm . $refs . meta , 'keyup' )
239
+ expect ( spy . calls . count ( ) ) . toBe ( 3 )
240
+ triggerEvent ( vm . $refs . meta , 'keyup' , e => { e . metaKey = true } )
241
+ expect ( spy . calls . count ( ) ) . toBe ( 4 )
242
+ } )
243
+
244
+ it ( 'should support exact modifier' , ( ) => {
245
+ vm = new Vue ( {
246
+ el,
247
+ template : `
248
+ <div>
249
+ <input ref="ctrl" @keyup.exact="foo">
250
+ </div>
251
+ ` ,
252
+ methods : { foo : spy }
253
+ } )
254
+
255
+ triggerEvent ( vm . $refs . ctrl , 'keyup' )
256
+ expect ( spy . calls . count ( ) ) . toBe ( 1 )
257
+
258
+ triggerEvent ( vm . $refs . ctrl , 'keyup' , e => {
259
+ e . ctrlKey = true
260
+ } )
261
+ expect ( spy . calls . count ( ) ) . toBe ( 1 )
262
+
263
+ // should not trigger if has other system modifiers
264
+ triggerEvent ( vm . $refs . ctrl , 'keyup' , e => {
265
+ e . ctrlKey = true
266
+ e . altKey = true
267
+ } )
268
+ expect ( spy . calls . count ( ) ) . toBe ( 1 )
269
+ } )
270
+
271
+ it ( 'should support system modifers with exact' , ( ) => {
272
+ vm = new Vue ( {
273
+ el,
274
+ template : `
275
+ <div>
276
+ <input ref="ctrl" @keyup.ctrl.exact="foo">
277
+ </div>
278
+ ` ,
279
+ methods : { foo : spy }
280
+ } )
281
+
282
+ triggerEvent ( vm . $refs . ctrl , 'keyup' )
283
+ expect ( spy . calls . count ( ) ) . toBe ( 0 )
284
+
285
+ triggerEvent ( vm . $refs . ctrl , 'keyup' , e => {
286
+ e . ctrlKey = true
287
+ } )
288
+ expect ( spy . calls . count ( ) ) . toBe ( 1 )
289
+
290
+ // should not trigger if has other system modifiers
291
+ triggerEvent ( vm . $refs . ctrl , 'keyup' , e => {
292
+ e . ctrlKey = true
293
+ e . altKey = true
294
+ } )
295
+ expect ( spy . calls . count ( ) ) . toBe ( 1 )
296
+ } )
297
+
208
298
it ( 'should support number keyCode' , ( ) => {
209
299
vm = new Vue ( {
210
300
el,
@@ -497,8 +587,8 @@ describe('Directive v-on', () => {
497
587
} ) . not . toThrow ( )
498
588
} )
499
589
500
- // GitHub Issue #5046
501
- it ( 'should support keyboard modifier' , ( ) => {
590
+ // Github Issue #5046
591
+ it ( 'should support keyboard modifier for direction keys ' , ( ) => {
502
592
const spyLeft = jasmine . createSpy ( )
503
593
const spyRight = jasmine . createSpy ( )
504
594
const spyUp = jasmine . createSpy ( )
0 commit comments