Skip to content

Commit

Permalink
fix(hub-common): fix setProp() throws error when intermediary prop is…
Browse files Browse the repository at this point in the history
… set to undefined

affects: @esri/hub-common
  • Loading branch information
tomwayson committed Dec 22, 2021
1 parent a1c2624 commit ecaf741
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/common/src/objects/deep-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function deepSet(
let worker = target;
const lastIdx = parts.length - 1;
parts.forEach((p, idx) => {
if (!worker.hasOwnProperty(p) || worker[p] === null) {
if (!worker.hasOwnProperty(p) || worker[p] == null) {
if (idx === lastIdx) {
worker[p] = value;
} else {
Expand Down
6 changes: 6 additions & 0 deletions packages/common/test/objects/set-prop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ describe("setProp", () => {
setProp(["foo", "bar"], true, obj);
expect(obj).toEqual({ foo: { bar: true } });
});

it("handles intermediary properties that are explicitly set to undefined", () => {
const obj = { foo: undefined as any };
setProp("foo.bar", true, obj);
expect(obj).toEqual({ foo: { bar: true } });
});
});

0 comments on commit ecaf741

Please sign in to comment.