Skip to content

Commit

Permalink
Return falsy properties values (#157)
Browse files Browse the repository at this point in the history
Previously the proxy only returned truthy values for the properties
and `undefined` otherwise.
- Fix this to return the original values
  • Loading branch information
azhiv authored Feb 11, 2022
1 parent 3dae81d commit 1f4e63b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/object-tree-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const objectProxyHandler = {
return childValue;
} else if (node.content) {
const nodeContent = node.content;
if (node.safeGet(nodeContent, key)) {
if (node.safeGet(nodeContent, key) !== undefined) {
return node.safeGet(nodeContent, key);
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/utils/object-tree-node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,16 @@ describe('Unit | Utility | object tree node', () => {
expect(result.changes).toEqual({});
expect(result.proxy.foo).toBe('foo');
});

it('it returns falsy values', () => {
const result = new ObjectTreeNode({}, { name: '', flag: false, count: 0, ref: null });

expect(result.proxy.name).toBe('');
expect(result.proxy.flag).toBe(false);
expect(result.proxy.count).toBe(0);
expect(result.proxy.ref).toBe(null);

// backward compatibility - unknown properties should still resolve to undefined
expect(result.proxy.nonExistentProperty).toBe(undefined);
});
});

0 comments on commit 1f4e63b

Please sign in to comment.