Skip to content

Commit

Permalink
Ensure typeIn has correct key option
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Novy committed Nov 7, 2018
1 parent a6aae8a commit dee1094
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions addon-test-support/@ember/test-helpers/dom/type-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function keyEntry(element, character) {
bubbles: true,
cancellable: true,
charCode,
key: character
};

const keyEvents = {
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/dom/type-in-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ module('DOM Helper: typeIn', function(hooks) {
assert.equal(element.value, 'foo');
});

test('it triggers key events with correct arguments', async function(assert) {
element = buildInstrumentedElement('input', ['key', 'charCode']);
await typeIn(element, 'foo');

let chars = ['f', 'o', 'o'];
let expectedEventsWithArguments = expectedEvents.map((eventName) => {
// Only key events get the key arguments
if (!['keydown', 'keypress', 'keyup'].includes(eventName)) {
return `${eventName} undefined undefined`;
}
// After each keyup, the next character comes up
let char = eventName === 'keyup' ? chars.shift() : chars[0];

return `${eventName} ${char} ${char.charCodeAt()}`;
});

assert.verifySteps(expectedEventsWithArguments);
});

test('filling in an input with a delay', async function(assert) {
element = buildInstrumentedElement('input');
await typeIn(element, 'foo', { delay: 150 });
Expand Down

0 comments on commit dee1094

Please sign in to comment.