|
| 1 | +import { expression, noopImporter } from '../../../tests/utils'; |
| 2 | +import { Array as expressionToArray } from '../expressionTo'; |
| 3 | + |
| 4 | +describe('expressionTo', () => { |
| 5 | + describe('MemberExpression', () => { |
| 6 | + it('with only identifiers', () => { |
| 7 | + expect( |
| 8 | + expressionToArray(expression('foo.bar.baz'), noopImporter), |
| 9 | + ).toEqual(['foo', 'bar', 'baz']); |
| 10 | + }); |
| 11 | + |
| 12 | + it('with one computed literal', () => { |
| 13 | + expect( |
| 14 | + expressionToArray(expression('foo["bar"].baz'), noopImporter), |
| 15 | + ).toEqual(['foo', '"bar"', 'baz']); |
| 16 | + }); |
| 17 | + |
| 18 | + it('with one computed identifier', () => { |
| 19 | + expect( |
| 20 | + expressionToArray(expression('foo[bar].baz'), noopImporter), |
| 21 | + ).toEqual(['foo', 'bar', 'baz']); |
| 22 | + }); |
| 23 | + |
| 24 | + it('with one computed object', () => { |
| 25 | + expect( |
| 26 | + expressionToArray(expression('foo[{ a: "true"}].baz'), noopImporter), |
| 27 | + ).toEqual(['foo', '{a: "true"}', 'baz']); |
| 28 | + }); |
| 29 | + |
| 30 | + it('with one computed object with spread', () => { |
| 31 | + expect( |
| 32 | + expressionToArray(expression('foo[{ ...a }].baz'), noopImporter), |
| 33 | + ).toEqual(['foo', '{...a}', 'baz']); |
| 34 | + }); |
| 35 | + |
| 36 | + it('with one computed object with method', () => { |
| 37 | + expect( |
| 38 | + expressionToArray(expression('foo[{ a(){} }].baz'), noopImporter), |
| 39 | + ).toEqual(['foo', '{a: <function>}', 'baz']); |
| 40 | + }); |
| 41 | + }); |
| 42 | +}); |
0 commit comments