|
1 |
| -import { TranslocoPipe, TranslocoService } from '@ngneat/transloco'; |
| 1 | +import {TranslocoPipe, TranslocoScope, TranslocoService} from '@ngneat/transloco'; |
2 | 2 | import { Mock } from 'ts-mocks';
|
3 | 3 | import { ChangeDetectorRef } from '@angular/core';
|
4 | 4 | import { createService, runLoader } from '../transloco.mocks';
|
@@ -34,29 +34,29 @@ describe('TranslocoPipe', () => {
|
34 | 34 | expect(translateServiceMock.translate).toHaveBeenCalledWith('title', {}, 'es');
|
35 | 35 | }));
|
36 | 36 |
|
37 |
| - it('should load scoped translation', fakeAsync(() => { |
38 |
| - spyOn(translateServiceMock, 'translate').and.callThrough(); |
39 |
| - pipe = new TranslocoPipe(translateServiceMock, 'lazy-page', null, cdrMock); |
40 |
| - (pipe as any).listenToLangChange = true; |
41 |
| - pipe.transform('title', {}); |
42 |
| - runLoader(); |
43 |
| - expect(translateServiceMock.translate).toHaveBeenCalledWith('title', {}, 'en'); |
44 |
| - translateServiceMock.setActiveLang('es'); |
45 |
| - runLoader(); |
46 |
| - expect(translateServiceMock.translate).toHaveBeenCalledWith('title', {}, 'es'); |
47 |
| - })); |
| 37 | + describe('Scoped Translation', () => { |
| 38 | + function assertScopedTranslation(scope: TranslocoScope) { |
| 39 | + spyOn(translateServiceMock, 'translate').and.callThrough(); |
| 40 | + pipe = new TranslocoPipe(translateServiceMock, scope, null, cdrMock); |
| 41 | + translateServiceMock.config.reRenderOnLangChange = true; |
| 42 | + pipe.transform('title', {}); |
| 43 | + runLoader(); |
| 44 | + expect(translateServiceMock.translate).toHaveBeenCalledWith('title', {}, 'en'); |
| 45 | + translateServiceMock.setActiveLang('es'); |
| 46 | + runLoader(); |
| 47 | + expect(translateServiceMock.translate).toHaveBeenCalledWith('title', {}, 'es'); |
| 48 | + } |
| 49 | + |
| 50 | + it('should load scoped translation', fakeAsync(() => { |
| 51 | + assertScopedTranslation('lazy-page'); |
| 52 | + })); |
| 53 | + |
| 54 | + it('should load scoped translation with scope alias', fakeAsync(() => { |
| 55 | + assertScopedTranslation({ scope: 'lazy-scope-alias', alias: 'myScopeAlias' }); |
| 56 | + })); |
| 57 | + }) |
| 58 | + |
48 | 59 |
|
49 |
| - it('should load scoped translation with scope alias', fakeAsync(() => { |
50 |
| - spyOn(translateServiceMock, 'translate').and.callThrough(); |
51 |
| - pipe = new TranslocoPipe(translateServiceMock, { scope: 'lazy-scope-alias', alias: 'myScopeAlias' }, null, cdrMock); |
52 |
| - (pipe as any).listenToLangChange = true; |
53 |
| - pipe.transform('title', {}); |
54 |
| - runLoader(); |
55 |
| - expect(translateServiceMock.translate).toHaveBeenCalledWith('title', {}, 'en'); |
56 |
| - translateServiceMock.setActiveLang('es'); |
57 |
| - runLoader(); |
58 |
| - expect(translateServiceMock.translate).toHaveBeenCalledWith('title', {}, 'es'); |
59 |
| - })); |
60 | 60 |
|
61 | 61 | it('should load scope translation with multiple provided scopes', fakeAsync(() => {
|
62 | 62 | spyOn(translateServiceMock, 'translate').and.callThrough();
|
|
0 commit comments