Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TranslatePipe): handle non string input #893

Merged
merged 1 commit into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion projects/ngx-translate/core/src/lib/translate.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class TranslatePipe implements PipeTransform, OnDestroy {
}

transform(query: string, ...args: any[]): any {
if (!query || query.length === 0) {
if (!query || !query.length) {
jrolheiser marked this conversation as resolved.
Show resolved Hide resolved
return query;
}

Expand Down
9 changes: 9 additions & 0 deletions projects/ngx-translate/core/tests/translate.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ describe('TranslatePipe', () => {
}).toThrowError(`Wrong parameter in TranslatePipe. Expected a valid Object, received: ${param}`);
});

it("should return given falsey or non length query", () => {
translate.setTranslation('en', {"TEST": "This is a test"});
translate.use('en');

expect(translatePipe.transform(null)).toBeNull();
expect(translatePipe.transform(undefined)).toBeUndefined();
expect(translatePipe.transform(1234 as any)).toBe(1234);
});

describe('should update translations on lang change', () => {
it('with fake loader', (done) => {
translate.setTranslation('en', {"TEST": "This is a test"});
Expand Down