@@ -19,7 +19,9 @@ describe('extendsHandler', () => {
19
19
resolveRequiredMock = resolveRequired as jest . Mock <
20
20
( ast : bt . File , varNameFilter ?: string [ ] ) => { [ key : string ] : string }
21
21
>
22
- resolveRequiredMock . mockReturnValue ( { testComponent : './componentPath' } )
22
+ resolveRequiredMock . mockReturnValue ( {
23
+ testComponent : { filePath : './componentPath' , exportName : 'default' } ,
24
+ } )
23
25
24
26
mockResolvePathFrom = resolvePathFrom as jest . Mock < ( path : string , from : string ) => string >
25
27
mockResolvePathFrom . mockReturnValue ( './component/full/path' )
@@ -30,8 +32,10 @@ describe('extendsHandler', () => {
30
32
31
33
function parseItExtends ( src : string ) {
32
34
const ast = babylon ( ) . parse ( src )
33
- const path = resolveExportedComponent ( ast )
34
- extendsHandler ( doc , path [ 0 ] , ast , '' )
35
+ const path = resolveExportedComponent ( ast ) . get ( 'default' )
36
+ if ( path ) {
37
+ extendsHandler ( doc , path , ast , '' )
38
+ }
35
39
}
36
40
37
41
it ( 'should resolve extended modules variables in import default' , ( ) => {
@@ -42,7 +46,7 @@ describe('extendsHandler', () => {
42
46
'}' ,
43
47
] . join ( '\n' )
44
48
parseItExtends ( src )
45
- expect ( parseFile ) . toHaveBeenCalledWith ( './component/full/path' , doc )
49
+ expect ( parseFile ) . toHaveBeenCalledWith ( './component/full/path' , doc , [ 'default' ] )
46
50
} )
47
51
48
52
it ( 'should resolve extended modules variables in require' , ( ) => {
@@ -53,27 +57,28 @@ describe('extendsHandler', () => {
53
57
'}' ,
54
58
] . join ( '\n' )
55
59
parseItExtends ( src )
56
- expect ( parseFile ) . toHaveBeenCalledWith ( './component/full/path' , doc )
60
+ expect ( parseFile ) . toHaveBeenCalledWith ( './component/full/path' , doc , [ 'default' ] )
57
61
} )
58
62
59
63
it ( 'should resolve extended modules variables in import' , ( ) => {
60
64
const src = [
61
- 'import { testComponent, other } from "./testComponent"' ,
65
+ 'import { test as testComponent, other } from "./testComponent"' ,
62
66
'export default {' ,
63
67
' extends:testComponent' ,
64
68
'}' ,
65
69
] . join ( '\n' )
66
70
parseItExtends ( src )
67
- expect ( parseFile ) . toHaveBeenCalledWith ( './component/full/path' , doc )
71
+ expect ( parseFile ) . toHaveBeenCalledWith ( './component/full/path' , doc , [ 'default' ] )
68
72
} )
69
73
70
74
it ( 'should resolve extended modules variables in class style components' , ( ) => {
71
75
const src = [
72
- 'import { testComponent} from "./testComponent"' ,
76
+ 'import { testComponent } from "./testComponent";' ,
77
+ '@Component' ,
73
78
'export default class Bart extends testComponent {' ,
74
79
'}' ,
75
80
] . join ( '\n' )
76
81
parseItExtends ( src )
77
- expect ( parseFile ) . toHaveBeenCalledWith ( './component/full/path' , doc )
82
+ expect ( parseFile ) . toHaveBeenCalledWith ( './component/full/path' , doc , [ 'default' ] )
78
83
} )
79
84
} )
0 commit comments