|
1 | | -// eslint-disable-next-line no-restricted-imports -- test file excluded from package tsconfig; default import satisfies TS/JSX |
2 | | -import React from 'react'; |
3 | 1 | import { render, screen } from '@testing-library/react'; |
4 | 2 | import { IconDefinition, CreateIconProps, createIcon, LegacyFlatIconDefinition, SVGPathObject } from '../createIcon'; |
5 | 3 |
|
@@ -107,6 +105,17 @@ test('does not set svgClassName when noDefaultStyle is true', () => { |
107 | 105 | expect(screen.getByRole('img', { hidden: true })).not.toHaveClass('pf-v6-icon-rh-standard'); |
108 | 106 | }); |
109 | 107 |
|
| 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 | + |
110 | 119 | test('sets correct svgPath if array', () => { |
111 | 120 | render(<SVGArrayIcon />); |
112 | 121 | const paths = screen.getByRole('img', { hidden: true }).querySelectorAll('path'); |
@@ -215,21 +224,23 @@ describe('rh-ui mapping: nested SVGs, set prop, and warnings', () => { |
215 | 224 |
|
216 | 225 | test('set="rh-ui" with no rhUiIcon mapping falls back to default and warns', () => { |
217 | 226 | 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 | + } |
234 | 245 | }); |
235 | 246 | }); |
0 commit comments