@@ -134,6 +134,44 @@ describe('setup', () => {
134134 test ( 'should not call fn()' , ( ) => expect ( fn ) . toHaveBeenCalledTimes ( 4 ) ) ;
135135 test ( 'return value should be undefined' , ( ) => expect ( useReduceActivities ) . toHaveLastReturnedWith ( undefined ) ) ;
136136 } ) ;
137+
138+ describe ( 'when the third activity is being replaced' , ( ) => {
139+ let fourthActivity : WebChatActivity ;
140+
141+ beforeEach ( ( ) => {
142+ fourthActivity = { ...ACTIVITY_TEMPLATE , id : 'a-00004' , text : 'Good morning!' } ;
143+
144+ useActivities . mockImplementationOnce ( ( ) => [ [ firstActivity , fourthActivity , secondActivity ] ] ) ;
145+
146+ renderResult . rerender ( < HookApp fn = { fn } /> ) ;
147+ } ) ;
148+
149+ describe ( 'fn() should have been called' , ( ) => {
150+ // It should call 2 more times because the first one should be from cache.
151+ test ( '6 times in total' , ( ) => expect ( fn ) . toHaveBeenCalledTimes ( 6 ) ) ;
152+
153+ test ( 'with the fourth activity on 5rd call' , ( ) =>
154+ expect ( fn ) . toHaveBeenNthCalledWith (
155+ 5 ,
156+ { maxText : 'Aloha!' } ,
157+ fourthActivity ,
158+ 1 ,
159+ expect . arrayContaining ( [ ] )
160+ ) ) ;
161+
162+ test ( 'with the second activity on 6th call' , ( ) =>
163+ expect ( fn ) . toHaveBeenNthCalledWith (
164+ 6 ,
165+ { maxText : 'Good morning!' } ,
166+ secondActivity ,
167+ 2 ,
168+ expect . arrayContaining ( [ ] )
169+ ) ) ;
170+
171+ test ( 'return value should be derived from the second activity' , ( ) =>
172+ expect ( useReduceActivities ) . toHaveLastReturnedWith ( { maxText : 'Hello, World!' } ) ) ;
173+ } ) ;
174+ } ) ;
137175 } ) ;
138176
139177 describe ( 'when the first activity is removed' , ( ) => {
0 commit comments