diff --git a/packages/vitest/src/integrations/snapshot/chai.ts b/packages/vitest/src/integrations/snapshot/chai.ts index 4f86d0b0668f..6ee0b0e62d6e 100644 --- a/packages/vitest/src/integrations/snapshot/chai.ts +++ b/packages/vitest/src/integrations/snapshot/chai.ts @@ -154,6 +154,9 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => { const promise = utils.flag(this, 'promise') as string | undefined const errorMessage = utils.flag(this, 'message') + if (inlineSnapshot) + inlineSnapshot = stripSnapshotIndentation(inlineSnapshot) + getSnapshotClient().assert({ received: getError(expected, promise), message, diff --git a/test/core/test/snapshot-inline.test.ts b/test/core/test/snapshot-inline.test.ts index 657e7a243940..fa91f4f74873 100644 --- a/test/core/test/snapshot-inline.test.ts +++ b/test/core/test/snapshot-inline.test.ts @@ -100,6 +100,22 @@ test('throwing inline snapshots', async () => { newlines" `) + expect(() => { + throw new Error(['Inline', 'snapshot', 'with', 'newlines'].join('\n')) + }).toThrowErrorMatchingInlineSnapshot(` + [Error: Inline + snapshot + with + newlines] + `) + + expect(new Error(['Inline', 'snapshot', 'with', 'newlines'].join('\n'))).toMatchInlineSnapshot(` + [Error: Inline + snapshot + with + newlines] + `) + await expect(async () => { throw new Error('omega') }).rejects.toThrowErrorMatchingInlineSnapshot(`[Error: omega]`)