Skip to content

Commit 613a6b2

Browse files
committed
updates to address coderabbit comments
1 parent 94d8ad5 commit 613a6b2

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

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

Lines changed: 18 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

@@ -197,21 +195,23 @@ describe('rh-ui mapping: nested SVGs, set prop, and warnings', () => {
197195

198196
test('set="rh-ui" with no rhUiIcon mapping falls back to default and warns', () => {
199197
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
200-
const IconNoRhMapping = createIcon({
201-
name: 'NoRhMappingIcon',
202-
icon: defaultIconDef,
203-
rhUiIcon: null
204-
});
205-
206-
render(<IconNoRhMapping set="rh-ui" />);
207-
208-
expect(warnSpy).toHaveBeenCalledWith(
209-
'Set "rh-ui" was provided for NoRhMappingIcon, but no rh-ui icon data exists for this icon. The default icon will be rendered.'
210-
);
211-
const root = screen.getByRole('img', { hidden: true });
212-
expect(root.querySelector('path')).toHaveAttribute('d', defaultPath);
213-
expect(root.querySelectorAll('svg')).toHaveLength(0);
214-
215-
warnSpy.mockRestore();
198+
try {
199+
const IconNoRhMapping = createIcon({
200+
name: 'NoRhMappingIcon',
201+
icon: defaultIconDef,
202+
rhUiIcon: null
203+
});
204+
205+
render(<IconNoRhMapping set="rh-ui" />);
206+
207+
expect(warnSpy).toHaveBeenCalledWith(
208+
'Set "rh-ui" was provided for NoRhMappingIcon, but no rh-ui icon data exists for this icon. The default icon will be rendered.'
209+
);
210+
const root = screen.getByRole('img', { hidden: true });
211+
expect(root.querySelector('path')).toHaveAttribute('d', defaultPath);
212+
expect(root.querySelectorAll('svg')).toHaveLength(0);
213+
} finally {
214+
warnSpy.mockRestore();
215+
}
216216
});
217217
});

packages/react-icons/src/createIcon.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface IconDefinitionWithSvgPath extends IconDefinitionBase {
2929
/** Describes SVG path content for one icon variant (default or rh-ui). */
3030
export type IconDefinition = IconDefinitionWithSvgPathData | IconDefinitionWithSvgPath;
3131

32+
/** When passing `icon` or `rhUiIcon` keys (nested form), `icon` is required at runtime. */
3233
export interface CreateIconProps {
3334
name?: string;
3435
icon?: IconDefinition;

0 commit comments

Comments
 (0)