diff --git a/packages/vitest/src/integrations/snapshot/port/inlineSnapshot.ts b/packages/vitest/src/integrations/snapshot/port/inlineSnapshot.ts index 0ced2c115..041a6d34c 100644 --- a/packages/vitest/src/integrations/snapshot/port/inlineSnapshot.ts +++ b/packages/vitest/src/integrations/snapshot/port/inlineSnapshot.ts @@ -61,6 +61,7 @@ function prepareSnapString(snap: string, source: string, index: number) { const lines = snap .trim() .replace(/\\/g, '\\\\') + .replace(/\$/g, '\\$') .split(/\n/g) .map(i => i.trimEnd()) diff --git a/test/core/test/snapshot.test.ts b/test/core/test/snapshot.test.ts index b74ccc970..8f84ab5ad 100644 --- a/test/core/test/snapshot.test.ts +++ b/test/core/test/snapshot.test.ts @@ -37,6 +37,15 @@ test('inline snapshot', () => { .filter(fn) " `) + const literal = ` + Hello \${world} +` + expect(literal) + .toMatchInlineSnapshot(` + " + Hello \${world} + " + `) }) test('snapshot with big array', () => {