Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simulate a key event with modifier key pressed in an Ember.js integration test?

I'm trying to test an event handler that reacts to the shift + delete key combo, but the Ember docs for the Test.keyEvent method don't seem to mention any way to activate modifier keys.

I tried issuing a keydown on shift (keyCode 16), then keydown on delete (keyCode 46):

keyEvent('.my input', 'keydown', 16);  // Shift
keyEvent('.my input', 'keydown', 46);  // Delete
keyEvent('.my input', 'keyup', 46);  // Delete
keyEvent('.my input', 'keyup', 16);  // Shift

but the delete event's shiftKey property is still undefined

like image 922
Gabriel Grant Avatar asked Jun 16 '16 20:06

Gabriel Grant


1 Answers

It seems the answer is to use triggerEvent instead of keyEvent:

triggerEvent('.my input', 'keydown', {
  keyCode: 46,  // Delete
  shiftKey: true
});
like image 172
Gabriel Grant Avatar answered Sep 20 '22 09:09

Gabriel Grant