@@ -460,4 +460,46 @@ describe("createInstance", () => {
460
460
await waitForElement ( ( ) => getByText ( "loading" ) )
461
461
await waitForElement ( ( ) => getByText ( "resolved" ) )
462
462
} )
463
+
464
+ test ( "custom instance also passes defaultProps to deferFn" , async ( ) => {
465
+ const deferFn = jest . fn ( ) . mockReturnValue ( resolveTo ( ) )
466
+ const CustomAsync = createInstance ( { deferFn } )
467
+
468
+ let counter = 1
469
+ const { getByText } = render (
470
+ < CustomAsync foo = "bar" >
471
+ { ( { run } ) => < button onClick = { ( ) => run ( "go" , counter ++ ) } > run</ button > }
472
+ </ CustomAsync >
473
+ )
474
+ const expectedProps = { deferFn, foo : "bar" }
475
+ expect ( deferFn ) . not . toHaveBeenCalled ( )
476
+ fireEvent . click ( getByText ( "run" ) )
477
+ expect ( deferFn ) . toHaveBeenCalledWith ( "go" , 1 , expect . objectContaining ( expectedProps ) , abortCtrl )
478
+ fireEvent . click ( getByText ( "run" ) )
479
+ expect ( deferFn ) . toHaveBeenCalledWith ( "go" , 2 , expect . objectContaining ( expectedProps ) , abortCtrl )
480
+ } )
481
+
482
+ test ( "custom instance correctly passes props to deferFn on reload" , async ( ) => {
483
+ const deferFn = jest . fn ( ) . mockReturnValue ( resolveTo ( ) )
484
+ const CustomAsync = createInstance ( { deferFn } )
485
+
486
+ let counter = 1
487
+ const { getByText } = render (
488
+ < CustomAsync foo = "bar" >
489
+ { ( { run, reload } ) =>
490
+ counter === 1 ? (
491
+ < button onClick = { ( ) => run ( "go" , counter ++ ) } > run</ button >
492
+ ) : (
493
+ < button onClick = { reload } > reload</ button >
494
+ )
495
+ }
496
+ </ CustomAsync >
497
+ )
498
+ const expectedProps = { deferFn, foo : "bar" }
499
+ expect ( deferFn ) . not . toHaveBeenCalled ( )
500
+ fireEvent . click ( getByText ( "run" ) )
501
+ expect ( deferFn ) . toHaveBeenCalledWith ( "go" , 1 , expect . objectContaining ( expectedProps ) , abortCtrl )
502
+ fireEvent . click ( getByText ( "reload" ) )
503
+ expect ( deferFn ) . toHaveBeenCalledWith ( "go" , 1 , expect . objectContaining ( expectedProps ) , abortCtrl )
504
+ } )
463
505
} )
0 commit comments