From 2e154079048481a55f20afefbdc8e7ff33f7f279 Mon Sep 17 00:00:00 2001 From: Joy Zhong Date: Mon, 22 Aug 2022 10:46:11 -0700 Subject: [PATCH] test(harness): Add #keypress method to fire keyup/keydown events on harness interactive element. PiperOrigin-RevId: 469228141 --- testing/harness.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/testing/harness.ts b/testing/harness.ts index fa6c336bbe..6c054409f7 100644 --- a/testing/harness.ts +++ b/testing/harness.ts @@ -304,6 +304,17 @@ export class Harness { 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.