File tree 2 files changed +13
-2
lines changed
2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { truncate } from './helpers'
2
2
3
3
export default function inspectDate ( dateObject , options ) {
4
- // If we need to - truncate the time portion, but never the date
5
- const split = dateObject . toJSON ( ) . split ( 'T' )
4
+ const stringRepresentation = dateObject . toJSON ( )
5
+
6
+ if ( stringRepresentation === null ) {
7
+ return 'Invalid Date'
8
+ }
9
+
10
+ const split = stringRepresentation . split ( 'T' )
6
11
const date = split [ 0 ]
12
+ // If we need to - truncate the time portion, but never the date
7
13
return options . stylize ( `${ date } T${ truncate ( split [ 1 ] , options . truncate - date . length - 1 ) } ` , 'date' )
8
14
}
Original file line number Diff line number Diff line change @@ -5,6 +5,11 @@ describe('date', () => {
5
5
expect ( inspect ( new Date ( 1475318637123 ) ) ) . to . equal ( '2016-10-01T10:43:57.123Z' )
6
6
} )
7
7
8
+ it ( 'returns "Invalid Date" if given an invalid Date object' , ( ) => {
9
+ // See: https://github.com/chaijs/loupe/issues/58
10
+ expect ( inspect ( new Date ( 'not a date' ) ) ) . to . equal ( 'Invalid Date' )
11
+ } )
12
+
8
13
describe ( 'colors' , ( ) => {
9
14
it ( 'returns date with red color, if colour is set to true' , ( ) => {
10
15
expect ( inspect ( new Date ( 1475318637123 ) , { colors : true } ) ) . to . equal (
You can’t perform that action at this time.
0 commit comments