From 1f4e63b07eec2477dc27d146bf2f3b8fc20a0175 Mon Sep 17 00:00:00 2001 From: Artem Zhivoderov <32125472+azhiv@users.noreply.github.com> Date: Fri, 11 Feb 2022 17:21:59 +0300 Subject: [PATCH] Return falsy properties values (#157) Previously the proxy only returned truthy values for the properties and `undefined` otherwise. - Fix this to return the original values --- src/utils/object-tree-node.ts | 2 +- test/utils/object-tree-node.test.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/utils/object-tree-node.ts b/src/utils/object-tree-node.ts index 03ffb50..5951d11 100644 --- a/src/utils/object-tree-node.ts +++ b/src/utils/object-tree-node.ts @@ -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); } } diff --git a/test/utils/object-tree-node.test.ts b/test/utils/object-tree-node.test.ts index 8c9f5c7..f5f972a 100644 --- a/test/utils/object-tree-node.test.ts +++ b/test/utils/object-tree-node.test.ts @@ -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); + }); });