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

jest-snapshot: Distinguish empty string from external snapshot not written #8880

Merged
merged 4 commits into from Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@
- `[jest-leak-detector]` [**BREAKING**] Use `weak-napi` instead of `weak` package ([#8686](https://github.com/facebook/jest/pull/8686))
- `[jest-mock]` Fix for mockReturnValue overriding mockImplementationOnce ([#8398](https://github.com/facebook/jest/pull/8398))
- `[jest-snapshot]` Remove only the added newlines in multiline snapshots ([#8859](https://github.com/facebook/jest/pull/8859))
- `[jest-snapshot]` Distinguish empty string from external snapshot not written ([#8880](https://github.com/facebook/jest/pull/8880))

### Chore & Maintenance

Expand Down
4 changes: 2 additions & 2 deletions packages/jest-snapshot/src/State.ts
Expand Up @@ -185,7 +185,7 @@ export default class SnapshotState {
// Do not mark the snapshot as "checked" if the snapshot is inline and
// there's an external snapshot. This way the external snapshot can be
// removed with `--updateSnapshot`.
if (!(isInline && this._snapshotData[key])) {
if (!(isInline && this._snapshotData[key] !== undefined)) {
this._uncheckedKeys.delete(key);
}

Expand Down Expand Up @@ -248,7 +248,7 @@ export default class SnapshotState {
return {
actual: unescape(receivedSerialized),
count,
expected: expected ? unescape(expected) : null,
expected: expected !== undefined ? unescape(expected) : null,
key,
pass: false,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-snapshot/src/index.ts
Expand Up @@ -340,7 +340,7 @@ const _toMatchSnapshot = ({
let report: () => string;
if (pass) {
return {message: () => '', pass: true};
} else if (!expected) {
} else if (expected == null) {
report = () =>
`New snapshot was ${RECEIVED_COLOR('not written')}. The update flag ` +
`must be explicitly passed to write a new snapshot.\n\n` +
Expand Down