Skip to content

Commit

Permalink
fix: apply stripSnapshotIndentation for thrown snapshot (#4663)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Dec 5, 2023
1 parent 574cc7d commit 748205d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/vitest/src/integrations/snapshot/chai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions test/core/test/snapshot-inline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]`)
Expand Down

0 comments on commit 748205d

Please sign in to comment.