Skip to content

Commit a348c24

Browse files
committed
nestedProperty: support retainNull for array get all
1 parent fa9867c commit a348c24

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/lib/nested_property.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function npGet(cont, parts) {
8787
allSame = true;
8888
out = [];
8989
for(j = 0; j < curCont.length; j++) {
90-
out[j] = npGet(curCont[j], parts.slice(i + 1))();
90+
out[j] = npGet(curCont[j], parts.slice(i + 1))(retainNull);
9191
if(out[j] !== out[0]) allSame = false;
9292
}
9393
return allSame ? out[0] : out;

test/jasmine/tests/lib_test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,12 @@ describe('Test lib.js:', function() {
340340
});
341341

342342
it('should access properties of objects in an array with index -1', function() {
343-
var obj = {arr: [{a: 1}, {a: 2}, {b: 3}]};
343+
var obj = {arr: [{a: 1}, {a: null}, {b: 3}]};
344344
var prop = np(obj, 'arr[-1].a');
345345

346-
expect(prop.get()).toEqual([1, 2, undefined]);
347-
expect(obj).toEqual({arr: [{a: 1}, {a: 2}, {b: 3}]});
346+
expect(prop.get()).toEqual([1, undefined, undefined]);
347+
expect(prop.get(true)).toEqual([1, null, undefined]);
348+
expect(obj).toEqual({arr: [{a: 1}, {a: null}, {b: 3}]});
348349

349350
prop.set(5);
350351
expect(prop.get()).toBe(5);

0 commit comments

Comments
 (0)