|
| 1 | +import { parse } from '../../../tests/utils'; |
| 2 | +import isDestructuringAssignment from '../isDestructuringAssignment'; |
| 3 | + |
| 4 | +describe('isDestructuringAssignment', () => { |
| 5 | + it('detects destructuring', () => { |
| 6 | + const def = parse(` |
| 7 | + var { Component } = require('react'); |
| 8 | + `).get('body', 0, 'declarations', 0, 'id', 'properties', 0, 'key'); |
| 9 | + |
| 10 | + expect(isDestructuringAssignment(def, 'Component')).toBe(true); |
| 11 | + }); |
| 12 | + |
| 13 | + it('fails if name does not match', () => { |
| 14 | + const def = parse(` |
| 15 | + var { Component } = require('react'); |
| 16 | + `).get('body', 0, 'declarations', 0, 'id', 'properties', 0, 'key'); |
| 17 | + |
| 18 | + expect(isDestructuringAssignment(def, 'Component2')).toBe(false); |
| 19 | + }); |
| 20 | + |
| 21 | + it('detects destructuring with alias', () => { |
| 22 | + const def = parse(` |
| 23 | + var { Component: C } = require('react'); |
| 24 | + `).get('body', 0, 'declarations', 0, 'id', 'properties', 0, 'value'); |
| 25 | + |
| 26 | + expect(isDestructuringAssignment(def, 'Component')).toBe(true); |
| 27 | + }); |
| 28 | + |
| 29 | + it('fails if name does not match with alias', () => { |
| 30 | + const def = parse(` |
| 31 | + var { Component: C } = require('react'); |
| 32 | + `).get('body', 0, 'declarations', 0, 'id', 'properties', 0, 'value'); |
| 33 | + |
| 34 | + expect(isDestructuringAssignment(def, 'Component2')).toBe(false); |
| 35 | + }); |
| 36 | +}); |
0 commit comments