Skip to content

Commit 94d8ad5

Browse files
committed
updates to address coderabbit comments
1 parent 764d78b commit 94d8ad5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/react-icons/src/__tests__/createIcon.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ test('accepts CreateIconProps with nested icon using deprecated svgPath field',
7878
expect(screen.getByRole('img', { hidden: true }).querySelector('path')).toHaveAttribute('d', 'nested-legacy-d');
7979
});
8080

81+
test('throws when nested CreateIconProps omits icon', () => {
82+
expect(() =>
83+
createIcon({
84+
name: 'MissingDefaultIcon',
85+
rhUiIcon: null
86+
})
87+
).toThrow(
88+
'@patternfly/react-icons: createIcon requires an `icon` definition when using nested CreateIconProps (name: MissingDefaultIcon).'
89+
);
90+
});
91+
8192
test('sets correct svgPath if array', () => {
8293
render(<SVGArrayIcon />);
8394
const paths = screen.getByRole('img', { hidden: true }).querySelectorAll('path');

packages/react-icons/src/createIcon.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,15 @@ interface NormalizedCreateIconProps {
8686
function normalizeCreateIconArg(arg: CreateIconProps | LegacyFlatIconDefinition): NormalizedCreateIconProps {
8787
if (isNestedCreateIconProps(arg)) {
8888
const p = arg as CreateIconProps;
89+
if (p.icon == null) {
90+
const label = p.name != null ? ` (name: ${String(p.name)})` : '';
91+
throw new Error(
92+
`@patternfly/react-icons: createIcon requires an \`icon\` definition when using nested CreateIconProps${label}.`
93+
);
94+
}
8995
return {
9096
name: p.name,
91-
icon: p.icon !== undefined && p.icon !== null ? normalizeIconDefinition(p.icon) : undefined,
97+
icon: normalizeIconDefinition(p.icon),
9298
rhUiIcon: p.rhUiIcon != null ? normalizeIconDefinition(p.rhUiIcon) : null
9399
};
94100
}

0 commit comments

Comments
 (0)