Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(snapshot): received add prepareExpected #711

Merged
merged 2 commits into from Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()
})