@@ -19,33 +19,58 @@ describe('resolveHOC', () => {
19
19
}
20
20
21
21
it ( 'resolves simple hoc' , ( ) => {
22
- const path = parse ( [ 'hoc(42 );' ] . join ( '\n' ) ) ;
23
- expect ( resolveHOC ( path ) ) . toEqualASTNode ( builders . literal ( 42 ) ) ;
22
+ const path = parse ( [ 'hoc(Component );' ] . join ( '\n' ) ) ;
23
+ expect ( resolveHOC ( path ) ) . toEqualASTNode ( builders . identifier ( 'Component' ) ) ;
24
24
} ) ;
25
25
26
26
it ( 'resolves simple hoc w/ multiple args' , ( ) => {
27
- const path = parse ( [ 'hoc1(arg1a, arg1b)(42 );' ] . join ( '\n' ) ) ;
28
- expect ( resolveHOC ( path ) ) . toEqualASTNode ( builders . literal ( 42 ) ) ;
27
+ const path = parse ( [ 'hoc1(arg1a, arg1b)(Component );' ] . join ( '\n' ) ) ;
28
+ expect ( resolveHOC ( path ) ) . toEqualASTNode ( builders . identifier ( 'Component' ) ) ;
29
29
} ) ;
30
30
31
31
it ( 'resolves nested hocs' , ( ) => {
32
32
const path = parse (
33
- [ 'hoc2(arg2b, arg2b)(' , ' hoc1(arg1a, arg2a)(42)' , ');' ] . join ( '\n' ) ,
33
+ `hoc2(arg2b, arg2b)(
34
+ hoc1(arg1a, arg2a)(Component)
35
+ );` ,
34
36
) ;
35
- expect ( resolveHOC ( path ) ) . toEqualASTNode ( builders . literal ( 42 ) ) ;
37
+ expect ( resolveHOC ( path ) ) . toEqualASTNode ( builders . identifier ( 'Component' ) ) ;
36
38
} ) ;
37
39
38
40
it ( 'resolves really nested hocs' , ( ) => {
39
41
const path = parse (
40
- [
41
- 'hoc3(arg3a, arg3b)(' ,
42
- ' hoc2(arg2b, arg2b)(' ,
43
- ' hoc1(arg1a, arg2a)(42)' ,
44
- ' )' ,
45
- ');' ,
46
- ] . join ( '\n' ) ,
42
+ `hoc3(arg3a, arg3b)(
43
+ hoc2(arg2b, arg2b)(
44
+ hoc1(arg1a, arg2a)(Component)
45
+ )
46
+ );` ,
47
47
) ;
48
- expect ( resolveHOC ( path ) ) . toEqualASTNode ( builders . literal ( 42 ) ) ;
48
+ expect ( resolveHOC ( path ) ) . toEqualASTNode ( builders . identifier ( 'Component' ) ) ;
49
+ } ) ;
50
+
51
+ it ( 'resolves HOC with additional params' , ( ) => {
52
+ const path = parse ( `hoc3(Component, {})` ) ;
53
+ expect ( resolveHOC ( path ) ) . toEqualASTNode ( builders . identifier ( 'Component' ) ) ;
54
+ } ) ;
55
+
56
+ it ( 'resolves HOC as last element if first is literal' , ( ) => {
57
+ const path = parse ( `hoc3(41, Component)` ) ;
58
+ expect ( resolveHOC ( path ) ) . toEqualASTNode ( builders . identifier ( 'Component' ) ) ;
59
+ } ) ;
60
+
61
+ it ( 'resolves HOC as last element if first is array' , ( ) => {
62
+ const path = parse ( `hoc3([], Component)` ) ;
63
+ expect ( resolveHOC ( path ) ) . toEqualASTNode ( builders . identifier ( 'Component' ) ) ;
64
+ } ) ;
65
+
66
+ it ( 'resolves HOC as last element if first is object' , ( ) => {
67
+ const path = parse ( `hoc3({}, Component)` ) ;
68
+ expect ( resolveHOC ( path ) ) . toEqualASTNode ( builders . identifier ( 'Component' ) ) ;
69
+ } ) ;
70
+
71
+ it ( 'resolves HOC as last element if first is spread' , ( ) => {
72
+ const path = parse ( `hoc3(...params, Component)` ) ;
73
+ expect ( resolveHOC ( path ) ) . toEqualASTNode ( builders . identifier ( 'Component' ) ) ;
49
74
} ) ;
50
75
51
76
it ( 'resolves intermediate hocs' , ( ) => {
0 commit comments