Skip to content

Commit f17f417

Browse files
committed
feat(directive): add limit property
1 parent 71e5488 commit f17f417

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ describe('TranslocoDirective', () => {
5151
expect(host.queryHost('div')).toHaveText('Admin Lazy spanish');
5252
}
5353

54+
function testLimitedTranslation(host: SpectatorWithHost<TranslocoDirective, HostComponent>) {
55+
const service = host.get<TranslocoService>(TranslocoService);
56+
initScopeTest(host, service);
57+
expect(host.queryHost('div')).toHaveText('Title english');
58+
service.setActiveLang('es');
59+
runLoader();
60+
host.detectChanges();
61+
expect(host.queryHost('div')).toHaveText('Title spanish');
62+
}
63+
5464
it('should unsubscribe after one emit when not in listenToLangChange mode', fakeAsync(() => {
5565
host = createHost(`<div transloco="home"></div>`);
5666
runLoader();
@@ -185,6 +195,11 @@ describe('TranslocoDirective', () => {
185195
expect(host.queryHost('p')).toHaveText('a.b.c from list english');
186196
expect(host.queryHostAll('p')[1]).toHaveText('a.b.c value english');
187197
}));
198+
199+
it('should limit translation to a nested property', fakeAsync(() => {
200+
host = createHost(`<section *transloco="let t; limit: 'nested'"><div>{{t.title}}</div></section>`, false);
201+
testLimitedTranslation(host);
202+
}));
188203
});
189204

190205
describe('Loading Template', () => {
@@ -195,7 +210,7 @@ describe('TranslocoDirective', () => {
195210
<section *transloco="let t; scope: 'lazy-page'; loadingTpl: loading">
196211
<h1 data-cy="lazy-page">{{ t.title }}</h1>
197212
</section>
198-
213+
199214
<ng-template #loading>
200215
<h1 id="lazy-page-loading">Loading...</h1>
201216
</ng-template>
@@ -252,7 +267,7 @@ describe('TranslocoDirective', () => {
252267
<section *transloco="let t; scope: 'lazy-page'; loadingTpl: loading">
253268
<h1 data-cy="lazy-page">{{ t.title }}</h1>
254269
</section>
255-
270+
256271
<ng-template #loading>
257272
<h1 id="lazy-page-loading">Loading...</h1>
258273
</ng-template>

0 commit comments

Comments
 (0)