Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(toHaveText): normalize zero width white space (#10623)

Pavel Feldman127dacf5d474
diff --git a/packages/playwright-core/src/server/injected/injectedScript.ts b/packages/playwright-core/src/server/injected/injectedScript.ts
index a363533780..0febe508bb 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 }) => {