Skip to content

Commit eba0bb6

Browse files
author
Erik Rasmussen
committed
Add test coverage for getter-only property scenario
- Test that component prop doesn't overwrite getter-only properties - Test all render paths (component, render, children) handle getters correctly - Reproduces and validates fix for issue #1055 - Ensures 100% coverage for the fix
1 parent e275b67 commit eba0bb6

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

src/renderComponent.test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,63 @@ describe("renderComponent", () => {
6969
expect(getA).not.toHaveBeenCalled();
7070
expect(getB).not.toHaveBeenCalled();
7171
});
72+
73+
it("should not overwrite getter-only properties when using component prop", () => {
74+
// This test reproduces issue #1055
75+
// When lazyProps has getter-only properties (like 'active'), and props contains
76+
// a property with the same name, it should not attempt to overwrite the getter
77+
const Component = jest.fn(() => null);
78+
const props = {
79+
component: Component,
80+
active: "value-from-props", // This would cause "Cannot set property active" error
81+
customProp: "custom",
82+
};
83+
const lazyProps = {};
84+
Object.defineProperty(lazyProps, "active", {
85+
get: () => "value-from-getter",
86+
enumerable: true,
87+
// Note: no setter - this is getter-only
88+
});
89+
const name = "TestComponent";
90+
91+
// Should not throw "Cannot set property active"
92+
expect(() => renderComponent(props, lazyProps, name)).not.toThrow();
93+
94+
expect(Component).toHaveBeenCalled();
95+
const componentProps = Component.mock.calls[0][0];
96+
97+
// The getter-only property should remain and use the getter value
98+
expect(componentProps.active).toBe("value-from-getter");
99+
100+
// Custom props should still be passed through
101+
expect(componentProps.customProp).toBe("custom");
102+
});
103+
104+
it("should handle getter-only properties in all render paths", () => {
105+
// Test with render prop
106+
const render = jest.fn();
107+
const lazyProps = {};
108+
Object.defineProperty(lazyProps, "active", {
109+
get: () => "getter-value",
110+
enumerable: true,
111+
});
112+
113+
renderComponent(
114+
{ render, active: "prop-value" },
115+
lazyProps,
116+
"TestComponent",
117+
);
118+
expect(render).toHaveBeenCalled();
119+
expect(render.mock.calls[0][0].active).toBe("getter-value");
120+
121+
// Test with children function
122+
const children = jest.fn();
123+
renderComponent(
124+
{ children, active: "prop-value" },
125+
lazyProps,
126+
"TestComponent",
127+
);
128+
expect(children).toHaveBeenCalled();
129+
expect(children.mock.calls[0][0].active).toBe("getter-value");
130+
});
72131
});

0 commit comments

Comments
 (0)