Skip to content

Commit

Permalink
fix(snapshot): received add prepareExpected (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
poyoho committed Feb 9, 2022
1 parent 4aa09c8 commit 5a848c0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vitest/src/integrations/snapshot/port/state.ts
Expand Up @@ -193,7 +193,7 @@ export default class SnapshotState {
const receivedSerialized = addExtraLineBreaks(serialize(received, undefined, this._snapshotFormat))
const expected = isInline ? inlineSnapshot : this._snapshotData[key]
const expectedTrimmed = prepareExpected(expected)
const pass = expectedTrimmed === receivedSerialized?.trim()
const pass = expectedTrimmed === prepareExpected(receivedSerialized)
const hasSnapshot = expected !== undefined
const snapshotIsPersisted = isInline || fs.existsSync(this._snapshotPath)

Expand Down
12 changes: 12 additions & 0 deletions test/snapshots/test/__snapshots__/shapshots.test.ts.snap
@@ -0,0 +1,12 @@
// Vitest Snapshot v1

exports[`multiline strings 1`] = `
"
export default function () {
function Foo() {
}
return Foo;
}
"
`;
16 changes: 16 additions & 0 deletions test/snapshots/test/shapshots.test.ts
@@ -1,3 +1,15 @@
const println = () => {
const message = `
export default function () {
function Foo() {
}
return Foo;
}
`
return message
}

test('non default snapshot format', () => {
expect({ foo: ['bar'] }).toMatchInlineSnapshot(`
Object {
Expand All @@ -7,3 +19,7 @@ test('non default snapshot format', () => {
}
`)
})

test('multiline strings ', () => {
expect(println()).toMatchSnapshot()
})

0 comments on commit 5a848c0

Please sign in to comment.