|
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 |
|
@@ -197,21 +195,23 @@ describe('rh-ui mapping: nested SVGs, set prop, and warnings', () => { |
197 | 195 |
|
198 | 196 | test('set="rh-ui" with no rhUiIcon mapping falls back to default and warns', () => { |
199 | 197 | 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 | + } |
216 | 216 | }); |
217 | 217 | }); |
0 commit comments