8
8
9
9
jest . mock ( '../../Documentation' ) ;
10
10
11
- import { expression , statement } from '../../../tests/utils' ;
11
+ import { expression , statement , noopImporter , makeMockImporter } from '../../../tests/utils' ;
12
12
13
13
describe ( 'propDocBlockHandler' , ( ) => {
14
14
let documentation ;
@@ -19,6 +19,17 @@ describe('propDocBlockHandler', () => {
19
19
propDocBlockHandler = require ( '../propDocBlockHandler' ) . default ;
20
20
} ) ;
21
21
22
+ const mockImporter = makeMockImporter ( {
23
+ props : statement ( `
24
+ export default {
25
+ /**
26
+ * A comment on imported props
27
+ */
28
+ foo: Prop.bool,
29
+ };
30
+ ` ) . get ( 'declaration' ) ,
31
+ } ) ;
32
+
22
33
function test ( getSrc , parse ) {
23
34
it ( 'finds docblocks for prop types' , ( ) => {
24
35
const definition = parse (
@@ -36,7 +47,7 @@ describe('propDocBlockHandler', () => {
36
47
) ,
37
48
) ;
38
49
39
- propDocBlockHandler ( documentation , definition ) ;
50
+ propDocBlockHandler ( documentation , definition , noopImporter ) ;
40
51
expect ( documentation . descriptors ) . toEqual ( {
41
52
foo : {
42
53
description : 'Foo comment' ,
@@ -62,7 +73,7 @@ describe('propDocBlockHandler', () => {
62
73
) ,
63
74
) ;
64
75
65
- propDocBlockHandler ( documentation , definition ) ;
76
+ propDocBlockHandler ( documentation , definition , noopImporter ) ;
66
77
expect ( documentation . descriptors ) . toEqual ( {
67
78
foo : {
68
79
description :
@@ -89,7 +100,7 @@ describe('propDocBlockHandler', () => {
89
100
) ,
90
101
) ;
91
102
92
- propDocBlockHandler ( documentation , definition ) ;
103
+ propDocBlockHandler ( documentation , definition , noopImporter ) ;
93
104
expect ( documentation . descriptors ) . toEqual ( {
94
105
foo : {
95
106
description : 'Foo comment' ,
@@ -113,7 +124,7 @@ describe('propDocBlockHandler', () => {
113
124
) ,
114
125
) ;
115
126
116
- propDocBlockHandler ( documentation , definition ) ;
127
+ propDocBlockHandler ( documentation , definition , noopImporter ) ;
117
128
expect ( documentation . descriptors ) . toEqual ( {
118
129
foo : {
119
130
description : 'Foo comment' ,
@@ -137,7 +148,7 @@ describe('propDocBlockHandler', () => {
137
148
) ,
138
149
) ;
139
150
140
- propDocBlockHandler ( documentation , definition ) ;
151
+ propDocBlockHandler ( documentation , definition , noopImporter ) ;
141
152
expect ( documentation . descriptors ) . toEqual ( {
142
153
foo : {
143
154
description : 'Foo comment' ,
@@ -156,13 +167,51 @@ describe('propDocBlockHandler', () => {
156
167
};
157
168
` ) ;
158
169
159
- propDocBlockHandler ( documentation , definition ) ;
170
+ propDocBlockHandler ( documentation , definition , noopImporter ) ;
160
171
expect ( documentation . descriptors ) . toEqual ( {
161
172
foo : {
162
173
description : 'Foo comment' ,
163
174
} ,
164
175
} ) ;
165
176
} ) ;
177
+
178
+ it ( 'resolves imported variables' , ( ) => {
179
+ const definition = parse ( `
180
+ ${ getSrc ( 'Props' ) }
181
+ import Props from 'props';
182
+ ` ) ;
183
+
184
+ propDocBlockHandler ( documentation , definition , mockImporter ) ;
185
+ expect ( documentation . descriptors ) . toEqual ( {
186
+ foo : {
187
+ description : 'A comment on imported props' ,
188
+ } ,
189
+ } ) ;
190
+ } ) ;
191
+
192
+ it ( 'resolves imported variables that are spread' , ( ) => {
193
+ const definition = parse ( `
194
+ ${ getSrc ( 'Props' ) }
195
+ import ExtraProps from 'props';
196
+ var Props = {
197
+ ...ExtraProps,
198
+ /**
199
+ * Bar comment
200
+ */
201
+ bar: Prop.bool,
202
+ }
203
+ ` ) ;
204
+
205
+ propDocBlockHandler ( documentation , definition , mockImporter ) ;
206
+ expect ( documentation . descriptors ) . toEqual ( {
207
+ foo : {
208
+ description : 'A comment on imported props' ,
209
+ } ,
210
+ bar : {
211
+ description : 'Bar comment' ,
212
+ } ,
213
+ } ) ;
214
+ } ) ;
166
215
}
167
216
168
217
describe ( 'React.createClass' , ( ) => {
@@ -200,9 +249,9 @@ describe('propDocBlockHandler', () => {
200
249
201
250
it ( 'does not error if propTypes cannot be found' , ( ) => {
202
251
let definition = expression ( '{fooBar: 42}' ) ;
203
- expect ( ( ) => propDocBlockHandler ( documentation , definition ) ) . not . toThrow ( ) ;
252
+ expect ( ( ) => propDocBlockHandler ( documentation , definition , noopImporter ) ) . not . toThrow ( ) ;
204
253
205
254
definition = statement ( 'class Foo {}' ) ;
206
- expect ( ( ) => propDocBlockHandler ( documentation , definition ) ) . not . toThrow ( ) ;
255
+ expect ( ( ) => propDocBlockHandler ( documentation , definition , noopImporter ) ) . not . toThrow ( ) ;
207
256
} ) ;
208
257
} ) ;
0 commit comments