Skip to content

Commit dd08e16

Browse files
phateddanez
authored andcommitted
Add importer tests for getPropertyValuePath
1 parent 4499c44 commit dd08e16

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

src/utils/__tests__/getPropertyValuePath-test.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,55 @@
66
*
77
*/
88

9-
import { statement } from '../../../tests/utils';
9+
import {
10+
statement,
11+
noopImporter,
12+
makeMockImporter,
13+
} from '../../../tests/utils';
1014
import getPropertyValuePath from '../getPropertyValuePath';
1115

1216
describe('getPropertyValuePath', () => {
17+
const mockImporter = makeMockImporter({
18+
bar: statement(`
19+
export default 'bar';
20+
`).get('declaration'),
21+
});
22+
1323
it('returns the value path if the property exists', () => {
1424
const objectExpressionPath = statement('({foo: 21, bar: 42})').get(
1525
'expression',
1626
);
17-
expect(getPropertyValuePath(objectExpressionPath, 'bar')).toBe(
18-
objectExpressionPath.get('properties', 1).get('value'),
19-
);
27+
expect(
28+
getPropertyValuePath(objectExpressionPath, 'bar', noopImporter),
29+
).toBe(objectExpressionPath.get('properties', 1).get('value'));
30+
});
31+
32+
it('returns the value path for a computed property in scope', () => {
33+
const objectExpressionPath = statement(`
34+
({foo: 21, [a]: 42});
35+
var a = 'bar';
36+
`).get('expression');
37+
expect(
38+
getPropertyValuePath(objectExpressionPath, 'bar', noopImporter),
39+
).toBe(objectExpressionPath.get('properties', 1).get('value'));
2040
});
2141

2242
it('returns undefined if the property does not exist', () => {
2343
const objectExpressionPath = statement('({foo: 21, bar: 42})').get(
2444
'expression',
2545
);
26-
expect(getPropertyValuePath(objectExpressionPath, 'baz')).toBeUndefined();
46+
expect(
47+
getPropertyValuePath(objectExpressionPath, 'baz', noopImporter),
48+
).toBeUndefined();
49+
});
50+
51+
it('returns the value path for a computed property that was imported', () => {
52+
const objectExpressionPath = statement(`
53+
({foo: 21, [a]: 42});
54+
import a from 'bar';
55+
`).get('expression');
56+
expect(
57+
getPropertyValuePath(objectExpressionPath, 'bar', mockImporter),
58+
).toBe(objectExpressionPath.get('properties', 1).get('value'));
2759
});
2860
});

0 commit comments

Comments
 (0)