@@ -116,18 +116,14 @@ describe('format API', () => {
116
116
formatDate = f . formatDate . bind ( null , config , state ) ;
117
117
} ) ;
118
118
119
- it ( 'fallsback and warns when no value is provided' , ( ) => {
120
- expect ( formatDate ( ) ) . toBe ( 'Invalid Date' ) ;
121
- expect ( consoleError ) . toHaveBeenCalledTimes ( 1 ) ;
122
- expect ( consoleError . mock . calls [ 0 ] [ 0 ] ) . toContain (
123
- '[React Intl] Error formatting date.\nRangeError'
124
- ) ;
119
+ it ( 'no value should render today' , ( ) => {
120
+ expect ( formatDate ( ) ) . toBe ( df . format ( ) ) ;
125
121
} ) ;
126
122
127
123
it ( 'fallsback and warns when a non-finite value is provided' , ( ) => {
128
- expect ( formatDate ( NaN ) ) . toBe ( 'Invalid Date ' ) ;
129
- expect ( formatDate ( '' ) ) . toBe ( 'Invalid Date' ) ;
130
- expect ( consoleError ) . toHaveBeenCalledTimes ( 2 ) ;
124
+ expect ( formatDate ( NaN ) ) . toBe ( 'NaN ' ) ;
125
+ expect ( formatDate ( '' ) ) . toBe ( df . format ( '' ) ) ;
126
+ expect ( consoleError ) . toHaveBeenCalledTimes ( 1 ) ;
131
127
} ) ;
132
128
133
129
it ( 'formats falsy finite values' , ( ) => {
@@ -141,7 +137,7 @@ describe('format API', () => {
141
137
} ) ;
142
138
143
139
it ( 'formats date string values' , ( ) => {
144
- expect ( formatDate ( new Date ( 0 ) . toString ( ) ) ) . toBe ( df . format ( new Date ( 0 ) ) ) ;
140
+ expect ( formatDate ( new Date ( 0 ) . toString ( ) ) ) . toBe ( new Date ( 0 ) . toString ( ) ) ;
145
141
} ) ;
146
142
147
143
it ( 'formats date ms timestamp values' , ( ) => {
@@ -175,7 +171,7 @@ describe('format API', () => {
175
171
} ) ;
176
172
177
173
it ( 'fallsback and warns on invalid Intl.DateTimeFormat options' , ( ) => {
178
- expect ( formatDate ( 0 , { year : 'invalid' } ) ) . toBe ( String ( new Date ( 0 ) ) ) ;
174
+ expect ( formatDate ( 0 , { year : 'invalid' } ) ) . toBe ( '0' ) ;
179
175
expect ( consoleError ) . toHaveBeenCalledTimes ( 1 ) ;
180
176
expect ( consoleError . mock . calls [ 0 ] [ 0 ] ) . toContain (
181
177
'[React Intl] Error formatting date.\nRangeError'
@@ -246,18 +242,14 @@ describe('format API', () => {
246
242
formatTime = f . formatTime . bind ( null , config , state ) ;
247
243
} ) ;
248
244
249
- it ( 'fallsback and warns when no value is provided' , ( ) => {
250
- expect ( formatTime ( ) ) . toBe ( 'Invalid Date' ) ;
251
- expect ( consoleError ) . toHaveBeenCalledTimes ( 1 ) ;
252
- expect ( consoleError . mock . calls [ 0 ] [ 0 ] ) . toContain (
253
- '[React Intl] Error formatting time.\nRangeError'
254
- ) ;
245
+ it ( 'render now if no value is provided' , ( ) => {
246
+ expect ( formatTime ( ) ) . toBe ( df . format ( ) ) ;
255
247
} ) ;
256
248
257
249
it ( 'fallsback and warns when a non-finite value is provided' , ( ) => {
258
- expect ( formatTime ( NaN ) ) . toBe ( 'Invalid Date ' ) ;
259
- expect ( formatTime ( '' ) ) . toBe ( 'Invalid Date' ) ;
260
- expect ( consoleError ) . toHaveBeenCalledTimes ( 2 ) ;
250
+ expect ( formatTime ( NaN ) ) . toBe ( 'NaN ' ) ;
251
+ expect ( formatTime ( '' ) ) . toBe ( df . format ( '' ) ) ;
252
+ expect ( consoleError ) . toHaveBeenCalledTimes ( 1 ) ;
261
253
} ) ;
262
254
263
255
it ( 'formats falsy finite values' , ( ) => {
@@ -271,7 +263,7 @@ describe('format API', () => {
271
263
} ) ;
272
264
273
265
it ( 'formats date string values' , ( ) => {
274
- expect ( formatTime ( new Date ( 0 ) . toString ( ) ) ) . toBe ( df . format ( new Date ( 0 ) ) ) ;
266
+ expect ( formatTime ( new Date ( 0 ) . toString ( ) ) ) . toBe ( new Date ( 0 ) . toString ( ) ) ;
275
267
} ) ;
276
268
277
269
it ( 'formats date ms timestamp values' , ( ) => {
@@ -309,7 +301,7 @@ describe('format API', () => {
309
301
} ) ;
310
302
311
303
it ( 'fallsback and warns on invalid Intl.DateTimeFormat options' , ( ) => {
312
- expect ( formatTime ( 0 , { hour : 'invalid' } ) ) . toBe ( String ( new Date ( 0 ) ) ) ;
304
+ expect ( formatTime ( 0 , { hour : 'invalid' } ) ) . toBe ( '0' ) ;
313
305
expect ( consoleError ) . toHaveBeenCalledTimes ( 1 ) ;
314
306
expect ( consoleError . mock . calls [ 0 ] [ 0 ] ) . toContain (
315
307
'[React Intl] Error formatting time.\nRangeError'
0 commit comments