Skip to content

Commit

Permalink
Merge pull request #68 from VadimDez/feature/#67
Browse files Browse the repository at this point in the history
fix filter when nested object is null, fixes #67
  • Loading branch information
VadimDez authored Sep 18, 2018
2 parents 1b73069 + 14d1ae9 commit 10d925a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/app/shared/ngx-filter-pipe/ngx-filter.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ describe('Pipe: FilterPipe', () => {
.toEqual([{ value: 'abc', nested: { number: 2 } }]);
});

it('filters array of objects with nested objects', () => {
const array = [
{ nested: { number: 1 } },
{ nested: { number: 2 } },
{ nested: null }
];
const filter = { nested: { number: 2 } };
const result = [{ nested: { number: 2 } }];

expect(pipe.transform(array, filter)).toEqual(result);
});

it('filters array of objects with nested objects (not every object has nested object)', () => {
expect(pipe.transform([
{ value: 'a' },
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/ngx-filter-pipe/ngx-filter.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class FilterPipe implements PipeTransform {
continue;
}

if (!FilterPipe.isFoundOnWalking(value, key)) {
if (!value || !FilterPipe.isFoundOnWalking(value, key)) {
return false;
}

Expand Down

0 comments on commit 10d925a

Please sign in to comment.