Skip to content

Commit 7331723

Browse files
committed
Add two new tests for annotation resolver
1 parent b6bde2d commit 7331723

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

packages/react-docgen/src/Documentation.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ export default class DocumentationBuilder {
203203
const obj: Documentation = {};
204204

205205
for (const [key, value] of this.#data) {
206-
// @ts-expect-error The types for Documentation do not allow to be extended atm
207206
obj[key] = value;
208207
}
209208

packages/react-docgen/src/resolver/__tests__/FindAnnotatedDefinitionsResolver-test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,24 @@ describe('FindAnnotatedDefinitionsResolver', () => {
159159
expect(findComponentsInSource(source)).toMatchSnapshot();
160160
});
161161

162+
test('finds named exported component', () => {
163+
const source = `
164+
// @component
165+
export const Component = () => {};
166+
`;
167+
168+
expect(findComponentsInSource(source)).toMatchSnapshot();
169+
});
170+
171+
test('finds default exported component', () => {
172+
const source = `
173+
// @component
174+
export default () => {};
175+
`;
176+
177+
expect(findComponentsInSource(source)).toMatchSnapshot();
178+
});
179+
162180
test('finds component wrapped in two HOCs', () => {
163181
const source = `
164182
// @component

packages/react-docgen/src/resolver/__tests__/__snapshots__/FindAnnotatedDefinitionsResolver-test.ts.snap

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,23 @@ exports[`FindAnnotatedDefinitionsResolver > finds component wrapped in two HOCs
144144
]
145145
`;
146146

147+
exports[`FindAnnotatedDefinitionsResolver > finds default exported component 1`] = `
148+
[
149+
Node {
150+
"async": false,
151+
"body": Node {
152+
"body": [],
153+
"directives": [],
154+
"type": "BlockStatement",
155+
},
156+
"generator": false,
157+
"id": null,
158+
"params": [],
159+
"type": "ArrowFunctionExpression",
160+
},
161+
]
162+
`;
163+
147164
exports[`FindAnnotatedDefinitionsResolver > finds function parameter with annotation 1`] = `
148165
[
149166
Node {
@@ -161,6 +178,23 @@ exports[`FindAnnotatedDefinitionsResolver > finds function parameter with annota
161178
]
162179
`;
163180

181+
exports[`FindAnnotatedDefinitionsResolver > finds named exported component 1`] = `
182+
[
183+
Node {
184+
"async": false,
185+
"body": Node {
186+
"body": [],
187+
"directives": [],
188+
"type": "BlockStatement",
189+
},
190+
"generator": false,
191+
"id": null,
192+
"params": [],
193+
"type": "ArrowFunctionExpression",
194+
},
195+
]
196+
`;
197+
164198
exports[`FindAnnotatedDefinitionsResolver > stateless components > finds ArrowFunctionExpression 1`] = `
165199
[
166200
Node {

0 commit comments

Comments
 (0)