From c0fa804367256f10d7e7859a6060bc1703838b35 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Fri, 15 Nov 2024 12:06:44 +0000 Subject: [PATCH] cherry-pick(#33619): fix(aria): normalize whitespace in toMatchAccessible{Name,Description} (#33621) --- packages/playwright/src/matchers/matchers.ts | 4 ++-- tests/page/expect-misc.spec.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/playwright/src/matchers/matchers.ts b/packages/playwright/src/matchers/matchers.ts index f7c68b4544f91..dd159a7f5e5a1 100644 --- a/packages/playwright/src/matchers/matchers.ts +++ b/packages/playwright/src/matchers/matchers.ts @@ -181,7 +181,7 @@ export function toHaveAccessibleDescription( options?: { timeout?: number, ignoreCase?: boolean }, ) { return toMatchText.call(this, 'toHaveAccessibleDescription', locator, 'Locator', async (isNot, timeout) => { - const expectedText = serializeExpectedTextValues([expected], { ignoreCase: options?.ignoreCase }); + const expectedText = serializeExpectedTextValues([expected], { ignoreCase: options?.ignoreCase, normalizeWhiteSpace: true }); return await locator._expect('to.have.accessible.description', { expectedText, isNot, timeout }); }, expected, options); } @@ -193,7 +193,7 @@ export function toHaveAccessibleName( options?: { timeout?: number, ignoreCase?: boolean }, ) { return toMatchText.call(this, 'toHaveAccessibleName', locator, 'Locator', async (isNot, timeout) => { - const expectedText = serializeExpectedTextValues([expected], { ignoreCase: options?.ignoreCase }); + const expectedText = serializeExpectedTextValues([expected], { ignoreCase: options?.ignoreCase, normalizeWhiteSpace: true }); return await locator._expect('to.have.accessible.name', { expectedText, isNot, timeout }); }, expected, options); } diff --git a/tests/page/expect-misc.spec.ts b/tests/page/expect-misc.spec.ts index 2242a5537822c..f99ac12376089 100644 --- a/tests/page/expect-misc.spec.ts +++ b/tests/page/expect-misc.spec.ts @@ -431,6 +431,9 @@ test('toHaveAccessibleName', async ({ page }) => { await expect(page.locator('div')).toHaveAccessibleName(/ell\w/); await expect(page.locator('div')).not.toHaveAccessibleName(/hello/); await expect(page.locator('div')).toHaveAccessibleName(/hello/, { ignoreCase: true }); + + await page.setContent(``); + await expect(page.locator('button')).toHaveAccessibleName('foo bar baz'); }); test('toHaveAccessibleDescription', async ({ page }) => { @@ -443,6 +446,12 @@ test('toHaveAccessibleDescription', async ({ page }) => { await expect(page.locator('div')).toHaveAccessibleDescription(/ell\w/); await expect(page.locator('div')).not.toHaveAccessibleDescription(/hello/); await expect(page.locator('div')).toHaveAccessibleDescription(/hello/, { ignoreCase: true }); + + await page.setContent(` +
+ foo bar\nbaz + `); + await expect(page.locator('div')).toHaveAccessibleDescription('foo bar baz'); }); test('toHaveRole', async ({ page }) => {