Skip to content

Commit

Permalink
test(harness): Add #keypress method to fire keyup/keydown events on h…
Browse files Browse the repository at this point in the history
…arness interactive element.

PiperOrigin-RevId: 469228141
  • Loading branch information
joyzhong authored and copybara-github committed Aug 22, 2022
1 parent fd138f7 commit 2e15407
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions testing/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,17 @@ export class Harness<E extends HTMLElement = HTMLElement> {
this.simulateBlur(element);
}

/**
* Simulates a keypress on an element.
*
* @param key The key to press.
* @param init Additional event options.
*/
async keypress(key: string, init: KeyboardEventInit = {}) {
const element = await this.getInteractiveElement();
this.simulateKeypress(element, key, init);
}

/**
* Returns the element that should be used for interaction simulation.
* Defaults to the host element itself.
Expand Down

0 comments on commit 2e15407

Please sign in to comment.