Skip to content

Commit 10c4e25

Browse files
committed
test: 💍 fix pipe tests
1 parent 2d9d0a0 commit 10c4e25

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

projects/ngneat/transloco/src/lib/tests/pipe/pipe.spec.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TranslocoPipe, TranslocoService } from '@ngneat/transloco';
1+
import {TranslocoPipe, TranslocoScope, TranslocoService} from '@ngneat/transloco';
22
import { Mock } from 'ts-mocks';
33
import { ChangeDetectorRef } from '@angular/core';
44
import { createService, runLoader } from '../transloco.mocks';
@@ -34,29 +34,29 @@ describe('TranslocoPipe', () => {
3434
expect(translateServiceMock.translate).toHaveBeenCalledWith('title', {}, 'es');
3535
}));
3636

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+
4859

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-
}));
6060

6161
it('should load scope translation with multiple provided scopes', fakeAsync(() => {
6262
spyOn(translateServiceMock, 'translate').and.callThrough();

0 commit comments

Comments
 (0)