Skip to content

Commit

Permalink
fix(pipe): handle non string input (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Rolheiser authored and ocombe committed Feb 5, 2020
1 parent 3e0aebb commit 9ff74dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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 @@ -37,7 +37,7 @@ export class TranslatePipe implements PipeTransform, OnDestroy {
}

transform(query: string, ...args: any[]): any {
if (!query || query.length === 0) {
if (!query || !query.length) {
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

0 comments on commit 9ff74dc

Please sign in to comment.