@@ -42,46 +42,38 @@ describe('React', () => {
4242 }
4343 } )
4444
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 => {
5646 const [ state , setState ] = React . useState ( { list : props . list } )
5747
5848 React . useEffect ( ( ) => {
59- setState ( { list : props . list } )
49+ setState ( prevState => ( { ... prevState , list : props . list } ) )
6050 } , [ props . list ] )
6151
62- renderSpy2 ( )
52+ renderSpy1 ( )
6353
64- return < Component3 list = { state . list } />
54+ return < Component2 list = { state . list } />
6555 }
6656
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 ( )
6961
70- const component3Decorator = connect ( ( state , ownProps ) => {
71- mapStateSpy3 ( )
62+ const component2Decorator = connect ( ( state , ownProps ) => {
63+ mapStateSpy2 ( )
7264
7365 return {
7466 mappedProp : ownProps . list . map ( id => state . byId [ id ] )
7567 }
7668 } )
7769
7870 const component3 = ( ) => {
79- renderSpy3 ( )
71+ renderSpy2 ( )
8072
8173 return < div > Hello</ div >
8274 }
8375
84- const Component3 = component3Decorator ( component3 )
76+ const Component2 = component2Decorator ( component3 )
8577
8678 rtl . render (
8779 < ProviderMock store = { store } >
@@ -90,20 +82,18 @@ describe('React', () => {
9082 )
9183
9284 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 )
9788
9889 rtl . act ( ( ) => {
9990 store . dispatch ( { type : 'FOO' } )
10091 } )
10192
10293 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 )
10797 } )
10898 } )
10999} )
0 commit comments