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

This commit is contained in:
Pavel Feldman 2021-12-01 09:21:21 -08:00 committed by GitHub
parent f05252874a
commit 127dacf5d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View file

@ -1129,7 +1129,7 @@ class ExpectedTextMatcher {
private normalizeWhiteSpace(s: string | undefined): string | undefined { private normalizeWhiteSpace(s: string | undefined): string | undefined {
if (!s) if (!s)
return s; return s;
return this._normalizeWhiteSpace ? s.trim().replace(/\s+/g, ' ') : s; return this._normalizeWhiteSpace ? s.trim().replace(/\u200b/g, '').replace(/\s+/g, ' ') : s;
} }
} }

View file

@ -88,6 +88,8 @@ test('should support toHaveText w/ text', async ({ runInlineTest }) => {
const locator = page.locator('#node'); const locator = page.locator('#node');
// Should normalize whitespace. // Should normalize whitespace.
await expect(locator).toHaveText('Text content'); 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 }) => { test('pass contain', async ({ page }) => {