@@ -27,6 +27,22 @@ describe('getMethodDocumentation', () => {
27
27
} ) ;
28
28
} ) ;
29
29
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
+
30
46
it ( 'handles computed method name' , ( ) => {
31
47
const def = statement ( `
32
48
class Foo {
@@ -67,6 +83,25 @@ describe('getMethodDocumentation', () => {
67
83
params : [ ] ,
68
84
} ) ;
69
85
} ) ;
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
+ } ) ;
70
105
} ) ;
71
106
72
107
describe ( 'parameters' , ( ) => {
@@ -97,6 +132,23 @@ describe('getMethodDocumentation', () => {
97
132
) ;
98
133
} ) ;
99
134
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
+
100
152
describe ( 'modifiers' , ( ) => {
101
153
function methodModifiersDoc ( modifiers ) {
102
154
return {
@@ -201,6 +253,20 @@ describe('getMethodDocumentation', () => {
201
253
} ) ,
202
254
) ;
203
255
} ) ;
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
+ } ) ;
204
270
} ) ;
205
271
206
272
describe ( 'private' , ( ) => {
0 commit comments