File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -81,7 +81,8 @@ export function stringify(value, reducers) {
81
81
break ;
82
82
83
83
case 'Date' :
84
- str = `["Date","${ thing . toISOString ( ) } "]` ;
84
+ const isValidDate = ! isNaN ( thing . getDate ( ) )
85
+ str = `["Date","${ isValidDate ? thing . toISOString ( ) : '' } "]` ;
85
86
break ;
86
87
87
88
case 'RegExp' :
Original file line number Diff line number Diff line change @@ -107,6 +107,15 @@ const fixtures = {
107
107
js : 'new Date(1000000000000)' ,
108
108
json : '[["Date","2001-09-09T01:46:40.000Z"]]'
109
109
} ,
110
+ {
111
+ name : 'invalid Date' ,
112
+ value : new Date ( '' ) ,
113
+ js : 'new Date(NaN)' ,
114
+ json : '[["Date",""]]' ,
115
+ validate : ( value ) => {
116
+ assert . ok ( isNaN ( value . valueOf ( ) ) ) ;
117
+ }
118
+ } ,
110
119
{
111
120
name : 'Array' ,
112
121
value : [ 'a' , 'b' , 'c' ] ,
@@ -455,7 +464,6 @@ for (const [name, tests] of Object.entries(fixtures)) {
455
464
test ( t . name , ( ) => {
456
465
const actual = unflatten ( JSON . parse ( t . json ) , t . revivers ) ;
457
466
const expected = t . value ;
458
-
459
467
if ( t . validate ) {
460
468
t . validate ( actual ) ;
461
469
} else {
You can’t perform that action at this time.
0 commit comments