Skip to content

Commit 3b78c3a

Browse files
committed
fix(core): Tools.getProperty did return 'null' for falsy values, now returns the actual values
1 parent 86d11e8 commit 3b78c3a

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

Diff for: packages/core/src/tools.spec.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Tools } from "./tools";
2+
3+
describe("Tools.getProperty", () => {
4+
it("works with a simple nested object containing a number > 0", () => {
5+
const obj = { a: { b: { c: 5 } } };
6+
7+
expect(Tools.getProperty(obj, "a", "b", "c")).toEqual(5);
8+
});
9+
10+
it("works with a simple nested object containing a 0", () => {
11+
const obj = { a: { b: { c: 0 } } };
12+
13+
expect(Tools.getProperty(obj, "a", "b", "c")).toEqual(0);
14+
});
15+
16+
it("works with a simple nested object containing `false`", () => {
17+
const obj = { a: { b: { c: false } } };
18+
19+
expect(Tools.getProperty(obj, "a", "b", "c")).toEqual(false);
20+
});
21+
22+
it("works with a simple nested object containing `true`", () => {
23+
const obj = { a: { b: { c: true } } };
24+
25+
expect(Tools.getProperty(obj, "a", "b", "c")).toEqual(true);
26+
});
27+
28+
it("works with a simple nested object containing a string", () => {
29+
const obj = { a: { b: { c: "qwerty" } } };
30+
31+
expect(Tools.getProperty(obj, "a", "b", "c")).toEqual("qwerty");
32+
});
33+
34+
it("works with a simple nested object containing an empty string", () => {
35+
const obj = { a: { b: { c: "" } } };
36+
37+
expect(Tools.getProperty(obj, "a", "b", "c")).toEqual("");
38+
});
39+
});

Diff for: packages/core/src/tools.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export namespace Tools {
183183
let position = object;
184184
if (position) {
185185
for (const prop of propPath) {
186-
if (position[prop]) {
186+
if (position[prop] !== null && position[prop] !== undefined) {
187187
position = position[prop];
188188
} else {
189189
return null;

0 commit comments

Comments
 (0)