@@ -315,7 +315,7 @@ describe("client", () => {
315
315
expect ( error ) . toBeNull ( ) ;
316
316
} ) ;
317
317
318
- it ( "should resolve error properly and have undefined data when queryFn returns undefined" , async ( ) => {
318
+ it ( "handles undefined response with non-zero Content-Length (status 200) by setting error and undefined data " , async ( ) => {
319
319
const fetchClient = createFetchClient < paths > ( { baseUrl } ) ;
320
320
const client = createClient ( fetchClient ) ;
321
321
@@ -324,6 +324,9 @@ describe("client", () => {
324
324
method : "get" ,
325
325
path : "/string-array" ,
326
326
status : 200 ,
327
+ headers : {
328
+ "Content-Length" : "10"
329
+ } ,
327
330
body : undefined ,
328
331
} ) ;
329
332
@@ -337,6 +340,53 @@ describe("client", () => {
337
340
expect ( data ) . toBeUndefined ( ) ;
338
341
} ) ;
339
342
343
+ it ( "handles undefined response with zero Content-Length by setting data and error to null" , async ( ) => {
344
+ const fetchClient = createFetchClient < paths > ( { baseUrl } ) ;
345
+ const client = createClient ( fetchClient ) ;
346
+
347
+ useMockRequestHandler ( {
348
+ baseUrl,
349
+ method : "get" ,
350
+ path : "/string-array" ,
351
+ status : 200 ,
352
+ headers : {
353
+ "Content-Length" : "0"
354
+ } ,
355
+ body : undefined ,
356
+ } ) ;
357
+
358
+ const { result } = renderHook ( ( ) => client . useQuery ( "get" , "/string-array" ) , { wrapper } ) ;
359
+
360
+ await waitFor ( ( ) => expect ( result . current . isFetching ) . toBe ( false ) ) ;
361
+
362
+ const { data, error } = result . current ;
363
+
364
+ expect ( error ) . toBeNull ( ) ;
365
+ expect ( data ) . toBeNull ( ) ;
366
+ } ) ;
367
+
368
+ it ( "handles undefined response with 204 No Content status by setting data and error to null" , async ( ) => {
369
+ const fetchClient = createFetchClient < paths > ( { baseUrl } ) ;
370
+ const client = createClient ( fetchClient ) ;
371
+
372
+ useMockRequestHandler ( {
373
+ baseUrl,
374
+ method : "get" ,
375
+ path : "/string-array" ,
376
+ status : 204 ,
377
+ body : undefined ,
378
+ } ) ;
379
+
380
+ const { result } = renderHook ( ( ) => client . useQuery ( "get" , "/string-array" ) , { wrapper } ) ;
381
+
382
+ await waitFor ( ( ) => expect ( result . current . isFetching ) . toBe ( false ) ) ;
383
+
384
+ const { data, error } = result . current ;
385
+
386
+ expect ( error ) . toBeNull ( ) ;
387
+ expect ( data ) . toBeNull ( ) ;
388
+ } ) ;
389
+
340
390
it ( "should infer correct data and error type" , async ( ) => {
341
391
const fetchClient = createFetchClient < paths > ( { baseUrl, fetch : fetchInfinite } ) ;
342
392
const client = createClient ( fetchClient ) ;
0 commit comments