6
6
*
7
7
*/
8
8
9
- import { expression , statement } from '../../../tests/utils' ;
9
+ import { expression , statement , noopImporter } from '../../../tests/utils' ;
10
10
import getPropType from '../getPropType' ;
11
11
12
12
describe ( 'getPropType' , ( ) => {
@@ -26,26 +26,26 @@ describe('getPropType', () => {
26
26
] ;
27
27
28
28
simplePropTypes . forEach ( type =>
29
- expect ( getPropType ( expression ( 'React.PropTypes.' + type ) ) ) . toEqual ( {
29
+ expect ( getPropType ( expression ( 'React.PropTypes.' + type ) , noopImporter ) ) . toEqual ( {
30
30
name : type ,
31
31
} ) ,
32
32
) ;
33
33
34
34
// It doesn't actually matter what the MemberExpression is
35
35
simplePropTypes . forEach ( type =>
36
- expect ( getPropType ( expression ( 'Foo.' + type + '.bar' ) ) ) . toEqual ( {
36
+ expect ( getPropType ( expression ( 'Foo.' + type + '.bar' ) , noopImporter ) ) . toEqual ( {
37
37
name : type ,
38
38
} ) ,
39
39
) ;
40
40
41
41
// Doesn't even have to be a MemberExpression
42
42
simplePropTypes . forEach ( type =>
43
- expect ( getPropType ( expression ( type ) ) ) . toEqual ( { name : type } ) ,
43
+ expect ( getPropType ( expression ( type ) , noopImporter ) ) . toEqual ( { name : type } ) ,
44
44
) ;
45
45
} ) ;
46
46
47
47
it ( 'detects complex prop types' , ( ) => {
48
- expect ( getPropType ( expression ( 'oneOf(["foo", "bar"])' ) ) ) . toEqual ( {
48
+ expect ( getPropType ( expression ( 'oneOf(["foo", "bar"])' ) , noopImporter ) ) . toEqual ( {
49
49
name : 'enum' ,
50
50
value : [
51
51
{ value : '"foo"' , computed : false } ,
@@ -54,41 +54,41 @@ describe('getPropType', () => {
54
54
} ) ;
55
55
56
56
// line comments are ignored
57
- expect ( getPropType ( expression ( 'oneOf(["foo", // baz\n"bar"])' ) ) ) . toEqual ( {
57
+ expect ( getPropType ( expression ( 'oneOf(["foo", // baz\n"bar"])' ) , noopImporter ) ) . toEqual ( {
58
58
name : 'enum' ,
59
59
value : [
60
60
{ value : '"foo"' , computed : false } ,
61
61
{ value : '"bar"' , computed : false } ,
62
62
] ,
63
63
} ) ;
64
64
65
- expect ( getPropType ( expression ( 'oneOfType([number, bool])' ) ) ) . toEqual ( {
65
+ expect ( getPropType ( expression ( 'oneOfType([number, bool])' ) , noopImporter ) ) . toEqual ( {
66
66
name : 'union' ,
67
67
value : [ { name : 'number' } , { name : 'bool' } ] ,
68
68
} ) ;
69
69
70
70
// custom type
71
- expect ( getPropType ( expression ( 'oneOfType([foo])' ) ) ) . toEqual ( {
71
+ expect ( getPropType ( expression ( 'oneOfType([foo])' ) , noopImporter ) ) . toEqual ( {
72
72
name : 'union' ,
73
73
value : [ { name : 'custom' , raw : 'foo' } ] ,
74
74
} ) ;
75
75
76
- expect ( getPropType ( expression ( 'instanceOf(Foo)' ) ) ) . toEqual ( {
76
+ expect ( getPropType ( expression ( 'instanceOf(Foo)' ) , noopImporter ) ) . toEqual ( {
77
77
name : 'instanceOf' ,
78
78
value : 'Foo' ,
79
79
} ) ;
80
80
81
- expect ( getPropType ( expression ( 'arrayOf(string)' ) ) ) . toEqual ( {
81
+ expect ( getPropType ( expression ( 'arrayOf(string)' ) , noopImporter ) ) . toEqual ( {
82
82
name : 'arrayOf' ,
83
83
value : { name : 'string' } ,
84
84
} ) ;
85
85
86
- expect ( getPropType ( expression ( 'objectOf(string)' ) ) ) . toEqual ( {
86
+ expect ( getPropType ( expression ( 'objectOf(string)' ) , noopImporter ) ) . toEqual ( {
87
87
name : 'objectOf' ,
88
88
value : { name : 'string' } ,
89
89
} ) ;
90
90
91
- expect ( getPropType ( expression ( 'shape({foo: string, bar: bool})' ) ) ) . toEqual ( {
91
+ expect ( getPropType ( expression ( 'shape({foo: string, bar: bool})' ) , noopImporter ) ) . toEqual ( {
92
92
name : 'shape' ,
93
93
value : {
94
94
foo : {
@@ -102,7 +102,7 @@ describe('getPropType', () => {
102
102
} ,
103
103
} ) ;
104
104
105
- expect ( getPropType ( expression ( 'exact({foo: string, bar: bool})' ) ) ) . toEqual ( {
105
+ expect ( getPropType ( expression ( 'exact({foo: string, bar: bool})' ) , noopImporter ) ) . toEqual ( {
106
106
name : 'exact' ,
107
107
value : {
108
108
foo : {
@@ -117,7 +117,7 @@ describe('getPropType', () => {
117
117
} ) ;
118
118
119
119
// custom
120
- expect ( getPropType ( expression ( 'shape({foo: xyz})' ) ) ) . toEqual ( {
120
+ expect ( getPropType ( expression ( 'shape({foo: xyz})' ) , noopImporter ) ) . toEqual ( {
121
121
name : 'shape' ,
122
122
value : {
123
123
foo : {
@@ -129,7 +129,7 @@ describe('getPropType', () => {
129
129
} ) ;
130
130
131
131
// custom
132
- expect ( getPropType ( expression ( 'exact({foo: xyz})' ) ) ) . toEqual ( {
132
+ expect ( getPropType ( expression ( 'exact({foo: xyz})' ) , noopImporter ) ) . toEqual ( {
133
133
name : 'exact' ,
134
134
value : {
135
135
foo : {
@@ -141,14 +141,14 @@ describe('getPropType', () => {
141
141
} ) ;
142
142
143
143
// computed
144
- expect ( getPropType ( expression ( 'shape(Child.propTypes)' ) ) ) . toEqual ( {
144
+ expect ( getPropType ( expression ( 'shape(Child.propTypes)' ) , noopImporter ) ) . toEqual ( {
145
145
name : 'shape' ,
146
146
value : 'Child.propTypes' ,
147
147
computed : true ,
148
148
} ) ;
149
149
150
150
// computed
151
- expect ( getPropType ( expression ( 'exact(Child.propTypes)' ) ) ) . toEqual ( {
151
+ expect ( getPropType ( expression ( 'exact(Child.propTypes)' ) , noopImporter ) ) . toEqual ( {
152
152
name : 'exact' ,
153
153
value : 'Child.propTypes' ,
154
154
computed : true ,
@@ -162,7 +162,7 @@ describe('getPropType', () => {
162
162
var shape = {bar: PropTypes.string};
163
163
` ) . get ( 'expression' ) ;
164
164
165
- expect ( getPropType ( propTypeExpression ) ) . toMatchSnapshot ( ) ;
165
+ expect ( getPropType ( propTypeExpression , noopImporter ) ) . toMatchSnapshot ( ) ;
166
166
} ) ;
167
167
168
168
it ( 'resolves simple identifier to their initialization value' , ( ) => {
@@ -171,7 +171,7 @@ describe('getPropType', () => {
171
171
var TYPES = ["foo", "bar"];
172
172
` ) . get ( 'expression' ) ;
173
173
174
- expect ( getPropType ( propTypeIdentifier ) ) . toMatchSnapshot ( ) ;
174
+ expect ( getPropType ( propTypeIdentifier , noopImporter ) ) . toMatchSnapshot ( ) ;
175
175
} ) ;
176
176
177
177
it ( 'resolves simple identifier to their initialization value in array' , ( ) => {
@@ -181,7 +181,7 @@ describe('getPropType', () => {
181
181
var BAR = "bar";
182
182
` ) . get ( 'expression' ) ;
183
183
184
- expect ( getPropType ( identifierInsideArray ) ) . toMatchSnapshot ( ) ;
184
+ expect ( getPropType ( identifierInsideArray , noopImporter ) ) . toMatchSnapshot ( ) ;
185
185
} ) ;
186
186
187
187
it ( 'resolves memberExpressions' , ( ) => {
@@ -190,7 +190,7 @@ describe('getPropType', () => {
190
190
var TYPES = { FOO: "foo", BAR: "bar" };
191
191
` ) . get ( 'expression' ) ;
192
192
193
- expect ( getPropType ( propTypeExpression ) ) . toMatchSnapshot ( ) ;
193
+ expect ( getPropType ( propTypeExpression , noopImporter ) ) . toMatchSnapshot ( ) ;
194
194
} ) ;
195
195
196
196
it ( 'correctly resolves SpreadElements in arrays' , ( ) => {
@@ -199,7 +199,7 @@ describe('getPropType', () => {
199
199
var TYPES = ["foo", "bar"];
200
200
` ) . get ( 'expression' ) ;
201
201
202
- expect ( getPropType ( propTypeExpression ) ) . toMatchSnapshot ( ) ;
202
+ expect ( getPropType ( propTypeExpression , noopImporter ) ) . toMatchSnapshot ( ) ;
203
203
} ) ;
204
204
205
205
it ( 'correctly resolves nested SpreadElements in arrays' , ( ) => {
@@ -209,7 +209,7 @@ describe('getPropType', () => {
209
209
var TYPES2 = ["bar"];
210
210
` ) . get ( 'expression' ) ;
211
211
212
- expect ( getPropType ( propTypeExpression ) ) . toMatchSnapshot ( ) ;
212
+ expect ( getPropType ( propTypeExpression , noopImporter ) ) . toMatchSnapshot ( ) ;
213
213
} ) ;
214
214
215
215
it ( 'does resolve object keys values' , ( ) => {
@@ -218,7 +218,7 @@ describe('getPropType', () => {
218
218
var TYPES = { FOO: "foo", BAR: "bar" };
219
219
` ) . get ( 'expression' ) ;
220
220
221
- expect ( getPropType ( propTypeExpression ) ) . toMatchSnapshot ( ) ;
221
+ expect ( getPropType ( propTypeExpression , noopImporter ) ) . toMatchSnapshot ( ) ;
222
222
} ) ;
223
223
224
224
it ( 'does resolve object values' , ( ) => {
@@ -227,7 +227,7 @@ describe('getPropType', () => {
227
227
var TYPES = { FOO: "foo", BAR: "bar" };
228
228
` ) . get ( 'expression' ) ;
229
229
230
- expect ( getPropType ( propTypeExpression ) ) . toMatchSnapshot ( ) ;
230
+ expect ( getPropType ( propTypeExpression , noopImporter ) ) . toMatchSnapshot ( ) ;
231
231
} ) ;
232
232
233
233
it ( 'does not resolve external values' , ( ) => {
@@ -236,16 +236,16 @@ describe('getPropType', () => {
236
236
import { TYPES } from './foo';
237
237
` ) . get ( 'expression' ) ;
238
238
239
- expect ( getPropType ( propTypeExpression ) ) . toMatchSnapshot ( ) ;
239
+ expect ( getPropType ( propTypeExpression , noopImporter ) ) . toMatchSnapshot ( ) ;
240
240
} ) ;
241
241
} ) ;
242
242
243
243
it ( 'detects custom validation functions for function' , ( ) => {
244
- expect ( getPropType ( expression ( '(function() {})' ) ) ) . toMatchSnapshot ( ) ;
244
+ expect ( getPropType ( expression ( '(function() {})' ) , noopImporter ) ) . toMatchSnapshot ( ) ;
245
245
} ) ;
246
246
247
247
it ( 'detects custom validation functions for arrow function' , ( ) => {
248
- expect ( getPropType ( expression ( '() => {}' ) ) ) . toMatchSnapshot ( ) ;
248
+ expect ( getPropType ( expression ( '() => {}' ) , noopImporter ) ) . toMatchSnapshot ( ) ;
249
249
} ) ;
250
250
251
251
it ( 'detects descriptions on nested types in arrayOf' , ( ) => {
@@ -257,6 +257,7 @@ describe('getPropType', () => {
257
257
*/
258
258
string
259
259
)` ) ,
260
+ noopImporter ,
260
261
) ,
261
262
) . toMatchSnapshot ( ) ;
262
263
} ) ;
@@ -270,6 +271,7 @@ describe('getPropType', () => {
270
271
*/
271
272
string
272
273
)` ) ,
274
+ noopImporter ,
273
275
) ,
274
276
) . toMatchSnapshot ( ) ;
275
277
} ) ;
@@ -287,6 +289,7 @@ describe('getPropType', () => {
287
289
*/
288
290
bar: bool
289
291
})` ) ,
292
+ noopImporter ,
290
293
) ,
291
294
) . toMatchSnapshot ( ) ;
292
295
} ) ;
@@ -298,6 +301,7 @@ describe('getPropType', () => {
298
301
foo: string.isRequired,
299
302
bar: bool
300
303
})` ) ,
304
+ noopImporter ,
301
305
) ,
302
306
) . toMatchSnapshot ( ) ;
303
307
} ) ;
@@ -315,6 +319,7 @@ describe('getPropType', () => {
315
319
*/
316
320
bar: bool
317
321
})` ) ,
322
+ noopImporter ,
318
323
) ,
319
324
) . toMatchSnapshot ( ) ;
320
325
} ) ;
@@ -326,6 +331,7 @@ describe('getPropType', () => {
326
331
foo: string.isRequired,
327
332
bar: bool
328
333
})` ) ,
334
+ noopImporter ,
329
335
) ,
330
336
) . toMatchSnapshot ( ) ;
331
337
} ) ;
@@ -337,6 +343,7 @@ describe('getPropType', () => {
337
343
[foo]: string.isRequired,
338
344
bar: bool
339
345
})` ) ,
346
+ noopImporter ,
340
347
) ,
341
348
) . toMatchSnapshot ( ) ;
342
349
} ) ;
@@ -348,6 +355,7 @@ describe('getPropType', () => {
348
355
[() => {}]: string.isRequired,
349
356
bar: bool
350
357
})` ) ,
358
+ noopImporter ,
351
359
) ,
352
360
) . toMatchSnapshot ( ) ;
353
361
} ) ;
0 commit comments