Skip to content

Commit

Permalink
fix(snapshot): preserve white spaces of toMatchFileSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Jan 2, 2025
1 parent c98b4b1 commit 874467a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/snapshot/src/port/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,9 @@ export default class SnapshotState {
: rawSnapshot
? rawSnapshot.content
: this._snapshotData[key]
const expectedTrimmed = prepareExpected(expected)
const pass = expectedTrimmed === prepareExpected(receivedSerialized)
const expectedTrimmed = rawSnapshot ? expected : prepareExpected(expected)
const receivedSerializedTrimmed = rawSnapshot ? receivedSerialized : prepareExpected(receivedSerialized)
const pass = expectedTrimmed === receivedSerializedTrimmed
const hasSnapshot = expected !== undefined
const snapshotIsPersisted
= isInline
Expand Down
2 changes: 2 additions & 0 deletions test/core/test/snapshot-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

white space
10 changes: 10 additions & 0 deletions test/core/test/snapshot-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
example: |
{
echo "hello"
}
some:
nesting:
- "hello world"
even:
more:
nesting: true
18 changes: 18 additions & 0 deletions test/core/test/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,21 @@ my string
"
`)
})

test('toMatchFileSnapshot preserves white spaces', async () => {
await expect(`
white space
`).toMatchFileSnapshot('snapshot-1.txt')
await expect(`\
example: |
{
echo "hello"
}
some:
nesting:
- "hello world"
even:
more:
nesting: true
`).toMatchFileSnapshot('snapshot-2.txt')
})

0 comments on commit 874467a

Please sign in to comment.