@@ -42,46 +42,38 @@ describe('React', () => {
42
42
}
43
43
} )
44
44
45
- const component1 = props => {
46
- renderSpy1 ( )
47
-
48
- return < Component2 list = { props . list } />
49
- }
50
-
51
- const Component1 = component1Decorator ( component1 )
52
-
53
- const renderSpy2 = jest . fn ( )
54
-
55
- const Component2 = props => {
45
+ const component2 = props => {
56
46
const [ state , setState ] = React . useState ( { list : props . list } )
57
47
58
48
React . useEffect ( ( ) => {
59
- setState ( { list : props . list } )
49
+ setState ( prevState => ( { ... prevState , list : props . list } ) )
60
50
} , [ props . list ] )
61
51
62
- renderSpy2 ( )
52
+ renderSpy1 ( )
63
53
64
- return < Component3 list = { state . list } />
54
+ return < Component2 list = { state . list } />
65
55
}
66
56
67
- const mapStateSpy3 = jest . fn ( )
68
- const renderSpy3 = jest . fn ( )
57
+ const Component1 = component1Decorator ( component2 )
58
+
59
+ const mapStateSpy2 = jest . fn ( )
60
+ const renderSpy2 = jest . fn ( )
69
61
70
- const component3Decorator = connect ( ( state , ownProps ) => {
71
- mapStateSpy3 ( )
62
+ const component2Decorator = connect ( ( state , ownProps ) => {
63
+ mapStateSpy2 ( )
72
64
73
65
return {
74
66
mappedProp : ownProps . list . map ( id => state . byId [ id ] )
75
67
}
76
68
} )
77
69
78
70
const component3 = ( ) => {
79
- renderSpy3 ( )
71
+ renderSpy2 ( )
80
72
81
73
return < div > Hello</ div >
82
74
}
83
75
84
- const Component3 = component3Decorator ( component3 )
76
+ const Component2 = component2Decorator ( component3 )
85
77
86
78
rtl . render (
87
79
< ProviderMock store = { store } >
@@ -90,20 +82,18 @@ describe('React', () => {
90
82
)
91
83
92
84
expect ( mapStateSpy1 ) . toHaveBeenCalledTimes ( 1 )
93
- expect ( renderSpy1 ) . toHaveBeenCalledTimes ( 1 )
94
- expect ( renderSpy2 ) . toHaveBeenCalledTimes ( 2 )
95
- expect ( mapStateSpy3 ) . toHaveBeenCalledTimes ( 1 )
96
- expect ( renderSpy3 ) . toHaveBeenCalledTimes ( 1 )
85
+ expect ( renderSpy1 ) . toHaveBeenCalledTimes ( 2 )
86
+ expect ( mapStateSpy2 ) . toHaveBeenCalledTimes ( 1 )
87
+ expect ( renderSpy2 ) . toHaveBeenCalledTimes ( 1 )
97
88
98
89
rtl . act ( ( ) => {
99
90
store . dispatch ( { type : 'FOO' } )
100
91
} )
101
92
102
93
expect ( mapStateSpy1 ) . toHaveBeenCalledTimes ( 2 )
103
- expect ( renderSpy1 ) . toHaveBeenCalledTimes ( 2 )
104
- expect ( renderSpy2 ) . toHaveBeenCalledTimes ( 4 )
105
- expect ( mapStateSpy3 ) . toHaveBeenCalledTimes ( 3 )
106
- expect ( renderSpy3 ) . toHaveBeenCalledTimes ( 3 )
94
+ expect ( renderSpy1 ) . toHaveBeenCalledTimes ( 4 )
95
+ expect ( mapStateSpy2 ) . toHaveBeenCalledTimes ( 3 )
96
+ expect ( renderSpy2 ) . toHaveBeenCalledTimes ( 3 )
107
97
} )
108
98
} )
109
99
} )
0 commit comments