@@ -8,7 +8,10 @@ describe('IntlCurrencyPipe', () => {
8
8
9
9
describe ( 'parsing' , ( ) => {
10
10
beforeEach ( ( ) => {
11
- testUnit = new IntlCurrencyPipe ( 'en-US' ) ;
11
+ TestBed . runInInjectionContext ( ( ) => {
12
+ testUnit = new IntlCurrencyPipe ( ) ;
13
+ Object . defineProperty ( testUnit , 'locale' , { value : 'en-US' } ) ;
14
+ } ) ;
12
15
} ) ;
13
16
14
17
it ( 'should create an instance' , ( ) => {
@@ -53,29 +56,34 @@ describe('IntlCurrencyPipe', () => {
53
56
it ( 'should respect the set locale' , ( ) => {
54
57
TestBed . configureTestingModule ( {
55
58
providers : [
56
- IntlCurrencyPipe ,
57
59
{
58
60
provide : INTL_LOCALES ,
59
61
useValue : 'de-DE' ,
60
62
} ,
61
63
] ,
62
64
} ) ;
63
- testUnit = TestBed . inject ( IntlCurrencyPipe ) ;
65
+ TestBed . runInInjectionContext ( ( ) => ( testUnit = new IntlCurrencyPipe ( ) ) ) ;
64
66
65
67
expect ( testUnit . transform ( 1024.2249 , 'EUR' ) ) . toEqual ( '1.024,22\xa0€' ) ;
66
68
} ) ;
67
69
68
70
it ( 'should fall back to the browser default locale' , ( ) => {
69
- TestBed . configureTestingModule ( { providers : [ IntlCurrencyPipe ] } ) ;
71
+ let defaultLanguageTestUnit ! : IntlCurrencyPipe ;
72
+ let browserLanguageTestUnit ! : IntlCurrencyPipe ;
73
+
74
+ TestBed . runInInjectionContext ( ( ) => {
75
+ defaultLanguageTestUnit = new IntlCurrencyPipe ( ) ;
76
+ browserLanguageTestUnit = new IntlCurrencyPipe ( ) ;
77
+ Object . defineProperty ( browserLanguageTestUnit , 'locale' , {
78
+ value : undefined ,
79
+ } ) ;
80
+ Object . defineProperty ( defaultLanguageTestUnit , 'locale' , {
81
+ value : navigator . language ,
82
+ } ) ;
83
+ } ) ;
70
84
71
- const result1 = TestBed . inject ( IntlCurrencyPipe ) . transform (
72
- 1024.2249 ,
73
- 'EUR' ,
74
- ) ;
75
- const result2 = new IntlCurrencyPipe ( navigator . language ) . transform (
76
- 1024.2249 ,
77
- 'EUR' ,
78
- ) ;
85
+ const result1 = browserLanguageTestUnit . transform ( 1024.2249 , 'EUR' ) ;
86
+ const result2 = defaultLanguageTestUnit . transform ( 1024.2249 , 'EUR' ) ;
79
87
80
88
expect ( result1 ) . toEqual ( result2 ) ;
81
89
} ) ;
@@ -85,7 +93,6 @@ describe('IntlCurrencyPipe', () => {
85
93
it ( 'should respect the setting from default config' , ( ) => {
86
94
TestBed . configureTestingModule ( {
87
95
providers : [
88
- IntlCurrencyPipe ,
89
96
{
90
97
provide : INTL_LOCALES ,
91
98
useValue : 'en-US' ,
@@ -98,15 +105,14 @@ describe('IntlCurrencyPipe', () => {
98
105
} ,
99
106
] ,
100
107
} ) ;
101
- testUnit = TestBed . inject ( IntlCurrencyPipe ) ;
108
+ TestBed . runInInjectionContext ( ( ) => ( testUnit = new IntlCurrencyPipe ( ) ) ) ;
102
109
103
110
expect ( testUnit . transform ( 1 , 'USD' ) ) . toEqual ( '+$1.00' ) ;
104
111
} ) ;
105
112
106
113
it ( 'should give the user options a higher priority' , ( ) => {
107
114
TestBed . configureTestingModule ( {
108
115
providers : [
109
- IntlCurrencyPipe ,
110
116
{
111
117
provide : INTL_LOCALES ,
112
118
useValue : 'en-US' ,
@@ -119,7 +125,7 @@ describe('IntlCurrencyPipe', () => {
119
125
} ,
120
126
] ,
121
127
} ) ;
122
- testUnit = TestBed . inject ( IntlCurrencyPipe ) ;
128
+ TestBed . runInInjectionContext ( ( ) => ( testUnit = new IntlCurrencyPipe ( ) ) ) ;
123
129
124
130
expect ( testUnit . transform ( 1 , 'USD' , { signDisplay : 'never' } ) ) . toEqual (
125
131
'$1.00' ,
@@ -130,14 +136,13 @@ describe('IntlCurrencyPipe', () => {
130
136
it ( 'should respect locale option' , ( ) => {
131
137
TestBed . configureTestingModule ( {
132
138
providers : [
133
- IntlCurrencyPipe ,
134
139
{
135
140
provide : INTL_LOCALES ,
136
141
useValue : 'en-US' ,
137
142
} ,
138
143
] ,
139
144
} ) ;
140
- testUnit = TestBed . inject ( IntlCurrencyPipe ) ;
145
+ TestBed . runInInjectionContext ( ( ) => ( testUnit = new IntlCurrencyPipe ( ) ) ) ;
141
146
142
147
expect ( testUnit . transform ( 1024 , 'USD' , { locale : 'de-DE' } ) ) . toEqual (
143
148
'1.024,00\xa0$' ,
@@ -147,7 +152,6 @@ describe('IntlCurrencyPipe', () => {
147
152
it ( 'should not override the style option' , ( ) => {
148
153
TestBed . configureTestingModule ( {
149
154
providers : [
150
- IntlCurrencyPipe ,
151
155
{
152
156
provide : INTL_LOCALES ,
153
157
useValue : 'en-US' ,
@@ -160,7 +164,7 @@ describe('IntlCurrencyPipe', () => {
160
164
} ,
161
165
] ,
162
166
} ) ;
163
- testUnit = TestBed . inject ( IntlCurrencyPipe ) ;
167
+ TestBed . runInInjectionContext ( ( ) => ( testUnit = new IntlCurrencyPipe ( ) ) ) ;
164
168
165
169
expect ( testUnit . transform ( 1 , 'USD' , { style : 'percent' } ) ) . toEqual ( '$1.00' ) ;
166
170
} ) ;
0 commit comments