@@ -16,6 +16,29 @@ describe('format()', () => {
1616 expect ( actual ) . equal ( '' ) ;
1717 } ) ;
1818
19+ describe ( 'format based on value type' , ( ) => {
20+ it ( 'integer' , ( ) => {
21+ const actual = format ( 1234 ) ;
22+ expect ( actual ) . equal ( '1,234' ) ;
23+ } ) ;
24+ it ( 'decimal' , ( ) => {
25+ const actual = format ( 1234.5678 ) ;
26+ expect ( actual ) . equal ( '1,234.57' ) ;
27+ } ) ;
28+ it ( 'date string' , ( ) => {
29+ const actual = format ( testDateStr ) ;
30+ expect ( actual ) . equal ( '11/21/2023' ) ;
31+ } ) ;
32+ it ( 'date' , ( ) => {
33+ const actual = format ( parseDate ( testDateStr ) ) ;
34+ expect ( actual ) . equal ( '11/21/2023' ) ;
35+ } ) ;
36+ it ( 'string' , ( ) => {
37+ const actual = format ( 'hello' ) ;
38+ expect ( actual ) . equal ( 'hello' ) ;
39+ } ) ;
40+ } ) ;
41+
1942 describe ( 'formats number' , ( ) => {
2043 // See `number.test.ts` for more number tests
2144 it ( 'returns original value as string for style "none"' , ( ) => {
@@ -46,6 +69,16 @@ describe('format()', () => {
4669 expect ( actual ) . equal ( '1,234.57' ) ;
4770 } ) ;
4871
72+ it ( 'formats with "decimal" config with locale (es)' , ( ) => {
73+ const actual = format ( 1234.5678 , { type : 'decimal' , locale : 'es' } ) ;
74+ expect ( actual ) . equal ( '1234,57' ) ;
75+ } ) ;
76+
77+ it ( 'formats with "decimal" config with locale (de)' , ( ) => {
78+ const actual = format ( 1234.5678 , { type : 'decimal' , locale : 'de' } ) ;
79+ expect ( actual ) . equal ( '1.234,57' ) ;
80+ } ) ;
81+
4982 it ( 'formats with "decimal" config with extra options' , ( ) => {
5083 const actual = format ( 1234.5678 , { type : 'decimal' , options : { fractionDigits : 3 } } ) ;
5184 expect ( actual ) . equal ( '1,234.568' ) ;
@@ -100,32 +133,19 @@ describe('format()', () => {
100133 expect ( actual ) . equal ( '11/21/2023' ) ;
101134 } ) ;
102135
103- it ( 'formats date with config with extra options ' , ( ) => {
104- const actual = format ( testDate , { type : 'day' , options : { variant : 'short' } } ) ;
105- expect ( actual ) . equal ( '11/21 ' ) ;
136+ it ( 'formats date with config with locale ' , ( ) => {
137+ const actual = format ( testDate , { type : 'day' , locale : 'es' } ) ;
138+ expect ( actual ) . equal ( '21/ 11/2023 ' ) ;
106139 } ) ;
107- } ) ;
108140
109- describe ( 'format based on value type' , ( ) => {
110- it ( 'format based on value type (integer)' , ( ) => {
111- const actual = format ( 1234 ) ;
112- expect ( actual ) . equal ( '1,234' ) ;
113- } ) ;
114- it ( 'format based on value type (decimal)' , ( ) => {
115- const actual = format ( 1234.5678 ) ;
116- expect ( actual ) . equal ( '1,234.57' ) ;
117- } ) ;
118- it ( 'format based on value type (date string)' , ( ) => {
119- const actual = format ( testDateStr ) ;
120- expect ( actual ) . equal ( '11/21/2023' ) ;
121- } ) ;
122- it ( 'format based on value type (date)' , ( ) => {
123- const actual = format ( parseDate ( testDateStr ) ) ;
124- expect ( actual ) . equal ( '11/21/2023' ) ;
141+ it ( 'formats date with config with locale' , ( ) => {
142+ const actual = format ( testDate , { type : 'day' , locale : 'de' } ) ;
143+ expect ( actual ) . equal ( '21.11.2023' ) ;
125144 } ) ;
126- it ( 'format based on value type (string)' , ( ) => {
127- const actual = format ( 'hello' ) ;
128- expect ( actual ) . equal ( 'hello' ) ;
145+
146+ it ( 'formats date with config with extra options' , ( ) => {
147+ const actual = format ( testDate , { type : 'day' , options : { variant : 'short' } } ) ;
148+ expect ( actual ) . equal ( '11/21' ) ;
129149 } ) ;
130150 } ) ;
131151} ) ;
0 commit comments