Skip to content

Commit

Permalink
fix(utils): ignore undefined values
Browse files Browse the repository at this point in the history
  • Loading branch information
juanrgm committed May 14, 2023
1 parent bf8a632 commit 4272269
Showing 4 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/witty-pigs-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@suid/utils": patch
---

Ignore undefined values in `merge` function
15 changes: 15 additions & 0 deletions packages/system/test/styled.test.tsx
Original file line number Diff line number Diff line change
@@ -47,6 +47,21 @@ describe("styled", () => {
expect(styles.marginTop).toBe("1px");
unmount();
});
it("ignores undefined values", () => {
const Div = styled("div")(
{
color: "blue",
},
{
color: undefined,
}
);
const { unmount } = render(() => <Div data-testid="e" />);
const e = screen.getByTestId("e");
const styles = window.getComputedStyle(e);
expect(styles.color).toBe("blue");
unmount();
});
it("creates styled function component", () => {
function Component(props: any) {
return <Box {...props} />;
2 changes: 1 addition & 1 deletion packages/utils/src/deepmerge.ts
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ export default function deepmerge<T>(
sourceValue,
options
);
} else {
} else if (sourceValue !== undefined) {
(output as Record<keyof any, unknown>)[key] = sourceValue;
}
});
13 changes: 13 additions & 0 deletions packages/utils/test/merge.test.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,19 @@ describe("merge", () => {
expect(object).toMatchObject({ a: 1, b: 2 });
});

it("ignores undefined values", () => {
const object = merge(
{ a: 1, b: 2, c: { d: 3 }, e: { f: 4 } },
{ a: undefined, b: undefined, c: undefined, e: { f: undefined, g: 5 } }
);
expect(object).toMatchObject({
a: 1,
b: 2,
c: { d: 3 },
e: { f: 4, g: 5 },
});
});

it("shoulds not alter the others object", () => {
const a = { a: 1 };
const b = { b: 1 };

0 comments on commit 4272269

Please sign in to comment.