Skip to content

Commit

Permalink
Fix pretty format failing when printing invalid dates (#6635)
Browse files Browse the repository at this point in the history
* Fix pretty format failing when printing invalid dates

* Updates changelog

* fixes wrong update of changelog

* changes the way pretty format outputs invalid dates
  • Loading branch information
huafu authored and rickhanlonii committed Aug 15, 2018
1 parent 9621416 commit 5d65701
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@

- `[jest-haste-map]` Optimize watchman crawler by using `glob` on initial query ([#6689](https://github.com/facebook/jest/pull/6689))

### Fixes

- `[pretty-format]` Fix formatting of invalid Date objects ([#6635](https://github.com/facebook/jest/pull/6635))

## 23.4.0

### Features
Expand Down
5 changes: 5 additions & 0 deletions packages/pretty-format/src/__tests__/pretty_format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ describe('prettyFormat()', () => {
expect(prettyFormat(val)).toEqual('2001-09-09T01:46:40.000Z');
});

it('prints an invalid date', () => {
const val = new Date(Infinity);
expect(prettyFormat(val)).toEqual('Date { NaN }');
});

it('prints an empty object', () => {
const val = {};
expect(prettyFormat(val)).toEqual('Object {}');
Expand Down
2 changes: 1 addition & 1 deletion packages/pretty-format/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function printBasicValue(
return printSymbol(val);
}
if (toStringed === '[object Date]') {
return toISOString.call(val);
return isNaN(+val) ? 'Date { NaN }' : toISOString.call(val);
}
if (toStringed === '[object Error]') {
return printError(val);
Expand Down

0 comments on commit 5d65701

Please sign in to comment.