Skip to content

Commit 8800601

Browse files
authored
fix(snapshot): fix toMatchFileSnapshot with empty file (#5894)
1 parent 64e200d commit 8800601

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

packages/snapshot/src/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export class SnapshotClient {
159159
options.filepath ||= filepath
160160
// resolve and read the raw snapshot file
161161
rawSnapshot.file = await snapshotState.environment.resolveRawPath(filepath, rawSnapshot.file)
162-
rawSnapshot.content = await snapshotState.environment.readSnapshotFile(rawSnapshot.file) || undefined
162+
rawSnapshot.content = await snapshotState.environment.readSnapshotFile(rawSnapshot.file) ?? undefined
163163
}
164164

165165
return this.assert(options)

test/core/test/fixtures/snapshot-empty.txt

Whitespace-only changes.

test/core/test/snapshot-file.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ describe('snapshots', () => {
1818
})
1919
}
2020
})
21+
22+
test('handle empty file', () => {
23+
expect('').toMatchFileSnapshot('./fixtures/snapshot-empty.txt')
24+
})

0 commit comments

Comments
 (0)