Skip to content

Commit

Permalink
fix(snapshot): fix toMatchFileSnapshot with empty file (#5894)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Jun 16, 2024
1 parent 64e200d commit 8800601
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/snapshot/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class SnapshotClient {
options.filepath ||= filepath
// resolve and read the raw snapshot file
rawSnapshot.file = await snapshotState.environment.resolveRawPath(filepath, rawSnapshot.file)
rawSnapshot.content = await snapshotState.environment.readSnapshotFile(rawSnapshot.file) || undefined
rawSnapshot.content = await snapshotState.environment.readSnapshotFile(rawSnapshot.file) ?? undefined
}

return this.assert(options)
Expand Down
Empty file.
4 changes: 4 additions & 0 deletions test/core/test/snapshot-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ describe('snapshots', () => {
})
}
})

test('handle empty file', () => {
expect('').toMatchFileSnapshot('./fixtures/snapshot-empty.txt')
})

0 comments on commit 8800601

Please sign in to comment.