From dcdb442a01288cb4b80e7cba7ca8a2f19f7def6b Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Tue, 30 Nov 2021 18:06:48 -0800 Subject: [PATCH] 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 a36353378073e..0febe508bb2ca 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 b4d1a882726de..7fec79d5701f3 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 }) => {