@@ -286,7 +286,7 @@ export const withPromiseFn = (Async, abortCtrl) => () => {
286
286
expect ( abortCtrl . abort ) . toHaveBeenCalledTimes ( 1 )
287
287
} )
288
288
289
- test ( "re-runs the promise when the value of `watch` changes" , ( ) => {
289
+ test ( "re-runs the promise with new props when the value of `watch` changes" , ( ) => {
290
290
class Counter extends React . Component {
291
291
constructor ( props ) {
292
292
super ( props )
@@ -304,19 +304,31 @@ export const withPromiseFn = (Async, abortCtrl) => () => {
304
304
}
305
305
const promiseFn = jest . fn ( ) . mockReturnValue ( resolveTo ( ) )
306
306
const { getByText } = render (
307
- < Counter > { count => < Async promiseFn = { promiseFn } watch = { count } /> } </ Counter >
307
+ < Counter > { count => < Async promiseFn = { promiseFn } watch = { count } count = { count } /> } </ Counter >
308
308
)
309
309
expect ( promiseFn ) . toHaveBeenCalledTimes ( 1 )
310
+ expect ( promiseFn ) . toHaveBeenLastCalledWith (
311
+ expect . objectContaining ( { count : 0 } ) ,
312
+ expect . any ( Object )
313
+ )
310
314
fireEvent . click ( getByText ( "increment" ) )
311
315
expect ( promiseFn ) . toHaveBeenCalledTimes ( 2 )
316
+ expect ( promiseFn ) . toHaveBeenLastCalledWith (
317
+ expect . objectContaining ( { count : 1 } ) ,
318
+ expect . any ( Object )
319
+ )
312
320
expect ( abortCtrl . abort ) . toHaveBeenCalled ( )
313
321
abortCtrl . abort . mockClear ( )
314
322
fireEvent . click ( getByText ( "increment" ) )
315
323
expect ( promiseFn ) . toHaveBeenCalledTimes ( 3 )
324
+ expect ( promiseFn ) . toHaveBeenLastCalledWith (
325
+ expect . objectContaining ( { count : 2 } ) ,
326
+ expect . any ( Object )
327
+ )
316
328
expect ( abortCtrl . abort ) . toHaveBeenCalled ( )
317
329
} )
318
330
319
- test ( "re-runs the promise when `watchFn` returns truthy" , ( ) => {
331
+ test ( "re-runs the promise with new props when `watchFn` returns truthy" , ( ) => {
320
332
class Counter extends React . Component {
321
333
constructor ( props ) {
322
334
super ( props )
@@ -338,11 +350,23 @@ export const withPromiseFn = (Async, abortCtrl) => () => {
338
350
< Counter > { count => < Async promiseFn = { promiseFn } watchFn = { watchFn } count = { count } /> } </ Counter >
339
351
)
340
352
expect ( promiseFn ) . toHaveBeenCalledTimes ( 1 )
353
+ expect ( promiseFn ) . toHaveBeenLastCalledWith (
354
+ expect . objectContaining ( { count : 0 } ) ,
355
+ expect . any ( Object )
356
+ )
341
357
fireEvent . click ( getByText ( "increment" ) )
342
358
expect ( promiseFn ) . toHaveBeenCalledTimes ( 1 )
359
+ expect ( promiseFn ) . toHaveBeenLastCalledWith (
360
+ expect . objectContaining ( { count : 0 } ) ,
361
+ expect . any ( Object )
362
+ )
343
363
expect ( abortCtrl . abort ) . not . toHaveBeenCalled ( )
344
364
fireEvent . click ( getByText ( "increment" ) )
345
365
expect ( promiseFn ) . toHaveBeenCalledTimes ( 2 )
366
+ expect ( promiseFn ) . toHaveBeenLastCalledWith (
367
+ expect . objectContaining ( { count : 2 } ) ,
368
+ expect . any ( Object )
369
+ )
346
370
expect ( abortCtrl . abort ) . toHaveBeenCalled ( )
347
371
} )
348
372
0 commit comments