Skip to content

Commit 146c8ff

Browse files
phateddanez
authored andcommitted
Add importer tests for resolveToModule
1 parent ada2b1b commit 146c8ff

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/utils/__tests__/resolveToModule-test.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
*
77
*/
88

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

1217
describe('resolveToModule', () => {
@@ -15,6 +20,18 @@ describe('resolveToModule', () => {
1520
return root.get('body', root.node.body.length - 1, 'expression');
1621
}
1722

23+
const mockImporter = makeMockImporter({
24+
Foo: statement(`
25+
export default bar;
26+
import bar from 'Bar';
27+
`).get('declaration'),
28+
29+
Bar: statement(`
30+
export default baz;
31+
import baz from 'Baz';
32+
`).get('declaration'),
33+
});
34+
1835
it('resolves identifiers', () => {
1936
const path = parsePath(`
2037
var foo = require("Foo");
@@ -85,5 +102,13 @@ describe('resolveToModule', () => {
85102
`);
86103
expect(resolveToModule(path, noopImporter)).toBe('Foo');
87104
});
105+
106+
it('can resolve imports until one not expanded', () => {
107+
const path = parsePath(`
108+
import foo from "Foo";
109+
foo;
110+
`);
111+
expect(resolveToModule(path, mockImporter)).toBe('Baz');
112+
});
88113
});
89114
});

0 commit comments

Comments
 (0)