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 }) => {