Skip to content

Commit 0946e6d

Browse files
phateddanez
authored andcommitted
Add importer test for isStatelessComponent
1 parent 5e04bf4 commit 0946e6d

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/utils/__tests__/isStatelessComponent-test.js

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

9-
import { parse, statement, noopImporter } from '../../../tests/utils';
9+
import {
10+
parse,
11+
statement,
12+
noopImporter,
13+
makeMockImporter,
14+
} from '../../../tests/utils';
1015
import isStatelessComponent from '../isStatelessComponent';
1116

1217
describe('isStatelessComponent', () => {
@@ -213,14 +218,20 @@ describe('isStatelessComponent', () => {
213218
});
214219

215220
describe('resolving return values', () => {
216-
function test(desc, code) {
221+
function test(desc, code, importer = noopImporter) {
217222
it(desc, () => {
218223
const def = parse(code).get('body', 1);
219224

220-
expect(isStatelessComponent(def, noopImporter)).toBe(true);
225+
expect(isStatelessComponent(def, importer)).toBe(true);
221226
});
222227
}
223228

229+
const mockImporter = makeMockImporter({
230+
bar: statement(`
231+
export default <div />;
232+
`).get('declaration'),
233+
});
234+
224235
it('does not see ifs as separate block', () => {
225236
const def = statement(`
226237
function Foo (props) {
@@ -338,5 +349,16 @@ describe('isStatelessComponent', () => {
338349
}
339350
`,
340351
);
352+
353+
test(
354+
'resolves imported values as return',
355+
`
356+
import bar from 'bar';
357+
function Foo (props) {
358+
return bar;
359+
}
360+
`,
361+
mockImporter,
362+
);
341363
});
342364
});

0 commit comments

Comments
 (0)