diff --git a/packages/vitest/src/integrations/snapshot/port/inlineSnapshot.ts b/packages/vitest/src/integrations/snapshot/port/inlineSnapshot.ts index 041a6d34cb7e..1d38234fbe8b 100644 --- a/packages/vitest/src/integrations/snapshot/port/inlineSnapshot.ts +++ b/packages/vitest/src/integrations/snapshot/port/inlineSnapshot.ts @@ -72,7 +72,7 @@ function prepareSnapString(snap: string, source: string, index: number) { : `${quote}\n${lines.map(i => indentNext + i).join('\n').replace(/`/g, '\\`')}\n${indent}${quote}` } -const startRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(['"`\)])/m +const startRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*[\w_$]*(['"`\)])/m export function replaceInlineSnap(code: string, s: MagicString, index: number, newSnap: string) { const startMatch = startRegex.exec(code.slice(index)) if (!startMatch) diff --git a/test/core/test/snapshot-inline.test.ts b/test/core/test/snapshot-inline.test.ts index 00f2a3479e0c..4bfabc8ed071 100644 --- a/test/core/test/snapshot-inline.test.ts +++ b/test/core/test/snapshot-inline.test.ts @@ -87,3 +87,22 @@ test('properties inline snapshot', () => { } `) }) + +test('literal tag', () => { + const html = String.raw + const text = ` + +

My First Heading.

+

My first paragraph.

+ +` + + expect(text).toMatchInlineSnapshot(html` + " + +

My First Heading.

+

My first paragraph.

+ + " + `) +})