Skip to content

Commit 165715d

Browse files
committed
Add new test
1 parent 45b9a89 commit 165715d

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

packages/react-docgen/src/utils/__tests__/__snapshots__/getTypeFromReactComponent-test.ts.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ exports[`getTypeFromReactComponent > TypeScript > classes > finds props type in
107107
]
108108
`;
109109

110+
exports[`getTypeFromReactComponent > TypeScript > stateless > finds generic forwardRef type annotation 1`] = `
111+
[
112+
Node {
113+
"type": "TSTypeReference",
114+
"typeName": Node {
115+
"name": "Props",
116+
"type": "Identifier",
117+
},
118+
},
119+
]
120+
`;
121+
110122
exports[`getTypeFromReactComponent > TypeScript > stateless > finds multiple variable type annotation 1`] = `
111123
[
112124
Node {

packages/react-docgen/src/utils/__tests__/getTypeFromReactComponent-test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ describe('getTypeFromReactComponent', () => {
5252
expect(getTypeFromReactComponent(path)).toMatchSnapshot();
5353
});
5454

55+
test('finds generic forwardRef type annotation', () => {
56+
const path = parseTypescript
57+
.statementLast<VariableDeclaration>(
58+
`import React from 'react';
59+
const x = React.forwardRef<HTMLDivElement, React.PropsWithChildren<Props>>((props, ref) => {})`,
60+
)
61+
.get('declarations')[0]
62+
.get('init') as NodePath<ArrowFunctionExpression>;
63+
64+
expect(getTypeFromReactComponent(path)).toMatchSnapshot();
65+
});
66+
5567
test('finds param inline type', () => {
5668
const path = parseTypescript
5769
.statementLast<VariableDeclaration>(

0 commit comments

Comments
 (0)