Skip to content

Commit 748205d

Browse files
authored
fix: apply stripSnapshotIndentation for thrown snapshot (#4663)
1 parent 574cc7d commit 748205d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

packages/vitest/src/integrations/snapshot/chai.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => {
154154
const promise = utils.flag(this, 'promise') as string | undefined
155155
const errorMessage = utils.flag(this, 'message')
156156

157+
if (inlineSnapshot)
158+
inlineSnapshot = stripSnapshotIndentation(inlineSnapshot)
159+
157160
getSnapshotClient().assert({
158161
received: getError(expected, promise),
159162
message,

test/core/test/snapshot-inline.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ test('throwing inline snapshots', async () => {
100100
newlines"
101101
`)
102102

103+
expect(() => {
104+
throw new Error(['Inline', 'snapshot', 'with', 'newlines'].join('\n'))
105+
}).toThrowErrorMatchingInlineSnapshot(`
106+
[Error: Inline
107+
snapshot
108+
with
109+
newlines]
110+
`)
111+
112+
expect(new Error(['Inline', 'snapshot', 'with', 'newlines'].join('\n'))).toMatchInlineSnapshot(`
113+
[Error: Inline
114+
snapshot
115+
with
116+
newlines]
117+
`)
118+
103119
await expect(async () => {
104120
throw new Error('omega')
105121
}).rejects.toThrowErrorMatchingInlineSnapshot(`[Error: omega]`)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy