Skip to content

Commit 28f80b3

Browse files
committed
add test for imported types
Signed-off-by: Winner95 <Winner95@users.noreply.github.com>
1 parent 713c392 commit 28f80b3

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

__tests__/handler.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ describe('typescript-react-function-component-props-handler', () => {
141141
expect(doc.props.onRemove.tsType.raw).toBe('() => void');
142142
});
143143

144+
// @TODO add support for imported type, partially covered by react.docgen config setup (?)
145+
test('handles React.FC<Props> components with inherited type props', () => {
146+
const doc = parseFixture('TextField.tsx');
147+
148+
expect(doc).toHaveProperty('props');
149+
expect(doc.props).toHaveProperty('onInfoButtonClick');
150+
expect(doc.props.onInfoButtonClick).toHaveProperty('tsType');
151+
expect(doc.props.onInfoButtonClick.tsType.raw).toBe('() => void');
152+
153+
// 'placeholder' prop comes from TextInputProps imported type, which is not yet supported
154+
expect(doc.props).not.toHaveProperty('placeholder');
155+
});
156+
144157
// Line 31 in index.js without type - can't be tested directly because of early return
145158
test('handles components without type', () => {
146159
const doc = parseFixture('ComponentWithoutType.tsx');

fixtures/TextField.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import { TextInputProps } from './Types';
3+
4+
type FieldLabelProps = {
5+
title: React.ReactNode;
6+
description?: React.ReactNode;
7+
hint?: React.ReactNode;
8+
badge?: React.ReactNode;
9+
isRequired?: boolean;
10+
};
11+
12+
type FieldErrorProps = {
13+
errors?: React.ReactNode;
14+
touched?: boolean;
15+
};
16+
17+
type TextFieldProps = FieldLabelProps &
18+
FieldErrorProps & {
19+
// Field-level events
20+
onInfoButtonClick?: () => void;
21+
} & TextInputProps;
22+
23+
export const TextField: React.FC<TextFieldProps> = ({ title }) => {
24+
return <span>{title}</span>;
25+
};

0 commit comments

Comments
 (0)