diff --git a/src/formatter/formatPropValue.js b/src/formatter/formatPropValue.js index 19b2b2884..1044e3b37 100644 --- a/src/formatter/formatPropValue.js +++ b/src/formatter/formatPropValue.js @@ -54,6 +54,9 @@ const formatPropValue = ( } if (propValue instanceof Date) { + if (isNaN(propValue.valueOf())) { + return `{new Date(NaN)}`; + } return `{new Date("${propValue.toISOString()}")}`; } diff --git a/src/formatter/formatPropValue.spec.js b/src/formatter/formatPropValue.spec.js index 62dfb8b37..8d0a0eeb4 100644 --- a/src/formatter/formatPropValue.spec.js +++ b/src/formatter/formatPropValue.spec.js @@ -93,6 +93,12 @@ describe('formatPropValue', () => { ).toBe('{new Date("2017-01-01T11:00:00.000Z")}'); }); + it('should format an invalid date prop value', () => { + expect(formatPropValue(new Date(NaN), false, 0, {})).toBe( + '{new Date(NaN)}' + ); + }); + it('should format an object prop value', () => { expect(formatPropValue({ foo: 42 }, false, 0, {})).toBe( '{*Mocked formatComplexDataStructure result*}'