1
1
import React from 'react' ;
2
- import { shallow } from 'enzyme' ;
2
+ import { shallow , mount } from 'enzyme' ;
3
3
4
4
import Link from '../index' ;
5
5
@@ -15,49 +15,65 @@ describe('<Link />', () => {
15
15
} ,
16
16
} ;
17
17
18
- // Clear method spies on prototype before each test
18
+ const mockProps = {
19
+ linkData,
20
+ pathFunc : 'diagonal' ,
21
+ orientation : 'horizontal' ,
22
+ transitionDuration : 500 ,
23
+ } ;
24
+
25
+
26
+ jest . spyOn ( Link . prototype , 'diagonalPath' ) ;
27
+ jest . spyOn ( Link . prototype , 'elbowPath' ) ;
28
+ jest . spyOn ( Link . prototype , 'applyOpacity' ) ;
29
+
30
+ // Clear method spies on prototype after each test
19
31
afterEach ( ( ) => jest . clearAllMocks ( ) ) ;
20
32
21
- it ( 'should apply the base className' , ( ) => {
33
+
34
+ it ( 'applies the base className' , ( ) => {
22
35
const renderedComponent = shallow (
23
- < Link
24
- linkData = { linkData }
25
- pathFunc = "diagonal"
26
- orientation = "horizontal"
27
- />
36
+ < Link { ...mockProps } />
28
37
) ;
29
38
30
39
expect ( renderedComponent . prop ( 'className' ) ) . toBe ( 'linkBase' ) ;
31
40
} ) ;
32
41
33
- it ( 'should call the appropriate path func based on `props.pathFunc`' , ( ) => {
34
- jest . spyOn ( Link . prototype , 'diagonalPath' ) ;
35
- jest . spyOn ( Link . prototype , 'elbowPath' ) ;
42
+
43
+ it ( 'calls the appropriate path func based on `props.pathFunc`' , ( ) => {
36
44
const diagonalComponent = shallow (
37
- < Link
38
- linkData = { linkData }
39
- pathFunc = "diagonal"
40
- orientation = "horizontal"
41
- />
45
+ < Link { ...mockProps } />
42
46
) ;
43
47
const elbowComponent = shallow (
44
48
< Link
45
- linkData = { linkData }
49
+ { ... mockProps }
46
50
pathFunc = "elbow"
47
- orientation = "horizontal"
48
51
/>
49
52
) ;
50
53
51
54
expect ( diagonalComponent . instance ( ) . diagonalPath ) . toHaveBeenCalled ( ) ;
52
55
expect ( elbowComponent . instance ( ) . elbowPath ) . toHaveBeenCalled ( ) ;
53
56
} ) ;
54
57
55
- it ( 'should return an appropriate elbowPath according to `props.orientation`' , ( ) => {
58
+
59
+ it ( 'returns an appropriate elbowPath according to `props.orientation`' , ( ) => {
56
60
expect (
57
61
Link . prototype . elbowPath ( linkData , 'horizontal' )
58
62
) . toBe ( `M${ linkData . source . y } ,${ linkData . source . x } V${ linkData . target . x } H${ linkData . target . y } ` ) ;
59
63
expect (
60
64
Link . prototype . elbowPath ( linkData , 'vertical' )
61
65
) . toBe ( `M${ linkData . source . x } ,${ linkData . source . y } V${ linkData . target . y } H${ linkData . target . x } ` ) ;
62
66
} ) ;
67
+
68
+
69
+ it ( 'fades in once it has been mounted' , ( ) => {
70
+ const fixture = 1 ;
71
+ const renderedComponent = mount (
72
+ < Link { ...mockProps } />
73
+ ) ;
74
+
75
+ expect ( renderedComponent . instance ( ) . applyOpacity ) . toHaveBeenCalledWith ( fixture ) ;
76
+ } ) ;
77
+
78
+ // TODO Find a way to meaningfully test `componentWillLeave`
63
79
} ) ;
0 commit comments