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

This commit is contained in:
Pavel Feldman 2021-12-01 09:21:21 -08:00
parent 013eea654a
commit daece9cf49
2 changed files with 3 additions and 1 deletions

View file

@ -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;
}
}

View file

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