Skip to content

Commit bb1a9af

Browse files
committed
Add test to verify it does not randomly find types on non forwardRef
1 parent 3cf7bde commit bb1a9af

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

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

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

110+
exports[`getTypeFromReactComponent > TypeScript > stateless > does not find generic forwardRef type annotation on typo 1`] = `[]`;
111+
110112
exports[`getTypeFromReactComponent > TypeScript > stateless > finds generic forwardRef type annotation 1`] = `
111113
[
112114
Node {

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

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

67+
test('does not find generic forwardRef type annotation on typo', () => {
68+
const path = parseTypescript
69+
.statementLast<VariableDeclaration>(
70+
`import React from 'react';
71+
const x = React.backwardRef<HTMLDivElement, React.PropsWithChildren<Props>>((props, ref) => {})`,
72+
)
73+
.get('declarations')[0]
74+
.get('init') as NodePath<ArrowFunctionExpression>;
75+
76+
expect(getTypeFromReactComponent(path)).toMatchSnapshot();
77+
});
78+
6779
test('finds param inline type', () => {
6880
const path = parseTypescript
6981
.statementLast<VariableDeclaration>(

0 commit comments

Comments
 (0)