@@ -3,40 +3,42 @@ import formatUnit, { supportedUnits } from '../formatUnit'
33
44const locales = [ 'en' , 'fr' , 'ro' ]
55
6- const tests = [
7- ...Object . keys ( supportedUnits ) . map ( unit => [
6+ type TestType = [ string , FormatUnitOptions , string , number ]
7+
8+ const SUPPORTED_UNITS = Object . keys (
9+ supportedUnits ,
10+ ) as FormatUnitOptions [ 'unit' ] [ ]
11+
12+ const tests : TestType [ ] = [
13+ ...SUPPORTED_UNITS . map < TestType > ( unit => [
814 'should work with' ,
915 { unit } ,
1016 'fr' ,
1117 12.56 ,
1218 ] ) ,
13- ...Object . keys ( supportedUnits )
14- . map ( unit =>
15- locales . map ( locale => [
16- `should work with locale ${ locale } and` ,
17- { unit } ,
18- locale ,
19- 12.56 ,
20- ] ) ,
21- )
22- . flat ( ) ,
23- ...Object . keys ( supportedUnits )
24- . map ( unit =>
25- locales . map ( locale => [
26- `should work with long format, locale ${ locale } and` ,
27- { short : false , unit } ,
28- locale ,
29- 12.56 ,
30- ] ) ,
31- )
32- . flat ( ) ,
33- ...Object . keys ( supportedUnits ) . map ( unit => [
19+ ...SUPPORTED_UNITS . map ( unit =>
20+ locales . map < TestType > ( locale => [
21+ `should work with locale ${ locale } and` ,
22+ { unit } ,
23+ locale ,
24+ 12.56 ,
25+ ] ) ,
26+ ) . flat ( ) ,
27+ ...SUPPORTED_UNITS . map ( unit =>
28+ locales . map < TestType > ( locale => [
29+ `should work with long format, locale ${ locale } and` ,
30+ { short : false , unit } ,
31+ locale ,
32+ 12.56 ,
33+ ] ) ,
34+ ) . flat ( ) ,
35+ ...SUPPORTED_UNITS . map < TestType > ( unit => [
3436 'should work with maximumFractionDigits' ,
3537 { maximumFractionDigits : 3 , unit } ,
3638 'fr' ,
3739 12.56 ,
3840 ] ) ,
39- ...Object . keys ( supportedUnits ) . map ( unit => [
41+ ...SUPPORTED_UNITS . map < TestType > ( unit => [
4042 'should work with minimumFractionDigits' ,
4143 { minimumFractionDigits : 3 , unit } ,
4244 'fr' ,
@@ -53,12 +55,6 @@ describe('formatUnit', () => {
5355 } )
5456
5557 test . each ( tests ) ( '%s %o' , ( _ , options , locale , amount ) => {
56- expect (
57- formatUnit (
58- locale as string ,
59- amount as number ,
60- options as FormatUnitOptions ,
61- ) ,
62- ) . toMatchSnapshot ( )
58+ expect ( formatUnit ( locale , amount , options ) ) . toMatchSnapshot ( )
6359 } )
6460} )
0 commit comments