|
6 | 6 | *
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import { expression, statement } from '../../../tests/utils'; |
| 9 | +import { |
| 10 | + expression, |
| 11 | + statement, |
| 12 | + noopImporter, |
| 13 | + makeMockImporter, |
| 14 | +} from '../../../tests/utils'; |
10 | 15 | import isReactComponentMethod from '../isReactComponentMethod';
|
11 | 16 |
|
12 | 17 | describe('isReactComponentMethod', () => {
|
| 18 | + const mockImporter = makeMockImporter({ |
| 19 | + foo: statement(` |
| 20 | + export default 'render'; |
| 21 | + `).get('declaration'), |
| 22 | + }); |
| 23 | + |
13 | 24 | it('returns true if the method is a component class method', () => {
|
14 | 25 | const def = statement('class Foo { render() {}}');
|
15 | 26 | const method = def.get('body', 'body', 0);
|
16 |
| - expect(isReactComponentMethod(method)).toBe(true); |
| 27 | + expect(isReactComponentMethod(method, noopImporter)).toBe(true); |
17 | 28 | });
|
18 | 29 |
|
19 | 30 | it('returns true if the method is a component `createClass` object method', () => {
|
20 | 31 | const def = expression('{ render() {}}');
|
21 | 32 | const method = def.get('properties', 0);
|
22 |
| - expect(isReactComponentMethod(method)).toBe(true); |
| 33 | + expect(isReactComponentMethod(method, noopImporter)).toBe(true); |
23 | 34 | });
|
24 | 35 |
|
25 | 36 | it('returns false if the method is not a component class method', () => {
|
26 | 37 | const def = statement('class Foo { bar() {}}');
|
27 | 38 | const method = def.get('body', 'body', 0);
|
28 |
| - expect(isReactComponentMethod(method)).toBe(false); |
| 39 | + expect(isReactComponentMethod(method, noopImporter)).toBe(false); |
29 | 40 | });
|
30 | 41 |
|
31 | 42 | it('returns false if the method is not a component `createClass` object method', () => {
|
32 | 43 | const def = expression('{ bar() {}}');
|
33 | 44 | const method = def.get('properties', 0);
|
34 |
| - expect(isReactComponentMethod(method)).toBe(false); |
| 45 | + expect(isReactComponentMethod(method, noopImporter)).toBe(false); |
35 | 46 | });
|
36 | 47 |
|
37 | 48 | it('returns false if the path is not a method or object property', () => {
|
38 | 49 | const def = statement('let foo = "bar";');
|
39 |
| - expect(isReactComponentMethod(def)).toBe(false); |
| 50 | + expect(isReactComponentMethod(def, noopImporter)).toBe(false); |
| 51 | + }); |
| 52 | + |
| 53 | + it('resolves imported value of computed property', () => { |
| 54 | + const def = statement(` |
| 55 | + class Foo { [foo]() {}} |
| 56 | + import foo from 'foo'; |
| 57 | + `); |
| 58 | + const method = def.get('body', 'body', 0); |
| 59 | + expect(isReactComponentMethod(method, mockImporter)).toBe(true); |
40 | 60 | });
|
41 | 61 | });
|
0 commit comments