Skip to content

Commit 43f8d0b

Browse files
committed
updates to address coderabbit comments
1 parent c6580be commit 43f8d0b

1 file changed

Lines changed: 29 additions & 18 deletions

File tree

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

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// eslint-disable-next-line no-restricted-imports -- test file excluded from package tsconfig; default import satisfies TS/JSX
2-
import React from 'react';
31
import { render, screen } from '@testing-library/react';
42
import { IconDefinition, CreateIconProps, createIcon, LegacyFlatIconDefinition, SVGPathObject } from '../createIcon';
53

@@ -107,6 +105,17 @@ test('does not set svgClassName when noDefaultStyle is true', () => {
107105
expect(screen.getByRole('img', { hidden: true })).not.toHaveClass('pf-v6-icon-rh-standard');
108106
});
109107

108+
test('throws when nested CreateIconProps omits icon', () => {
109+
expect(() =>
110+
createIcon({
111+
name: 'MissingDefaultIcon',
112+
rhUiIcon: null
113+
})
114+
).toThrow(
115+
'@patternfly/react-icons: createIcon requires an `icon` definition when using nested CreateIconProps (name: MissingDefaultIcon).'
116+
);
117+
});
118+
110119
test('sets correct svgPath if array', () => {
111120
render(<SVGArrayIcon />);
112121
const paths = screen.getByRole('img', { hidden: true }).querySelectorAll('path');
@@ -215,21 +224,23 @@ describe('rh-ui mapping: nested SVGs, set prop, and warnings', () => {
215224

216225
test('set="rh-ui" with no rhUiIcon mapping falls back to default and warns', () => {
217226
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
218-
const IconNoRhMapping = createIcon({
219-
name: 'NoRhMappingIcon',
220-
icon: defaultIconDef,
221-
rhUiIcon: null
222-
});
223-
224-
render(<IconNoRhMapping set="rh-ui" />);
225-
226-
expect(warnSpy).toHaveBeenCalledWith(
227-
'Set "rh-ui" was provided for NoRhMappingIcon, but no rh-ui icon data exists for this icon. The default icon will be rendered.'
228-
);
229-
const root = screen.getByRole('img', { hidden: true });
230-
expect(root.querySelector('path')).toHaveAttribute('d', defaultPath);
231-
expect(root.querySelectorAll('svg')).toHaveLength(0);
232-
233-
warnSpy.mockRestore();
227+
try {
228+
const IconNoRhMapping = createIcon({
229+
name: 'NoRhMappingIcon',
230+
icon: defaultIconDef,
231+
rhUiIcon: null
232+
});
233+
234+
render(<IconNoRhMapping set="rh-ui" />);
235+
236+
expect(warnSpy).toHaveBeenCalledWith(
237+
'Set "rh-ui" was provided for NoRhMappingIcon, but no rh-ui icon data exists for this icon. The default icon will be rendered.'
238+
);
239+
const root = screen.getByRole('img', { hidden: true });
240+
expect(root.querySelector('path')).toHaveAttribute('d', defaultPath);
241+
expect(root.querySelectorAll('svg')).toHaveLength(0);
242+
} finally {
243+
warnSpy.mockRestore();
244+
}
234245
});
235246
});

0 commit comments

Comments
 (0)