|
1 | 1 | import {fakeAsync, TestBed, tick} from "@angular/core/testing";
|
2 | 2 | import {Observable, of, timer, zip, defer} from "rxjs";
|
3 |
| -import {mapTo, take, toArray} from 'rxjs/operators'; |
| 3 | +import {mapTo, take, toArray, first} from 'rxjs/operators'; |
4 | 4 | import {LangChangeEvent, TranslateLoader, TranslateModule, TranslateService, TranslationChangeEvent} from '../src/public_api';
|
5 | 5 |
|
6 | 6 | let translations: any = {"TEST": "This is a test"};
|
@@ -299,6 +299,37 @@ describe('TranslateService', () => {
|
299 | 299 | translate.use('en');
|
300 | 300 | });
|
301 | 301 |
|
| 302 | + it('should update lazy streaming translations on translation change', (done: Function) => { |
| 303 | + translations = {"TEST": "This is a test"}; |
| 304 | + translate.use('en'); |
| 305 | + |
| 306 | + const translation$ = translate.getStreamOnTranslationChange('TEST'); |
| 307 | + |
| 308 | + translate.setTranslation('en', {"TEST": "This is a test2"}); |
| 309 | + |
| 310 | + translation$.pipe(first()).subscribe((res: string[]) => { |
| 311 | + const expected = "This is a test2"; |
| 312 | + expect(res).toEqual(expected); |
| 313 | + done(); |
| 314 | + }); |
| 315 | + }); |
| 316 | + |
| 317 | + it('should update lazy streaming translations on language change', (done: Function) => { |
| 318 | + translations = {"TEST": "This is a test"}; |
| 319 | + translate.use('en'); |
| 320 | + |
| 321 | + const translation$ = translate.stream('TEST'); |
| 322 | + |
| 323 | + translate.setTranslation('nl', {"TEST": "Dit is een test"}); |
| 324 | + translate.use('nl'); |
| 325 | + |
| 326 | + translation$.pipe(first()).subscribe((res: string[]) => { |
| 327 | + const expected = 'Dit is een test'; |
| 328 | + expect(res).toEqual(expected); |
| 329 | + done(); |
| 330 | + }); |
| 331 | + }); |
| 332 | + |
302 | 333 | it('should update streaming translations of an array on language change', (done: Function) => {
|
303 | 334 | const en = {"TEST": "This is a test", "TEST2": "This is a test2"};
|
304 | 335 | const nl = {"TEST": "Dit is een test", "TEST2": "Dit is een test2"};
|
|
0 commit comments