From 55fb53ef8290973d223c78edb26a1379463bc305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 7 Dec 2021 23:48:27 +0100 Subject: [PATCH] test(keyboard): add tests for click events being dispatched when Space/Enter gets pressed while focus is on a button (#10748) --- tests/page/page-keyboard.spec.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/page/page-keyboard.spec.ts b/tests/page/page-keyboard.spec.ts index 8194cd8418..2edf443976 100644 --- a/tests/page/page-keyboard.spec.ts +++ b/tests/page/page-keyboard.spec.ts @@ -440,6 +440,30 @@ it('should move to the start of the document', async ({ page, isMac }) => { expect(await page.evaluate(() => window.getSelection().toString())).toBe('1\n2\n3\n'); }); +it('should dispatch a click event on a button when Space gets pressed', async ({ page }) => { + await page.setContent(``); + const actual = await page.evaluateHandle(() => { + const actual = { clicked: false }; + document.querySelector('button').addEventListener('click', () => (actual.clicked = true)); + return actual; + }); + await page.focus('button'); + await page.keyboard.press('Space'); + expect((await actual.jsonValue()).clicked).toBe(true); +}); + +it('should dispatch a click event on a button when Enter gets pressed', async ({ page }) => { + await page.setContent(``); + const actual = await page.evaluateHandle(() => { + const actual = { clicked: false }; + document.querySelector('button').addEventListener('click', () => (actual.clicked = true)); + return actual; + }); + await page.focus('button'); + await page.keyboard.press('Enter'); + expect((await actual.jsonValue()).clicked).toBe(true); +}); + async function captureLastKeydown(page) { const lastEvent = await page.evaluateHandle(() => { const lastEvent = {