Skip to content

Commit 26ad447

Browse files
phateddanez
authored andcommitted
Add function assignment tests for getMethodDocumentation
1 parent 7f59d5f commit 26ad447

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/utils/__tests__/getMethodDocumentation-test.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ describe('getMethodDocumentation', () => {
2727
});
2828
});
2929

30+
it('handles function assignment', () => {
31+
const def = statement(`
32+
class Foo {
33+
hello = () => {}
34+
}
35+
`);
36+
const method = def.get('body', 'body', 0);
37+
expect(getMethodDocumentation(method)).toEqual({
38+
name: 'hello',
39+
docblock: null,
40+
modifiers: [],
41+
returns: null,
42+
params: [],
43+
});
44+
});
45+
3046
it('handles computed method name', () => {
3147
const def = statement(`
3248
class Foo {
@@ -67,6 +83,25 @@ describe('getMethodDocumentation', () => {
6783
params: [],
6884
});
6985
});
86+
87+
it('extracts docblock on function assignment', () => {
88+
const def = statement(`
89+
class Foo {
90+
/**
91+
* Don't use this!
92+
*/
93+
foo = () => {}
94+
}
95+
`);
96+
const method = def.get('body', 'body', 0);
97+
expect(getMethodDocumentation(method)).toEqual({
98+
name: 'foo',
99+
docblock: "Don't use this!",
100+
modifiers: [],
101+
returns: null,
102+
params: [],
103+
});
104+
});
70105
});
71106

72107
describe('parameters', () => {
@@ -97,6 +132,23 @@ describe('getMethodDocumentation', () => {
97132
);
98133
});
99134

135+
it('extracts flow type info on function assignment', () => {
136+
const def = statement(`
137+
class Foo {
138+
foo = (bar: number) => {}
139+
}
140+
`);
141+
const method = def.get('body', 'body', 0);
142+
expect(getMethodDocumentation(method)).toEqual(
143+
methodParametersDoc([
144+
{
145+
name: 'bar',
146+
type: { name: 'number' },
147+
},
148+
]),
149+
);
150+
});
151+
100152
describe('modifiers', () => {
101153
function methodModifiersDoc(modifiers) {
102154
return {
@@ -201,6 +253,20 @@ describe('getMethodDocumentation', () => {
201253
}),
202254
);
203255
});
256+
257+
it('extracts flow types on function assignment', () => {
258+
const def = statement(`
259+
class Foo {
260+
foo = (): number => {}
261+
}
262+
`);
263+
const method = def.get('body', 'body', 0);
264+
expect(getMethodDocumentation(method)).toEqual(
265+
methodReturnDoc({
266+
type: { name: 'number' },
267+
}),
268+
);
269+
});
204270
});
205271

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

0 commit comments

Comments
 (0)