Skip to content

Commit

Permalink
Merge pull request #391 from localpcguy/addNumberKeyCodes
Browse files Browse the repository at this point in the history
add numbers to keyFromKeyCode
  • Loading branch information
rwjblue authored Jul 9, 2018
2 parents e172fe6 + b94c30a commit a4253d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion addon-test-support/@ember/test-helpers/dom/trigger-key-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ const keyFromKeyCode = {
38: 'ArrowUp',
39: 'ArrowRight',
40: 'ArrowDown',
48: '0',
49: '1',
50: '2',
51: '3',
52: '4',
53: '5',
54: '6',
55: '7',
56: '8',
57: '9',
65: 'a',
66: 'b',
67: 'c',
Expand Down Expand Up @@ -145,7 +155,7 @@ export default function triggerKeyEvent(target, eventType, key, modifiers = DEFA
);
}

if (isNumeric(key)) {
if (isNumeric(key) && key.length > 1) {
throw new Error(
`Must provide a numeric \`keyCode\` to \`triggerKeyEvent\` but you passed \`${key}\` as a string.`
);
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/dom/trigger-key-event-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ module('DOM Helper: triggerKeyEvent', function(hooks) {
await checkKey(38, 'ArrowUp');
await checkKey(39, 'ArrowRight');
await checkKey(40, 'ArrowDown');
await checkKey(48, '0');
await checkKey(57, '9');
await checkKey(91, 'Meta');
await checkKey(93, 'Meta');
await checkKey(187, '=');
Expand Down Expand Up @@ -218,6 +220,8 @@ module('DOM Helper: triggerKeyEvent', function(hooks) {
await checkKeyCode('Meta', 91);
await checkKeyCode('=', 187);
await checkKeyCode('-', 189);
await checkKeyCode('0', 48);
await checkKeyCode('9', 57);
await checkKeyCode('A', 65);
await checkKeyCode('Z', 90);
});
Expand Down

0 comments on commit a4253d1

Please sign in to comment.