@@ -3,69 +3,139 @@ var expect = require("chai").expect;
3
3
Globalize . locale ( "en" ) ;
4
4
5
5
describe ( "The compiled `basic.js`" , function ( ) {
6
- it ( "should include dateFormatter" , function ( ) {
6
+ /**
7
+ * Date
8
+ */
9
+ it ( "should include support for dateFormatter" , function ( ) {
7
10
var result = Globalize . dateFormatter ( { time : "medium" } ) ( new Date ( 2017 , 3 , 15 , 12 , 31 , 45 ) ) ;
8
11
// Note, the reason for the loose match below is due to ignore the local time zone differences.
9
12
expect ( result ) . to . have . string ( "31:45" ) ;
10
13
} ) ;
11
14
12
- it ( "should include formatDate" , function ( ) {
15
+ it ( "should include support for dateToPartsFormatter" , function ( ) {
16
+ var result = Globalize . dateToPartsFormatter ( { time : "long" } ) ( new Date ( 2017 , 3 , 15 , 10 , 17 , 37 ) ) ;
17
+ expect ( result ) . to . include ( { type : "second" , value : "37" } ) ;
18
+ } ) ;
19
+
20
+ it ( "should include support for formatDate" , function ( ) {
13
21
var result = Globalize . formatDate ( new Date ( 2017 , 3 , 15 ) , { date : "medium" } ) ;
14
22
// Note, the reason for the loose match below is due to ignore the local time zone differences.
15
23
expect ( result ) . to . have . string ( "Apr" ) ;
16
24
expect ( result ) . to . have . string ( "2017" ) ;
17
25
} ) ;
18
26
19
- it ( "should include formatDate with timeZone support" , function ( ) {
27
+ it ( "should include support for formatDate with timeZone support" , function ( ) {
20
28
var result = Globalize . formatDate ( new Date ( "2017-04-15T12:00:00Z" ) , { datetime : "full" , timeZone : "America/Sao_Paulo" } ) ;
21
29
expect ( result ) . to . equal ( "Saturday, April 15, 2017 at 9:00:00 AM Brasilia Standard Time" ) ;
22
30
} ) ;
23
31
24
- it ( "should include formatDateToParts" , function ( ) {
25
- var result = Globalize . formatDateToParts ( new Date ( 2017 , 3 , 15 ) , { datetime : "medium " } ) ;
26
- expect ( result ) . to . include ( { type : "month" , value : "Apr " } ) ;
32
+ it ( "should include support for formatDateToParts" , function ( ) {
33
+ var result = Globalize . formatDateToParts ( new Date ( 2017 , 3 , 15 ) , { date : "long " } ) ;
34
+ expect ( result ) . to . include ( { type : "month" , value : "April " } ) ;
27
35
expect ( result ) . to . include ( { type : "year" , value : "2017" } ) ;
28
36
} ) ;
29
37
30
- it ( "should include formatNumber" , function ( ) {
38
+ it ( "should include support for dateParser" , function ( ) {
39
+ var result = Globalize . dateParser ( { skeleton : "MMMd" , timeZone : "America/New_York" } ) ( "Jan 1" ) ;
40
+ expect ( result . getMonth ( ) ) . to . equal ( 0 ) ;
41
+ expect ( result . getDate ( ) ) . to . equal ( 1 ) ;
42
+ } ) ;
43
+
44
+ it ( "should include support for parseDate" , function ( ) {
45
+ var result = Globalize . parseDate ( "1/2/1982" ) ;
46
+ expect ( result . getFullYear ( ) ) . to . equal ( 1982 ) ;
47
+ expect ( result . getMonth ( ) ) . to . equal ( 0 ) ;
48
+ expect ( result . getDate ( ) ) . to . equal ( 2 ) ;
49
+ } ) ;
50
+
51
+ it ( "should include support for parseDate with timeZone support" , function ( ) {
52
+ var result = Globalize . parseDate ( "January 1, 2000 at 12:00:00 AM EST" , { datetime : "long" , timeZone : "America/New_York" } ) ;
53
+ expect ( result ) . to . deep . equal ( new Date ( "2000-01-01T05:00:00Z" ) ) ;
54
+ } ) ;
55
+
56
+ /**
57
+ * Number
58
+ */
59
+ it ( "should include support for numberFormatter" , function ( ) {
60
+ var result = Globalize . numberFormatter ( { minimumFractionDigits : 0 , maximumFractionDigits : 10 } ) ( Math . PI ) ;
61
+ expect ( result ) . to . equal ( "3.1415926536" ) ;
62
+ } ) ;
63
+
64
+ it ( "should include support for formatNumber" , function ( ) {
31
65
var result = Globalize . formatNumber ( Math . PI ) ;
32
66
expect ( result ) . to . equal ( "3.142" ) ;
33
67
} ) ;
34
68
35
- it ( "should include formatCurrency" , function ( ) {
69
+ it ( "should include support for parseNumber" , function ( ) {
70
+ var result = Globalize . parseNumber ( "1,234.56" ) ;
71
+ expect ( result ) . to . equal ( 1234.56 ) ;
72
+ } ) ;
73
+
74
+ /**
75
+ * Currency
76
+ */
77
+ it ( "should include support for currencyFormatter" , function ( ) {
78
+ var result = Globalize . currencyFormatter ( "EUR" ) ( 9.99 ) ;
79
+ expect ( result ) . to . equal ( "€9.99" ) ;
80
+ } ) ;
81
+
82
+ it ( "should include support for formatCurrency" , function ( ) {
36
83
var result = Globalize . formatCurrency ( 69900 , "USD" ) ;
37
84
expect ( result ) . to . equal ( "$69,900.00" ) ;
38
85
} ) ;
39
86
40
- it ( "should include formatMessage" , function ( ) {
87
+ /**
88
+ * Message
89
+ */
90
+ it ( "should include support for pluralGenerator" , function ( ) {
91
+ var result = Globalize . pluralGenerator ( { type : "ordinal" } ) ( 2 ) ;
92
+ expect ( result ) . to . equal ( "two" ) ;
93
+ } ) ;
94
+
95
+ it ( "should include support for plural" , function ( ) {
96
+ var result = Globalize . plural ( 5 ) ;
97
+ expect ( result ) . to . equal ( "other" ) ;
98
+ } ) ;
99
+
100
+ it ( "should include support for messageFormatter" , function ( ) {
101
+ var result = Globalize . messageFormatter ( "task" ) ( { count : 1000 , formattedCount : "1,000" } ) ;
102
+ expect ( result ) . to . equal ( "You have 1,000 tasks remaining" ) ;
103
+ } ) ;
104
+
105
+ it ( "should include support for formatMessage" , function ( ) {
41
106
var result = Globalize . formatMessage ( "like" , 0 ) ;
42
107
expect ( result ) . to . equal ( "Be the first to like this" ) ;
43
108
} ) ;
44
109
45
- it ( "should include formatRelativeTime" , function ( ) {
46
- var result = Globalize . formatRelativeTime ( 1 , "second" ) ;
47
- expect ( result ) . to . equal ( "in 1 second" ) ;
48
- } ) ;
110
+ /**
111
+ * Relative Time
112
+ */
49
113
50
- it ( "should include formatUnit" , function ( ) {
51
- var result = Globalize . formatUnit ( 60 , "mile/hour" , { form : "short" } ) ;
52
- expect ( result ) . to . equal ( "60 mph" ) ;
114
+ // Use relativeTimeFormatter.
115
+ it ( "should include support for relativeTimeFormatter" , function ( ) {
116
+ var result = Globalize . relativeTimeFormatter ( "day" ) ( 0 ) ;
117
+ expect ( result ) . to . equal ( "today" ) ;
53
118
} ) ;
54
119
55
- it ( "should include parseNumber" , function ( ) {
56
- var result = Globalize . parseNumber ( "1,234.56" ) ;
57
- expect ( result ) . to . equal ( 1234.56 ) ;
120
+ // Use formatRelativeTime.
121
+ it ( "should include support for formatRelativeTime" , function ( ) {
122
+ var result = Globalize . formatRelativeTime ( 1 , "second" ) ;
123
+ expect ( result ) . to . equal ( "in 1 second" ) ;
58
124
} ) ;
59
125
60
- it ( "should include parseDate" , function ( ) {
61
- var result = Globalize . parseDate ( "1/2/1982" ) ;
62
- expect ( result . getFullYear ( ) ) . to . equal ( 1982 ) ;
63
- expect ( result . getMonth ( ) ) . to . equal ( 0 ) ;
64
- expect ( result . getDate ( ) ) . to . equal ( 2 ) ;
126
+ /**
127
+ * Unit
128
+ */
129
+
130
+ // Use unitFormatter.
131
+ it ( "should include support for unitFormatter" , function ( ) {
132
+ var result = Globalize . unitFormatter ( "kilowatt" ) ( 120 ) ;
133
+ expect ( result ) . to . equal ( "120 kilowatts" ) ;
65
134
} ) ;
66
135
67
- it ( "should include parseDate with timeZone support" , function ( ) {
68
- var result = Globalize . parseDate ( "January 1, 2000 at 12:00:00 AM EST" , { datetime : "long" , timeZone : "America/New_York" } ) ;
69
- expect ( result ) . to . deep . equal ( new Date ( "2000-01-01T05:00:00Z" ) ) ;
136
+ // Use formatUnit.
137
+ it ( "should include support for formatUnit" , function ( ) {
138
+ var result = Globalize . formatUnit ( 60 , "mile/hour" , { form : "short" } ) ;
139
+ expect ( result ) . to . equal ( "60 mph" ) ;
70
140
} ) ;
71
141
} ) ;
0 commit comments