|
6 | 6 | *
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import { statement, noopImporter } from '../../../tests/utils'; |
| 9 | +import { |
| 10 | + statement, |
| 11 | + noopImporter, |
| 12 | + makeMockImporter, |
| 13 | +} from '../../../tests/utils'; |
10 | 14 | import getMethodDocumentation from '../getMethodDocumentation';
|
11 | 15 |
|
12 | 16 | 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 | + |
13 | 31 | describe('name', () => {
|
14 | 32 | it('extracts the method name', () => {
|
15 | 33 | const def = statement(`
|
@@ -62,6 +80,23 @@ describe('getMethodDocumentation', () => {
|
62 | 80 | const method = def.get('body', 'body', 0);
|
63 | 81 | expect(getMethodDocumentation(method, noopImporter)).toMatchSnapshot();
|
64 | 82 | });
|
| 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 | + }); |
65 | 100 | });
|
66 | 101 |
|
67 | 102 | describe('docblock', () => {
|
@@ -149,6 +184,24 @@ describe('getMethodDocumentation', () => {
|
149 | 184 | );
|
150 | 185 | });
|
151 | 186 |
|
| 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 | + |
152 | 205 | describe('modifiers', () => {
|
153 | 206 | function methodModifiersDoc(modifiers) {
|
154 | 207 | return {
|
@@ -271,6 +324,21 @@ describe('getMethodDocumentation', () => {
|
271 | 324 | }),
|
272 | 325 | );
|
273 | 326 | });
|
| 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 | + }); |
274 | 342 | });
|
275 | 343 |
|
276 | 344 | describe('private', () => {
|
|
0 commit comments