diff --git a/packages/playwright/src/matchers/toMatchAriaSnapshot.ts b/packages/playwright/src/matchers/toMatchAriaSnapshot.ts index f3e7d47a6e..0bb600f7b0 100644 --- a/packages/playwright/src/matchers/toMatchAriaSnapshot.ts +++ b/packages/playwright/src/matchers/toMatchAriaSnapshot.ts @@ -126,7 +126,6 @@ function unshift(snapshot: string): string { const match = line.match(/^(\s*)/); if (match && match[1].length < whitespacePrefixLength) whitespacePrefixLength = match[1].length; - break; } return lines.filter(t => t.trim()).map(line => line.substring(whitespacePrefixLength)).join('\n'); } diff --git a/tests/page/page-aria-snapshot.spec.ts b/tests/page/page-aria-snapshot.spec.ts index a7937e9be5..fe0de8cb9e 100644 --- a/tests/page/page-aria-snapshot.spec.ts +++ b/tests/page/page-aria-snapshot.spec.ts @@ -27,7 +27,6 @@ function unshift(snapshot: string): string { const match = line.match(/^(\s*)/); if (match && match[1].length < whitespacePrefixLength) whitespacePrefixLength = match[1].length; - break; } return lines.filter(t => t.trim()).map(line => line.substring(whitespacePrefixLength)).join('\n'); } diff --git a/tests/page/to-match-aria-snapshot.spec.ts b/tests/page/to-match-aria-snapshot.spec.ts index 05a02f369b..3961d6ad0a 100644 --- a/tests/page/to-match-aria-snapshot.spec.ts +++ b/tests/page/to-match-aria-snapshot.spec.ts @@ -659,3 +659,17 @@ test('should parse attributes', async ({ page }) => { `); } }); + +test('should not unshift actual template text', async ({ page }) => { + await page.setContent(` +

title

+

title 2

+ `); + const error = await expect(page.locator('body')).toMatchAriaSnapshot(` + - heading "title" [level=1] + - heading "title 2" [level=1] + `, { timeout: 1000 }).catch(e => e); + expect(stripAnsi(error.message)).toContain(` + - heading "title" [level=1] +- heading "title 2" [level=1]`); +});