Skip to content

Commit ad1e61a

Browse files
phateddanez
authored andcommitted
Add importer tests for isReactComponentMethod
1 parent c024843 commit ad1e61a

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/utils/__tests__/isReactComponentMethod-test.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,56 @@
66
*
77
*/
88

9-
import { expression, statement } from '../../../tests/utils';
9+
import {
10+
expression,
11+
statement,
12+
noopImporter,
13+
makeMockImporter,
14+
} from '../../../tests/utils';
1015
import isReactComponentMethod from '../isReactComponentMethod';
1116

1217
describe('isReactComponentMethod', () => {
18+
const mockImporter = makeMockImporter({
19+
foo: statement(`
20+
export default 'render';
21+
`).get('declaration'),
22+
});
23+
1324
it('returns true if the method is a component class method', () => {
1425
const def = statement('class Foo { render() {}}');
1526
const method = def.get('body', 'body', 0);
16-
expect(isReactComponentMethod(method)).toBe(true);
27+
expect(isReactComponentMethod(method, noopImporter)).toBe(true);
1728
});
1829

1930
it('returns true if the method is a component `createClass` object method', () => {
2031
const def = expression('{ render() {}}');
2132
const method = def.get('properties', 0);
22-
expect(isReactComponentMethod(method)).toBe(true);
33+
expect(isReactComponentMethod(method, noopImporter)).toBe(true);
2334
});
2435

2536
it('returns false if the method is not a component class method', () => {
2637
const def = statement('class Foo { bar() {}}');
2738
const method = def.get('body', 'body', 0);
28-
expect(isReactComponentMethod(method)).toBe(false);
39+
expect(isReactComponentMethod(method, noopImporter)).toBe(false);
2940
});
3041

3142
it('returns false if the method is not a component `createClass` object method', () => {
3243
const def = expression('{ bar() {}}');
3344
const method = def.get('properties', 0);
34-
expect(isReactComponentMethod(method)).toBe(false);
45+
expect(isReactComponentMethod(method, noopImporter)).toBe(false);
3546
});
3647

3748
it('returns false if the path is not a method or object property', () => {
3849
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);
4060
});
4161
});

0 commit comments

Comments
 (0)