@@ -3,7 +3,7 @@ import { server, baseUrl, useMockRequestHandler } from "./fixtures/mock-server.j
3
3
import type { paths } from "./fixtures/api.js" ;
4
4
import createClient from "../src/index.js" ;
5
5
import createFetchClient from "openapi-fetch" ;
6
- import { fireEvent , render , renderHook , screen , waitFor } from "@testing-library/react" ;
6
+ import { fireEvent , render , renderHook , screen , waitFor , act } from "@testing-library/react" ;
7
7
import { QueryClient , QueryClientProvider } from "@tanstack/react-query" ;
8
8
import { Suspense , type ReactNode } from "react" ;
9
9
import { ErrorBoundary } from "react-error-boundary" ;
@@ -109,6 +109,26 @@ describe("client", () => {
109
109
expectTypeOf ( error ) . toEqualTypeOf < { code : number ; message : string } | null > ( ) ;
110
110
} ) ;
111
111
112
+ it ( "passes abort signal to fetch" , async ( ) => {
113
+ let signalPassedToFetch : AbortSignal | undefined ;
114
+
115
+ const fetchClient = createFetchClient < paths > ( {
116
+ baseUrl,
117
+ fetch : async ( { signal } ) => {
118
+ signalPassedToFetch = signal ;
119
+ await new Promise ( ( ) => { } ) ;
120
+ return Response . error ( ) ;
121
+ } ,
122
+ } ) ;
123
+ const client = createClient ( fetchClient ) ;
124
+
125
+ const { unmount } = renderHook ( ( ) => client . useQuery ( "get" , "/string-array" ) , { wrapper } ) ;
126
+
127
+ unmount ( ) ;
128
+
129
+ expect ( signalPassedToFetch ?. aborted ) . toBeTruthy ( ) ;
130
+ } ) ;
131
+
112
132
describe ( "params" , ( ) => {
113
133
it ( "should be required if OpenAPI schema requires params" , async ( ) => {
114
134
const fetchClient = createFetchClient < paths > ( { baseUrl } ) ;
@@ -258,6 +278,29 @@ describe("client", () => {
258
278
259
279
await waitFor ( ( ) => rendered . findByText ( "data: Hello" ) ) ;
260
280
} ) ;
281
+
282
+ it ( "passes abort signal to fetch" , async ( ) => {
283
+ let signalPassedToFetch : AbortSignal | undefined ;
284
+
285
+ const fetchClient = createFetchClient < paths > ( {
286
+ baseUrl,
287
+ fetch : async ( { signal } ) => {
288
+ signalPassedToFetch = signal ;
289
+ await new Promise ( ( ) => { } ) ;
290
+ return Response . error ( ) ;
291
+ } ,
292
+ } ) ;
293
+ const client = createClient ( fetchClient ) ;
294
+ const queryClient = new QueryClient ( { } ) ;
295
+
296
+ const { unmount } = renderHook ( ( ) => client . useSuspenseQuery ( "get" , "/string-array" , { } , { } , queryClient ) ) ;
297
+
298
+ unmount ( ) ;
299
+
300
+ await act ( ( ) => queryClient . cancelQueries ( ) ) ;
301
+
302
+ expect ( signalPassedToFetch ?. aborted ) . toBeTruthy ( ) ;
303
+ } ) ;
261
304
} ) ;
262
305
263
306
describe ( "useMutation" , ( ) => {
0 commit comments