|
6 | 6 | *
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import { statement } from '../../../tests/utils'; |
| 9 | +import { |
| 10 | + statement, |
| 11 | + noopImporter, |
| 12 | + makeMockImporter, |
| 13 | +} from '../../../tests/utils'; |
10 | 14 | import getPropertyValuePath from '../getPropertyValuePath';
|
11 | 15 |
|
12 | 16 | describe('getPropertyValuePath', () => {
|
| 17 | + const mockImporter = makeMockImporter({ |
| 18 | + bar: statement(` |
| 19 | + export default 'bar'; |
| 20 | + `).get('declaration'), |
| 21 | + }); |
| 22 | + |
13 | 23 | it('returns the value path if the property exists', () => {
|
14 | 24 | const objectExpressionPath = statement('({foo: 21, bar: 42})').get(
|
15 | 25 | 'expression',
|
16 | 26 | );
|
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')); |
20 | 40 | });
|
21 | 41 |
|
22 | 42 | it('returns undefined if the property does not exist', () => {
|
23 | 43 | const objectExpressionPath = statement('({foo: 21, bar: 42})').get(
|
24 | 44 | 'expression',
|
25 | 45 | );
|
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')); |
27 | 59 | });
|
28 | 60 | });
|
0 commit comments