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)