From daece9cf49a09e6bff10b5d434645847b2e17c0e Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Wed, 1 Dec 2021 09:21:21 -0800 Subject: [PATCH] cherry-pick(#10623): fix(toHaveText): normalize zero width white space --- packages/playwright-core/src/server/injected/injectedScript.ts | 2 +- tests/playwright-test/playwright.expect.text.spec.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/playwright-core/src/server/injected/injectedScript.ts b/packages/playwright-core/src/server/injected/injectedScript.ts index 88438c2830..e982c961e7 100644 --- a/packages/playwright-core/src/server/injected/injectedScript.ts +++ b/packages/playwright-core/src/server/injected/injectedScript.ts @@ -1129,7 +1129,7 @@ class ExpectedTextMatcher { private normalizeWhiteSpace(s: string | undefined): string | undefined { if (!s) return s; - return this._normalizeWhiteSpace ? s.trim().replace(/\s+/g, ' ') : s; + return this._normalizeWhiteSpace ? s.trim().replace(/\u200b/g, '').replace(/\s+/g, ' ') : s; } } diff --git a/tests/playwright-test/playwright.expect.text.spec.ts b/tests/playwright-test/playwright.expect.text.spec.ts index b4d1a88272..7fec79d570 100644 --- a/tests/playwright-test/playwright.expect.text.spec.ts +++ b/tests/playwright-test/playwright.expect.text.spec.ts @@ -88,6 +88,8 @@ test('should support toHaveText w/ text', async ({ runInlineTest }) => { const locator = page.locator('#node'); // Should normalize whitespace. await expect(locator).toHaveText('Text content'); + // Should normalize zero width whitespace. + await expect(locator).toHaveText('T\u200be\u200bx\u200bt content'); }); test('pass contain', async ({ page }) => {