Skip to content

Commit

Permalink
fix(inline-snapshots): detect linebreaks
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed May 4, 2022
1 parent 1561836 commit a5e422f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/vitest/src/integrations/snapshot/port/utils.ts
Expand Up @@ -161,7 +161,7 @@ export async function saveSnapshotFile(

export function prepareExpected(expected?: string) {
function findStartIndent() {
const match = /^( +)}\s+$/m.exec(expected || '')
const match = /^( +)[}|"]/m.exec(expected || '')
return match?.[1]?.length || 0
}

Expand All @@ -171,7 +171,7 @@ export function prepareExpected(expected?: string) {

if (startIndent) {
expectedTrimmed = expectedTrimmed
?.replace(new RegExp(`^${' '.repeat(startIndent)}`, 'gm'), '').replace(/ +}$/, '}')
?.replace(new RegExp(`^${' '.repeat(startIndent)}`, 'gm'), '').replace(/ +[}|"]$/, '}')
}

return expectedTrimmed
Expand Down
9 changes: 9 additions & 0 deletions test/core/test/snapshot-inline.test.ts
Expand Up @@ -80,6 +80,15 @@ test('throwing inline snapshots', () => {
},
}
`)

expect(() => {
throw ['Inline', 'snapshot', 'with', 'newlines'].join('\n')
}).toThrowErrorMatchingInlineSnapshot(`
"Inline
snapshot
with
newlines"
`)
})

test('properties inline snapshot', () => {
Expand Down

0 comments on commit a5e422f

Please sign in to comment.