6
6
*
7
7
*/
8
8
9
- import { parse , noopImporter } from '../../../tests/utils' ;
9
+ import {
10
+ parse ,
11
+ statement ,
12
+ noopImporter ,
13
+ makeMockImporter ,
14
+ } from '../../../tests/utils' ;
10
15
import isReactCreateClassCall from '../isReactCreateClassCall' ;
11
16
12
17
describe ( 'isReactCreateClassCall' , ( ) => {
@@ -15,6 +20,18 @@ describe('isReactCreateClassCall', () => {
15
20
return root . get ( 'body' , root . node . body . length - 1 , 'expression' ) ;
16
21
}
17
22
23
+ const mockImporter = makeMockImporter ( {
24
+ foo : statement ( `
25
+ export default React.createClass;
26
+ import React from 'react';
27
+ ` ) . get ( 'declaration' ) ,
28
+
29
+ bar : statement ( `
30
+ export default makeClass;
31
+ import makeClass from "create-react-class";
32
+ ` ) . get ( 'declaration' ) ,
33
+ } ) ;
34
+
18
35
describe ( 'built in React.createClass' , ( ) => {
19
36
it ( 'accepts createClass called on React' , ( ) => {
20
37
const def = parsePath ( `
@@ -85,6 +102,14 @@ describe('isReactCreateClassCall', () => {
85
102
` ) ;
86
103
expect ( isReactCreateClassCall ( def , noopImporter ) ) . toBe ( true ) ;
87
104
} ) ;
105
+
106
+ it ( 'resolves createClass imported from intermediate module' , ( ) => {
107
+ const def = parsePath ( `
108
+ import foo from "foo";
109
+ foo({});
110
+ ` ) ;
111
+ expect ( isReactCreateClassCall ( def , mockImporter ) ) . toBe ( true ) ;
112
+ } ) ;
88
113
} ) ;
89
114
90
115
describe ( 'modular in create-react-class' , ( ) => {
@@ -117,5 +142,13 @@ describe('isReactCreateClassCall', () => {
117
142
` ) ;
118
143
expect ( isReactCreateClassCall ( def , noopImporter ) ) . toBe ( false ) ;
119
144
} ) ;
145
+
146
+ it ( 'resolves create-react-class imported from intermediate module' , ( ) => {
147
+ const def = parsePath ( `
148
+ import bar from "bar";
149
+ bar({});
150
+ ` ) ;
151
+ expect ( isReactCreateClassCall ( def , mockImporter ) ) . toBe ( true ) ;
152
+ } ) ;
120
153
} ) ;
121
154
} ) ;
0 commit comments