Skip to content

Commit 96db52f

Browse files
phateddanez
authored andcommitted
Add importer tests for getMethodDocumentation
1 parent e86d846 commit 96db52f

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

src/utils/__tests__/getMethodDocumentation-test.js

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,28 @@
66
*
77
*/
88

9-
import { statement, noopImporter } from '../../../tests/utils';
9+
import {
10+
statement,
11+
noopImporter,
12+
makeMockImporter,
13+
} from '../../../tests/utils';
1014
import getMethodDocumentation from '../getMethodDocumentation';
1115

1216
describe('getMethodDocumentation', () => {
17+
const mockImporter = makeMockImporter({
18+
hello: statement(`
19+
export default () => {};
20+
`).get('declaration'),
21+
22+
bar: statement(`
23+
export default (bar: number) => {};
24+
`).get('declaration'),
25+
26+
baz: statement(`
27+
export default (): number => {};
28+
`).get('declaration'),
29+
});
30+
1331
describe('name', () => {
1432
it('extracts the method name', () => {
1533
const def = statement(`
@@ -62,6 +80,23 @@ describe('getMethodDocumentation', () => {
6280
const method = def.get('body', 'body', 0);
6381
expect(getMethodDocumentation(method, noopImporter)).toMatchSnapshot();
6482
});
83+
84+
it('resolves assignment of imported function', () => {
85+
const def = statement(`
86+
class Foo {
87+
hello = hello;
88+
}
89+
import hello from 'hello';
90+
`);
91+
const method = def.get('body', 'body', 0);
92+
expect(getMethodDocumentation(method, mockImporter)).toEqual({
93+
name: 'hello',
94+
docblock: null,
95+
modifiers: [],
96+
returns: null,
97+
params: [],
98+
});
99+
});
65100
});
66101

67102
describe('docblock', () => {
@@ -149,6 +184,24 @@ describe('getMethodDocumentation', () => {
149184
);
150185
});
151186

187+
it('resolves flow type info on imported functions', () => {
188+
const def = statement(`
189+
class Foo {
190+
foo = bar
191+
}
192+
import bar from 'bar';
193+
`);
194+
const method = def.get('body', 'body', 0);
195+
expect(getMethodDocumentation(method, mockImporter)).toEqual(
196+
methodParametersDoc([
197+
{
198+
name: 'bar',
199+
type: { name: 'number' },
200+
},
201+
]),
202+
);
203+
});
204+
152205
describe('modifiers', () => {
153206
function methodModifiersDoc(modifiers) {
154207
return {
@@ -271,6 +324,21 @@ describe('getMethodDocumentation', () => {
271324
}),
272325
);
273326
});
327+
328+
it('resolves flow types on imported functions', () => {
329+
const def = statement(`
330+
class Foo {
331+
foo = baz
332+
}
333+
import baz from 'baz';
334+
`);
335+
const method = def.get('body', 'body', 0);
336+
expect(getMethodDocumentation(method, mockImporter)).toEqual(
337+
methodReturnDoc({
338+
type: { name: 'number' },
339+
}),
340+
);
341+
});
274342
});
275343

276344
describe('private', () => {

0 commit comments

Comments
 (0)