Skip to content

Commit c85b84e

Browse files
committed
update createIcon tests for new structure
1 parent faf45e4 commit c85b84e

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
import { render, screen } from '@testing-library/react';
2-
import { createIcon } from '../createIcon';
2+
import { IconDefinition, CreateIconProps, createIcon, SVGPathObject } from '../createIcon';
33

4-
const iconDef = {
4+
const multiPathIcon: IconDefinition = {
55
name: 'IconName',
66
width: 10,
77
height: 20,
8-
svgPath: 'svgPath'
8+
svgPathData: [
9+
{ path: 'svgPath1', className: 'class1' },
10+
{ path: 'svgPath2', className: 'class2' }
11+
],
12+
svgClassName: 'test'
913
};
1014

11-
const iconDefWithArrayPath = {
15+
const singlePathIcon: IconDefinition = {
1216
name: 'IconName',
1317
width: 10,
1418
height: 20,
15-
svgPath: [
16-
{ path: 'svgPath1', className: 'class1' },
17-
{ path: 'svgPath2', className: 'class2' }
18-
],
19+
svgPathData: 'svgPath',
1920
svgClassName: 'test'
2021
};
2122

23+
const iconDef: CreateIconProps = {
24+
name: 'SinglePathIconName',
25+
icon: singlePathIcon
26+
};
27+
28+
const iconDefWithArrayPath: CreateIconProps = {
29+
name: 'MultiPathIconName',
30+
icon: multiPathIcon
31+
};
32+
2233
const SVGIcon = createIcon(iconDef);
2334
const SVGArrayIcon = createIcon(iconDefWithArrayPath);
2435

2536
test('sets correct viewBox', () => {
2637
render(<SVGIcon />);
2738
expect(screen.getByRole('img', { hidden: true })).toHaveAttribute(
2839
'viewBox',
29-
`0 0 ${iconDef.width} ${iconDef.height}`
40+
`0 0 ${singlePathIcon.width} ${singlePathIcon.height}`
3041
);
3142
});
3243

@@ -39,16 +50,16 @@ test('sets correct svgPath if array', () => {
3950
render(<SVGArrayIcon />);
4051
const paths = screen.getByRole('img', { hidden: true }).querySelectorAll('path');
4152
expect(paths).toHaveLength(2);
42-
expect(paths[0]).toHaveAttribute('d', iconDefWithArrayPath.svgPath[0].path);
43-
expect(paths[1]).toHaveAttribute('d', iconDefWithArrayPath.svgPath[1].path);
44-
expect(paths[0]).toHaveClass(iconDefWithArrayPath.svgPath[0].className);
45-
expect(paths[1]).toHaveClass(iconDefWithArrayPath.svgPath[1].className);
53+
expect(paths[0]).toHaveAttribute('d', (multiPathIcon.svgPathData as SVGPathObject[])[0].path);
54+
expect(paths[1]).toHaveAttribute('d', (multiPathIcon.svgPathData as SVGPathObject[])[1].path);
55+
expect(paths[0]).toHaveClass((multiPathIcon.svgPathData as SVGPathObject[])[0].className ?? '');
56+
expect(paths[1]).toHaveClass((multiPathIcon.svgPathData as SVGPathObject[])[1].className ?? '');
4657
});
4758

4859
test('sets correct svgClassName', () => {
4960
render(<SVGArrayIcon />);
5061
const paths = screen.getByRole('img', { hidden: true });
51-
expect(paths).toHaveClass(iconDefWithArrayPath.svgClassName);
62+
expect(paths).toHaveClass(multiPathIcon.svgClassName ?? '');
5263
});
5364

5465
test('aria-hidden is true if no title is specified', () => {

packages/react-icons/src/createIcon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface IconDefinition {
1515
svgClassName?: string;
1616
}
1717

18-
export interface CreateIconProps extends IconDefinition {
18+
export interface CreateIconProps {
1919
name?: string;
2020
icon?: IconDefinition;
2121
rhUiIcon?: IconDefinition | null;

0 commit comments

Comments
 (0)