@@ -362,6 +362,68 @@ describe('Element.Event keyup with f<key>', function(){
362
362
363
363
} ) ;
364
364
365
+ describe ( 'Keypress key code' , function ( ) {
366
+
367
+ /*<ltIE8>*/
368
+ // return early for IE8- because Syn.js does not fire events
369
+ if ( ! document . addEventListener ) return ;
370
+ /*</ltIE8>*/
371
+
372
+ var input , key , shift , done ;
373
+
374
+ function keyHandler ( e ) {
375
+ key = e . key ;
376
+ shift = ! ! e . event . shiftKey ;
377
+ }
378
+
379
+ function typeWriter ( action ) {
380
+ setTimeout ( function ( ) {
381
+ Syn . type ( action , 'keyTester' ) ;
382
+ } , 1 ) ;
383
+ if ( done ) return true ;
384
+ }
385
+
386
+ beforeEach ( function ( ) {
387
+ input = new Element ( 'input' , {
388
+ 'type' : 'text' ,
389
+ 'id' : 'keyTester'
390
+ } ) . addEvent ( 'keypress' , keyHandler ) . inject ( document . body ) ;
391
+ } ) ;
392
+
393
+ afterEach ( function ( ) {
394
+ input . removeEvent ( 'keypress' , keyHandler ) . destroy ( ) ;
395
+ input = key = shift = done = null ;
396
+ } ) ;
397
+
398
+ it ( 'should return "enter" in event.key' , function ( ) {
399
+ typeWriter ( '[enter]' ) ;
400
+ waits ( 50 ) ;
401
+ runs ( function ( ) {
402
+ expect ( key ) . toBe ( 'enter' ) ;
403
+ expect ( shift ) . not . toBeTruthy ( ) ;
404
+ } ) ;
405
+ } ) ;
406
+
407
+ it ( 'should return "1" in event.key' , function ( ) {
408
+ typeWriter ( '1' ) ;
409
+ waits ( 50 ) ;
410
+ runs ( function ( ) {
411
+ expect ( key ) . toBe ( '1' ) ;
412
+ expect ( shift ) . not . toBeTruthy ( ) ;
413
+ } ) ;
414
+ } ) ;
415
+
416
+ it ( 'should return false when pressing SHIFT + 1' , function ( ) {
417
+ typeWriter ( '[shift]![shift-up]' ) ;
418
+ waits ( 50 ) ;
419
+ runs ( function ( ) {
420
+ expect ( key ) . toBe ( false ) ;
421
+ expect ( shift ) . toBeTruthy ( ) ;
422
+ } ) ;
423
+ } ) ;
424
+
425
+ } ) ;
426
+
365
427
describe ( 'Element.removeEvent' , function ( ) {
366
428
367
429
it ( 'should remove the onunload method' , function ( ) {
0 commit comments