diff --git a/src/modules/list/helpers.spec.ts b/src/modules/list/helpers.spec.ts index 785bdc987..257217c1a 100644 --- a/src/modules/list/helpers.spec.ts +++ b/src/modules/list/helpers.spec.ts @@ -32,6 +32,33 @@ describe('list helpers', () => { expect(result).toBeNull(); }); + it('returns property when selector is a nested selector', () => { + let data: any = { + myResults: { nestedValue: 'expected'}, + otherResult: 'nothing' + }; + let result = getData(data, 'myResults.nestedValue'); + expect(result).toBe('expected'); + }); + + it('returns property when selector is a nested selector that does not exits', () => { + let data: any = { + myResults: {}, + otherResult: 'nothing' + }; + let result = getData(data, 'myResults.nestedValue'); + expect(result).toBeNull(); + }); + + it('returns property when selector is a nested selector that is undefined', () => { + let data: any = { + myResults: { nestedValue: undefined }, + otherResult: 'nothing' + }; + let result = getData(data, 'myResults.nestedValue'); + expect(result).toBeNull(); + }); + it('returns null when empty string selector defined', () => { let data = { myResult: 'something', diff --git a/src/modules/list/helpers.ts b/src/modules/list/helpers.ts index deb61a153..f911bcacd 100644 --- a/src/modules/list/helpers.ts +++ b/src/modules/list/helpers.ts @@ -11,11 +11,9 @@ export function getData(item: any, selector: string): any { if (resultFieldParts.length > 0) { for (let index = 0; index < resultFieldParts.length; index++) { let part = resultFieldParts[index]; - if (result[part] === undefined) { - break; - } /* tslint:disable */ - else if (result[part] === null) { + /* istanbul ignore else */ + if (result[part] === null || result[part] === undefined) { result = null; break; }