Skip to content

Commit

Permalink
Adds a test checking that we handle empty string styles
Browse files Browse the repository at this point in the history
This adds a test for the fix for #79 - while that situation can appear in more situations than the one tested here (nodes being detached from the DOM, etc), it at least manifests in our test environment if we don't apply any styling to the parent node.

Relates to #80, so if there is a decision to change the behavior, there is at least a test of _some_ kind
  • Loading branch information
saperdadsk committed Feb 23, 2024
1 parent 323d599 commit 618e504
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/AutoSizer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe("AutoSizer", () => {
paddingRight = 0,
paddingTop = 0,
width = 200,
excludeWrapperStyling = false,
} = {},
props: Omit<Props, "children"> = {}
) {
Expand All @@ -110,7 +111,7 @@ describe("AutoSizer", () => {
const root = createRoot(container);
act(() => {
root.render(
<div style={wrapperStyle}>
<div style={!excludeWrapperStyling ? wrapperStyle : undefined}>
<AutoSizer
disableHeight={disableHeight as any}
disableWidth={disableWidth as any}
Expand Down Expand Up @@ -144,6 +145,18 @@ describe("AutoSizer", () => {
expect(container.textContent).toContain("width:200");
});

it("should not render children for elements with empty computed styles", () => {
mockOffsetSize(0, 0);

renderHelper({
excludeWrapperStyling: true,
height: 0,
width: 0,
});

expect(container.textContent).toEqual("");
});

it("should account for padding when calculating the available width and height", () => {
renderHelper({
paddingBottom: 10,
Expand Down

0 comments on commit 618e504

Please sign in to comment.