@@ -140,15 +140,7 @@ describe('MultiTranslateHttpLoader - Multiple Translation Files', () => {
140
140
it ( 'should be able to get translations from multiple files' , ( ) => {
141
141
translate . use ( 'en' ) ;
142
142
143
- // this will request the translation from the backend because we use a static files loader for TranslateService
144
- translate . get ( 'TEST' ) . subscribe ( ( res : string ) => {
145
- expect ( res ) . toEqual ( 'This is a test (core)' ) ;
146
- } ) ;
147
- translate . get ( 'TEST-SHARED' ) . subscribe ( ( res : string ) => {
148
- expect ( res ) . toEqual ( 'This is a test (shared)' ) ;
149
- } ) ;
150
-
151
- // mock response after the xhr request, otherwise it will be undefined
143
+ // mock response, otherwise it will be undefined
152
144
http . expectOne ( '/assets/i18n/core/en.json' ) . flush ( {
153
145
"TEST" : "This is a test (core)" ,
154
146
"TEST2" : "This is another test (core)" ,
@@ -164,18 +156,30 @@ describe('MultiTranslateHttpLoader - Multiple Translation Files', () => {
164
156
}
165
157
} ) ;
166
158
167
- // this will request the translation from downloaded translations without making a request to the backend
168
- translate . get ( 'TEST2' ) . subscribe ( ( res : string ) => {
169
- expect ( res ) . toEqual ( 'This is another test (core)' ) ;
170
- } ) ;
171
- translate . get ( 'TEST2-SHARED' ) . subscribe ( ( res : string ) => {
172
- expect ( res ) . toEqual ( 'This is another test (shared)' ) ;
159
+ expect ( translate . instant ( 'TEST2' ) ) . toEqual ( 'This is another test (core)' ) ;
160
+ expect ( translate . instant ( 'TEST2-SHARED' ) ) . toEqual ( 'This is another test (shared)' ) ;
161
+ expect ( translate . instant ( 'DEEP' ) ) . toEqual ( {
162
+ "some" : "thing" ,
163
+ "another" : "something"
173
164
} ) ;
174
- translate . get ( 'DEEP' ) . subscribe ( ( res : any ) => {
175
- expect ( res ) . toEqual ( {
176
- "some" : "thing" ,
177
- "another" : "something"
178
- } ) ;
165
+ } ) ;
166
+
167
+ it ( 'should be able to get translations from multiple files even if some are missing' , ( ) => {
168
+ translate . use ( 'en' ) ;
169
+
170
+ // mock response, otherwise it will be undefined
171
+ http . expectOne ( '/assets/i18n/core/en.json' ) . flush ( {
172
+ "TEST" : "This is a test (core)" ,
173
+ "TEST2" : "This is another test (core)" ,
174
+ "DEEP" : {
175
+ "some" : "thing"
176
+ }
179
177
} ) ;
178
+ http . expectOne ( '/assets/i18n/shared/en.json' ) . error ( new ErrorEvent ( 'network error' ) ) ;
179
+
180
+ expect ( translate . instant ( 'TEST' ) ) . toEqual ( 'This is a test (core)' ) ;
181
+ expect ( translate . instant ( 'TEST2' ) ) . toEqual ( 'This is another test (core)' ) ;
182
+ expect ( translate . instant ( 'TEST-SHARED' ) ) . toEqual ( 'TEST-SHARED' ) ;
183
+ expect ( translate . instant ( 'TEST2-SHARED' ) ) . toEqual ( 'TEST2-SHARED' ) ;
180
184
} ) ;
181
185
} ) ;
0 commit comments