@@ -3,6 +3,9 @@ import React from "react"
33import { render , fireEvent , cleanup , waitForElement } from "react-testing-library"
44import Async , { createInstance } from "./"
55
6+ const abortController = { abort : ( ) => { } }
7+ window . AbortController = jest . fn ( ) . mockImplementation ( ( ) => abortController )
8+
69afterEach ( cleanup )
710
811const resolveIn = ms => value => new Promise ( resolve => setTimeout ( resolve , ms , value ) )
@@ -20,7 +23,7 @@ describe("Async", () => {
2023 test ( "calls promiseFn with props" , ( ) => {
2124 const promiseFn = jest . fn ( ) . mockReturnValue ( Promise . resolve ( ) )
2225 render ( < Async promiseFn = { promiseFn } anotherProp = "123" /> )
23- expect ( promiseFn ) . toHaveBeenCalledWith ( { promiseFn, anotherProp : "123" } )
26+ expect ( promiseFn ) . toHaveBeenCalledWith ( { promiseFn, anotherProp : "123" } , abortController )
2427 } )
2528
2629 test ( "passes resolved data to children as render prop" , async ( ) => {
@@ -134,9 +137,19 @@ describe("Async", () => {
134137 )
135138 expect ( deferFn ) . not . toHaveBeenCalled ( )
136139 fireEvent . click ( getByText ( "run" ) )
137- expect ( deferFn ) . toHaveBeenCalledWith ( "go" , 1 , expect . objectContaining ( { deferFn, foo : "bar" } ) )
140+ expect ( deferFn ) . toHaveBeenCalledWith (
141+ "go" ,
142+ 1 ,
143+ expect . objectContaining ( { deferFn, foo : "bar" } ) ,
144+ abortController
145+ )
138146 fireEvent . click ( getByText ( "run" ) )
139- expect ( deferFn ) . toHaveBeenCalledWith ( "go" , 2 , expect . objectContaining ( { deferFn, foo : "bar" } ) )
147+ expect ( deferFn ) . toHaveBeenCalledWith (
148+ "go" ,
149+ 2 ,
150+ expect . objectContaining ( { deferFn, foo : "bar" } ) ,
151+ abortController
152+ )
140153 } )
141154
142155 test ( "reload uses the arguments of the previous run" , ( ) => {
@@ -156,11 +169,26 @@ describe("Async", () => {
156169 )
157170 expect ( deferFn ) . not . toHaveBeenCalled ( )
158171 fireEvent . click ( getByText ( "run" ) )
159- expect ( deferFn ) . toHaveBeenCalledWith ( "go" , 1 , expect . objectContaining ( { deferFn } ) )
172+ expect ( deferFn ) . toHaveBeenCalledWith (
173+ "go" ,
174+ 1 ,
175+ expect . objectContaining ( { deferFn } ) ,
176+ abortController
177+ )
160178 fireEvent . click ( getByText ( "run" ) )
161- expect ( deferFn ) . toHaveBeenCalledWith ( "go" , 2 , expect . objectContaining ( { deferFn } ) )
179+ expect ( deferFn ) . toHaveBeenCalledWith (
180+ "go" ,
181+ 2 ,
182+ expect . objectContaining ( { deferFn } ) ,
183+ abortController
184+ )
162185 fireEvent . click ( getByText ( "reload" ) )
163- expect ( deferFn ) . toHaveBeenCalledWith ( "go" , 2 , expect . objectContaining ( { deferFn } ) )
186+ expect ( deferFn ) . toHaveBeenCalledWith (
187+ "go" ,
188+ 2 ,
189+ expect . objectContaining ( { deferFn } ) ,
190+ abortController
191+ )
164192 } )
165193
166194 test ( "only accepts the last invocation of the promise" , async ( ) => {
0 commit comments