Skip to content

Commit 16173f8

Browse files
authored
Merge pull request #5 from Winner95/feature02_update_tests
Improve tests for React.forwardRef components and add CI workflow
2 parents 1f5edce + d5bf682 commit 16173f8

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [18, 20]
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
cache: yarn
27+
28+
- name: Install dependencies
29+
run: yarn install --frozen-lockfile
30+
31+
- name: Run tests
32+
run: yarn test --ci

__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', () => {

index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@ function checkForProptypes(path, paramTypeName) {
4848

4949
function setParamsTypeDefinitionFromFunctionType(documentation, path) {
5050
if (
51-
path.parentPath.node.init &&
51+
path.parentPath.node.init &&
5252
Array.isArray(path.parentPath.node.init.params) &&
5353
path.parentPath.node.init.params.length === 0
54-
)
55-
{
54+
) {
5655
return;
57-
}
58-
56+
}
57+
5958
if (
6059
path.node.type === 'ArrowFunctionExpression' &&
6160
(

0 commit comments

Comments
 (0)