Skip to content

Commit 7cc42ef

Browse files
phateddanez
authored andcommitted
Avoid guarding on importer & fix tests for utils
1 parent 18f34d7 commit 7cc42ef

8 files changed

+108
-101
lines changed

src/utils/__tests__/getPropType-test.js

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*/
88

9-
import { expression, statement } from '../../../tests/utils';
9+
import { expression, statement, noopImporter } from '../../../tests/utils';
1010
import getPropType from '../getPropType';
1111

1212
describe('getPropType', () => {
@@ -26,26 +26,26 @@ describe('getPropType', () => {
2626
];
2727

2828
simplePropTypes.forEach(type =>
29-
expect(getPropType(expression('React.PropTypes.' + type))).toEqual({
29+
expect(getPropType(expression('React.PropTypes.' + type), noopImporter)).toEqual({
3030
name: type,
3131
}),
3232
);
3333

3434
// It doesn't actually matter what the MemberExpression is
3535
simplePropTypes.forEach(type =>
36-
expect(getPropType(expression('Foo.' + type + '.bar'))).toEqual({
36+
expect(getPropType(expression('Foo.' + type + '.bar'), noopImporter)).toEqual({
3737
name: type,
3838
}),
3939
);
4040

4141
// Doesn't even have to be a MemberExpression
4242
simplePropTypes.forEach(type =>
43-
expect(getPropType(expression(type))).toEqual({ name: type }),
43+
expect(getPropType(expression(type), noopImporter)).toEqual({ name: type }),
4444
);
4545
});
4646

4747
it('detects complex prop types', () => {
48-
expect(getPropType(expression('oneOf(["foo", "bar"])'))).toEqual({
48+
expect(getPropType(expression('oneOf(["foo", "bar"])'), noopImporter)).toEqual({
4949
name: 'enum',
5050
value: [
5151
{ value: '"foo"', computed: false },
@@ -54,41 +54,41 @@ describe('getPropType', () => {
5454
});
5555

5656
// 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({
5858
name: 'enum',
5959
value: [
6060
{ value: '"foo"', computed: false },
6161
{ value: '"bar"', computed: false },
6262
],
6363
});
6464

65-
expect(getPropType(expression('oneOfType([number, bool])'))).toEqual({
65+
expect(getPropType(expression('oneOfType([number, bool])'), noopImporter)).toEqual({
6666
name: 'union',
6767
value: [{ name: 'number' }, { name: 'bool' }],
6868
});
6969

7070
// custom type
71-
expect(getPropType(expression('oneOfType([foo])'))).toEqual({
71+
expect(getPropType(expression('oneOfType([foo])'), noopImporter)).toEqual({
7272
name: 'union',
7373
value: [{ name: 'custom', raw: 'foo' }],
7474
});
7575

76-
expect(getPropType(expression('instanceOf(Foo)'))).toEqual({
76+
expect(getPropType(expression('instanceOf(Foo)'), noopImporter)).toEqual({
7777
name: 'instanceOf',
7878
value: 'Foo',
7979
});
8080

81-
expect(getPropType(expression('arrayOf(string)'))).toEqual({
81+
expect(getPropType(expression('arrayOf(string)'), noopImporter)).toEqual({
8282
name: 'arrayOf',
8383
value: { name: 'string' },
8484
});
8585

86-
expect(getPropType(expression('objectOf(string)'))).toEqual({
86+
expect(getPropType(expression('objectOf(string)'), noopImporter)).toEqual({
8787
name: 'objectOf',
8888
value: { name: 'string' },
8989
});
9090

91-
expect(getPropType(expression('shape({foo: string, bar: bool})'))).toEqual({
91+
expect(getPropType(expression('shape({foo: string, bar: bool})'), noopImporter)).toEqual({
9292
name: 'shape',
9393
value: {
9494
foo: {
@@ -102,7 +102,7 @@ describe('getPropType', () => {
102102
},
103103
});
104104

105-
expect(getPropType(expression('exact({foo: string, bar: bool})'))).toEqual({
105+
expect(getPropType(expression('exact({foo: string, bar: bool})'), noopImporter)).toEqual({
106106
name: 'exact',
107107
value: {
108108
foo: {
@@ -117,7 +117,7 @@ describe('getPropType', () => {
117117
});
118118

119119
// custom
120-
expect(getPropType(expression('shape({foo: xyz})'))).toEqual({
120+
expect(getPropType(expression('shape({foo: xyz})'), noopImporter)).toEqual({
121121
name: 'shape',
122122
value: {
123123
foo: {
@@ -129,7 +129,7 @@ describe('getPropType', () => {
129129
});
130130

131131
// custom
132-
expect(getPropType(expression('exact({foo: xyz})'))).toEqual({
132+
expect(getPropType(expression('exact({foo: xyz})'), noopImporter)).toEqual({
133133
name: 'exact',
134134
value: {
135135
foo: {
@@ -141,14 +141,14 @@ describe('getPropType', () => {
141141
});
142142

143143
// computed
144-
expect(getPropType(expression('shape(Child.propTypes)'))).toEqual({
144+
expect(getPropType(expression('shape(Child.propTypes)'), noopImporter)).toEqual({
145145
name: 'shape',
146146
value: 'Child.propTypes',
147147
computed: true,
148148
});
149149

150150
// computed
151-
expect(getPropType(expression('exact(Child.propTypes)'))).toEqual({
151+
expect(getPropType(expression('exact(Child.propTypes)'), noopImporter)).toEqual({
152152
name: 'exact',
153153
value: 'Child.propTypes',
154154
computed: true,
@@ -162,7 +162,7 @@ describe('getPropType', () => {
162162
var shape = {bar: PropTypes.string};
163163
`).get('expression');
164164

165-
expect(getPropType(propTypeExpression)).toMatchSnapshot();
165+
expect(getPropType(propTypeExpression, noopImporter)).toMatchSnapshot();
166166
});
167167

168168
it('resolves simple identifier to their initialization value', () => {
@@ -171,7 +171,7 @@ describe('getPropType', () => {
171171
var TYPES = ["foo", "bar"];
172172
`).get('expression');
173173

174-
expect(getPropType(propTypeIdentifier)).toMatchSnapshot();
174+
expect(getPropType(propTypeIdentifier, noopImporter)).toMatchSnapshot();
175175
});
176176

177177
it('resolves simple identifier to their initialization value in array', () => {
@@ -181,7 +181,7 @@ describe('getPropType', () => {
181181
var BAR = "bar";
182182
`).get('expression');
183183

184-
expect(getPropType(identifierInsideArray)).toMatchSnapshot();
184+
expect(getPropType(identifierInsideArray, noopImporter)).toMatchSnapshot();
185185
});
186186

187187
it('resolves memberExpressions', () => {
@@ -190,7 +190,7 @@ describe('getPropType', () => {
190190
var TYPES = { FOO: "foo", BAR: "bar" };
191191
`).get('expression');
192192

193-
expect(getPropType(propTypeExpression)).toMatchSnapshot();
193+
expect(getPropType(propTypeExpression, noopImporter)).toMatchSnapshot();
194194
});
195195

196196
it('correctly resolves SpreadElements in arrays', () => {
@@ -199,7 +199,7 @@ describe('getPropType', () => {
199199
var TYPES = ["foo", "bar"];
200200
`).get('expression');
201201

202-
expect(getPropType(propTypeExpression)).toMatchSnapshot();
202+
expect(getPropType(propTypeExpression, noopImporter)).toMatchSnapshot();
203203
});
204204

205205
it('correctly resolves nested SpreadElements in arrays', () => {
@@ -209,7 +209,7 @@ describe('getPropType', () => {
209209
var TYPES2 = ["bar"];
210210
`).get('expression');
211211

212-
expect(getPropType(propTypeExpression)).toMatchSnapshot();
212+
expect(getPropType(propTypeExpression, noopImporter)).toMatchSnapshot();
213213
});
214214

215215
it('does resolve object keys values', () => {
@@ -218,7 +218,7 @@ describe('getPropType', () => {
218218
var TYPES = { FOO: "foo", BAR: "bar" };
219219
`).get('expression');
220220

221-
expect(getPropType(propTypeExpression)).toMatchSnapshot();
221+
expect(getPropType(propTypeExpression, noopImporter)).toMatchSnapshot();
222222
});
223223

224224
it('does resolve object values', () => {
@@ -227,7 +227,7 @@ describe('getPropType', () => {
227227
var TYPES = { FOO: "foo", BAR: "bar" };
228228
`).get('expression');
229229

230-
expect(getPropType(propTypeExpression)).toMatchSnapshot();
230+
expect(getPropType(propTypeExpression, noopImporter)).toMatchSnapshot();
231231
});
232232

233233
it('does not resolve external values', () => {
@@ -236,16 +236,16 @@ describe('getPropType', () => {
236236
import { TYPES } from './foo';
237237
`).get('expression');
238238

239-
expect(getPropType(propTypeExpression)).toMatchSnapshot();
239+
expect(getPropType(propTypeExpression, noopImporter)).toMatchSnapshot();
240240
});
241241
});
242242

243243
it('detects custom validation functions for function', () => {
244-
expect(getPropType(expression('(function() {})'))).toMatchSnapshot();
244+
expect(getPropType(expression('(function() {})'), noopImporter)).toMatchSnapshot();
245245
});
246246

247247
it('detects custom validation functions for arrow function', () => {
248-
expect(getPropType(expression('() => {}'))).toMatchSnapshot();
248+
expect(getPropType(expression('() => {}'), noopImporter)).toMatchSnapshot();
249249
});
250250

251251
it('detects descriptions on nested types in arrayOf', () => {
@@ -257,6 +257,7 @@ describe('getPropType', () => {
257257
*/
258258
string
259259
)`),
260+
noopImporter,
260261
),
261262
).toMatchSnapshot();
262263
});
@@ -270,6 +271,7 @@ describe('getPropType', () => {
270271
*/
271272
string
272273
)`),
274+
noopImporter,
273275
),
274276
).toMatchSnapshot();
275277
});
@@ -287,6 +289,7 @@ describe('getPropType', () => {
287289
*/
288290
bar: bool
289291
})`),
292+
noopImporter,
290293
),
291294
).toMatchSnapshot();
292295
});
@@ -298,6 +301,7 @@ describe('getPropType', () => {
298301
foo: string.isRequired,
299302
bar: bool
300303
})`),
304+
noopImporter,
301305
),
302306
).toMatchSnapshot();
303307
});
@@ -315,6 +319,7 @@ describe('getPropType', () => {
315319
*/
316320
bar: bool
317321
})`),
322+
noopImporter,
318323
),
319324
).toMatchSnapshot();
320325
});
@@ -326,6 +331,7 @@ describe('getPropType', () => {
326331
foo: string.isRequired,
327332
bar: bool
328333
})`),
334+
noopImporter,
329335
),
330336
).toMatchSnapshot();
331337
});
@@ -337,6 +343,7 @@ describe('getPropType', () => {
337343
[foo]: string.isRequired,
338344
bar: bool
339345
})`),
346+
noopImporter,
340347
),
341348
).toMatchSnapshot();
342349
});
@@ -348,6 +355,7 @@ describe('getPropType', () => {
348355
[() => {}]: string.isRequired,
349356
bar: bool
350357
})`),
358+
noopImporter,
351359
),
352360
).toMatchSnapshot();
353361
});

src/utils/__tests__/isReactCloneElementCall-test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*/
88

9-
import { parse } from '../../../tests/utils';
9+
import { parse, noopImporter } from '../../../tests/utils';
1010
import isReactCloneElementCall from '../isReactCloneElementCall';
1111

1212
describe('isReactCloneElementCall', () => {
@@ -21,63 +21,63 @@ describe('isReactCloneElementCall', () => {
2121
var React = require("React");
2222
React.cloneElement({});
2323
`);
24-
expect(isReactCloneElementCall(def)).toBe(true);
24+
expect(isReactCloneElementCall(def, noopImporter)).toBe(true);
2525
});
2626

2727
it('accepts cloneElement called on aliased React', () => {
2828
const def = parsePath(`
2929
var other = require("React");
3030
other.cloneElement({});
3131
`);
32-
expect(isReactCloneElementCall(def)).toBe(true);
32+
expect(isReactCloneElementCall(def, noopImporter)).toBe(true);
3333
});
3434

3535
it('ignores other React calls', () => {
3636
const def = parsePath(`
3737
var React = require("React");
3838
React.isValidElement({});
3939
`);
40-
expect(isReactCloneElementCall(def)).toBe(false);
40+
expect(isReactCloneElementCall(def, noopImporter)).toBe(false);
4141
});
4242

4343
it('ignores non React calls to cloneElement', () => {
4444
const def = parsePath(`
4545
var React = require("bob");
4646
React.cloneElement({});
4747
`);
48-
expect(isReactCloneElementCall(def)).toBe(false);
48+
expect(isReactCloneElementCall(def, noopImporter)).toBe(false);
4949
});
5050

5151
it('accepts cloneElement called on destructed value', () => {
5252
const def = parsePath(`
5353
var { cloneElement } = require("react");
5454
cloneElement({});
5555
`);
56-
expect(isReactCloneElementCall(def)).toBe(true);
56+
expect(isReactCloneElementCall(def, noopImporter)).toBe(true);
5757
});
5858

5959
it('accepts cloneElement called on destructed aliased value', () => {
6060
const def = parsePath(`
6161
var { cloneElement: foo } = require("react");
6262
foo({});
6363
`);
64-
expect(isReactCloneElementCall(def)).toBe(true);
64+
expect(isReactCloneElementCall(def, noopImporter)).toBe(true);
6565
});
6666

6767
it('accepts cloneElement called on imported value', () => {
6868
const def = parsePath(`
6969
import { cloneElement } from "react";
7070
cloneElement({});
7171
`);
72-
expect(isReactCloneElementCall(def)).toBe(true);
72+
expect(isReactCloneElementCall(def, noopImporter)).toBe(true);
7373
});
7474

7575
it('accepts cloneElement called on imported aliased value', () => {
7676
const def = parsePath(`
7777
import { cloneElement as foo } from "react";
7878
foo({});
7979
`);
80-
expect(isReactCloneElementCall(def)).toBe(true);
80+
expect(isReactCloneElementCall(def, noopImporter)).toBe(true);
8181
});
8282
});
8383
});

0 commit comments

Comments
 (0)