diff --git a/packages/snapshot/src/client.ts b/packages/snapshot/src/client.ts index 1742a810f..e6add4e99 100644 --- a/packages/snapshot/src/client.ts +++ b/packages/snapshot/src/client.ts @@ -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) diff --git a/test/core/test/fixtures/snapshot-empty.txt b/test/core/test/fixtures/snapshot-empty.txt new file mode 100644 index 000000000..e69de29bb diff --git a/test/core/test/snapshot-file.test.ts b/test/core/test/snapshot-file.test.ts index c1eb01cf7..28c65b014 100644 --- a/test/core/test/snapshot-file.test.ts +++ b/test/core/test/snapshot-file.test.ts @@ -18,3 +18,7 @@ describe('snapshots', () => { }) } }) + +test('handle empty file', () => { + expect('').toMatchFileSnapshot('./fixtures/snapshot-empty.txt') +})