Skip to content

Commit 09fbe6c

Browse files
committed
add test coverage for union type props
Signed-off-by: Winner95 <Winner95@users.noreply.github.com>
1 parent 9b4d29e commit 09fbe6c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

__tests__/handler.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ describe('typescript-react-function-component-props-handler', () => {
5959
);
6060
});
6161

62+
test('handles React.FC<Props> components with union type props', () => {
63+
const doc = parseFixture('Icon.tsx');
64+
65+
expect(doc.props).toHaveProperty('size');
66+
expect(doc.props.size.tsType).toMatchObject({ name: 'union' });
67+
expect(doc.props.size.tsType).toHaveProperty('raw');
68+
expect(doc.props.size.tsType.raw).toBe("'small' | 'medium' | 'big'");
69+
});
70+
6271
// Line 31 in index.js without type - can't be tested directly because of early return
6372
test('handles components without type', () => {
6473
const doc = parseFixture('ComponentWithoutType.tsx');

fixtures/Icon.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
3+
type IconProps = Omit<
4+
React.SVGProps<SVGSVGElement>,
5+
'width' | 'height' | 'focusable'
6+
> & {
7+
size?: 'small' | 'medium' | 'big';
8+
color?: 'solid' | 'neutral' | 'warning';
9+
};
10+
11+
export const Icon: React.FC<IconProps> = ({ size }) => {
12+
return <span>{size}</span>;
13+
};

0 commit comments

Comments
 (0)