@@ -156,6 +156,21 @@ describe('<FormattedMessage>', () => {
156
156
expect ( rendered . text ( ) ) . toBe ( intl . formatMessage ( descriptor ) ) ;
157
157
} ) ;
158
158
159
+ it ( 'should render out raw array if tagName is not specified' , ( ) => {
160
+ const descriptor = {
161
+ id : 'hello' ,
162
+ defaultMessage : 'Hello, World!' ,
163
+ tagName : ''
164
+ } ;
165
+
166
+ const rendered = mountWithProvider (
167
+ descriptor ,
168
+ { ...providerProps , textComponent : undefined }
169
+ ) ;
170
+
171
+ expect ( rendered . text ( ) ) . toBe ( intl . formatMessage ( descriptor ) ) ;
172
+ } ) ;
173
+
159
174
it ( 'supports function-as-child pattern' , ( ) => {
160
175
const descriptor = {
161
176
id : 'hello' ,
@@ -244,6 +259,44 @@ describe('<FormattedMessage>', () => {
244
259
expect ( nameNode . text ( ) ) . toBe ( 'Jest' ) ;
245
260
} ) ;
246
261
} ) ;
262
+ it ( 'should use timeZone from Provider' , function ( ) {
263
+ const rendered = mountWithProvider (
264
+ {
265
+ id : 'hello' ,
266
+ values : {
267
+ ts : new Date ( 0 ) ,
268
+ } ,
269
+ } ,
270
+ {
271
+ ...providerProps ,
272
+ messages : {
273
+ hello : 'Hello, {ts, date, short} - {ts, time, short}' ,
274
+ } ,
275
+ timeZone : 'Asia/Tokyo' ,
276
+ }
277
+ ) ;
278
+
279
+ expect ( rendered . text ( ) ) . toBe ( 'Hello, 1/1/70 - 9:00 AM' ) ;
280
+ } ) ;
281
+
282
+ it ( 'should use timeZone from Provider for defaultMessage' , function ( ) {
283
+ const rendered = mountWithProvider (
284
+ {
285
+ id : 'hello' ,
286
+ defaultMessage : 'Hello, {ts, date, short} - {ts, time, short}' ,
287
+ values : {
288
+ ts : new Date ( 0 ) ,
289
+ } ,
290
+ } ,
291
+ {
292
+ ...providerProps ,
293
+ timeZone : 'Asia/Tokyo' ,
294
+ }
295
+ ) ;
296
+
297
+ expect ( rendered . text ( ) ) . toBe ( 'Hello, 1/1/70 - 9:00 AM' ) ;
298
+ } ) ;
299
+
247
300
it ( 'should merge timeZone into formats' , function ( ) {
248
301
const rendered = mountWithProvider (
249
302
{
@@ -259,18 +312,20 @@ describe('<FormattedMessage>', () => {
259
312
} ,
260
313
formats : {
261
314
time : {
262
- short : { hour : 'numeric' , minute : 'numeric' , second : 'numeric' } ,
263
- } ,
264
- date : { short : { year : '2-digit' , month : 'numeric' , day : 'numeric' } } ,
265
- } as CustomFormats ,
266
- timeZone : 'Europe/London' ,
315
+ short : {
316
+ second : 'numeric' ,
317
+ timeZoneName : 'long'
318
+ }
319
+ }
320
+ } ,
321
+ timeZone : 'Asia/Tokyo' ,
267
322
}
268
323
) ;
269
324
270
- expect ( rendered . text ( ) ) . toBe ( 'Hello, 1/1/70 - 1 :00:00 AM' ) ;
325
+ expect ( rendered . text ( ) ) . toBe ( 'Hello, 1/1/70 - 9 :00:00 AM Japan Standard Time ' ) ;
271
326
} ) ;
272
327
273
- it ( 'should merge timeZone into formats ' , function ( ) {
328
+ it ( 'should merge timeZone into defaultFormats ' , function ( ) {
274
329
const rendered = mountWithProvider (
275
330
{
276
331
id : 'hello' ,
@@ -283,15 +338,17 @@ describe('<FormattedMessage>', () => {
283
338
...providerProps ,
284
339
defaultFormats : {
285
340
time : {
286
- short : { hour : 'numeric' , minute : 'numeric' , second : 'numeric' } ,
287
- } ,
288
- date : { short : { year : '2-digit' , month : 'numeric' , day : 'numeric' } } ,
289
- } as CustomFormats ,
341
+ short : {
342
+ second : 'numeric' ,
343
+ timeZoneName : 'long'
344
+ }
345
+ }
346
+ } ,
290
347
timeZone : 'Asia/Tokyo' ,
291
348
}
292
349
) ;
293
350
294
- expect ( rendered . text ( ) ) . toBe ( 'Hello, 1/1/70 - 9:00:00 AM' ) ;
351
+ expect ( rendered . text ( ) ) . toBe ( 'Hello, 1/1/70 - 9:00:00 AM Japan Standard Time ' ) ;
295
352
} ) ;
296
353
297
354
it ( 'should re-render when `values` are different' , ( ) => {
0 commit comments