Skip to content

Commit d5bf682

Browse files
committed
update tests for React.forwardRef(...) components
Signed-off-by: Winner95 <Winner95@users.noreply.github.com>
1 parent fb46cda commit d5bf682

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

__tests__/handler.test.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,26 @@ describe('typescript-react-function-component-props-handler', () => {
3939
expect(doc.displayName).toBe('TooltipTarget');
4040
});
4141

42-
// Currently returns error for React.forwardRef(...) components
4342
test('handles React.forwardRef(...) components - part 2', () => {
44-
expect(() => parseFixture('ForwardedButton.tsx')).toThrow(
45-
"Cannot read properties of undefined (reading 'length')"
46-
);
43+
const doc = parseFixture('ForwardedButton.tsx');
44+
45+
expect(doc.displayName).toBe('ForwardedButton');
46+
expect(doc).toHaveProperty('props');
47+
expect(doc.props).toHaveProperty('label');
48+
expect(doc.props.label.tsType).toMatchObject({ name: 'string' });
49+
expect(doc.props.label.required).toBe(true);
50+
expect(doc.props.label).toHaveProperty('description');
51+
expect(doc.props.label.description).toBe('Text to show inside the button');
52+
53+
expect(doc.props).toHaveProperty('onClick');
54+
expect(doc.props.onClick.tsType).toMatchObject({ name: 'signature' });
55+
expect(doc.props.onClick.tsType.type).toBe('function');
56+
expect(doc.props.onClick.tsType.raw).toBe('() => void');
57+
expect(doc.props.onClick.tsType.signature).toMatchObject({ arguments: [], return: { name: 'void' } });
58+
expect(doc.props.onClick.required).toBe(false);
59+
60+
expect(doc.props.onClick).toHaveProperty('description');
61+
expect(doc.props.onClick.description).toBe('Optional click handler');
4762
});
4863

4964
test('handles React.FC<Props> components - AccessibleButton', () => {

0 commit comments

Comments
 (0)