@@ -3,7 +3,6 @@ import type { FetchArgs } from '@reduxjs/toolkit/query'
33import { createApi , fetchBaseQuery } from '@reduxjs/toolkit/query'
44import { headersToObject } from 'headers-polyfill'
55import { HttpResponse , delay , http } from 'msw'
6- // @ts -ignore
76import nodeFetch from 'node-fetch'
87import queryString from 'query-string'
98import { vi } from 'vitest'
@@ -19,12 +18,11 @@ const defaultHeaders: Record<string, string> = {
1918
2019const baseUrl = 'https://example.com'
2120
22- // @ts -ignore
23- const fetchFn = vi . fn < Promise < any > , any [ ] > ( nodeFetch )
21+ const fetchFn = vi . fn ( fetch )
2422
2523const baseQuery = fetchBaseQuery ( {
2624 baseUrl,
27- fetchFn : fetchFn as any ,
25+ fetchFn,
2826 prepareHeaders : ( headers , { getState } ) => {
2927 const { token } = ( getState ( ) as RootState ) . auth
3028
@@ -419,7 +417,6 @@ describe('fetchBaseQuery', () => {
419417 it ( 'supports a custom jsonContentType' , async ( ) => {
420418 const baseQuery = fetchBaseQuery ( {
421419 baseUrl,
422- fetchFn : fetchFn as any ,
423420 jsonContentType : 'application/vnd.api+json' ,
424421 } )
425422
@@ -459,7 +456,6 @@ describe('fetchBaseQuery', () => {
459456 // Use jsonReplacer
460457 const baseQueryWithReplacer = fetchBaseQuery ( {
461458 baseUrl,
462- fetchFn : fetchFn as any ,
463459 jsonReplacer : ( key , value ) =>
464460 value instanceof Set ? [ ...value ] : value ,
465461 } )
@@ -546,7 +542,6 @@ describe('fetchBaseQuery', () => {
546542 it ( 'should support a paramsSerializer' , async ( ) => {
547543 const baseQuery = fetchBaseQuery ( {
548544 baseUrl,
549- fetchFn : fetchFn as any ,
550545 paramsSerializer : ( params : Record < string , unknown > ) =>
551546 queryString . stringify ( params , { arrayFormat : 'bracket' } ) ,
552547 } )
@@ -591,7 +586,6 @@ describe('fetchBaseQuery', () => {
591586 }
592587 const baseQuery = fetchBaseQuery ( {
593588 baseUrl,
594- fetchFn : fetchFn as any ,
595589 isJsonContentType : ( headers ) =>
596590 [
597591 'application/vnd.api+json' ,
@@ -805,7 +799,6 @@ describe('fetchBaseQuery', () => {
805799
806800 const baseQuery = fetchBaseQuery ( {
807801 baseUrl,
808- fetchFn : fetchFn as any ,
809802 prepareHeaders : (
810803 headers ,
811804 { getState, arg, extra, endpoint, type, forced } ,
@@ -974,7 +967,6 @@ describe('fetchBaseQuery', () => {
974967
975968 const globalizedBaseQuery = fetchBaseQuery ( {
976969 baseUrl,
977- fetchFn : fetchFn as any ,
978970 responseHandler : 'text' ,
979971 } )
980972
@@ -1003,7 +995,6 @@ describe('fetchBaseQuery', () => {
1003995
1004996 const globalizedBaseQuery = fetchBaseQuery ( {
1005997 baseUrl,
1006- fetchFn : fetchFn as any ,
1007998 responseHandler : 'content-type' ,
1008999 } )
10091000
@@ -1031,7 +1022,6 @@ describe('fetchBaseQuery', () => {
10311022
10321023 const globalizedBaseQuery = fetchBaseQuery ( {
10331024 baseUrl,
1034- fetchFn : fetchFn as any ,
10351025 responseHandler : 'content-type' ,
10361026 } )
10371027
@@ -1059,7 +1049,6 @@ describe('fetchBaseQuery', () => {
10591049
10601050 const globalizedBaseQuery = fetchBaseQuery ( {
10611051 baseUrl,
1062- fetchFn : fetchFn as any ,
10631052 responseHandler : 'content-type' ,
10641053 } )
10651054
@@ -1084,7 +1073,6 @@ describe('fetchBaseQuery', () => {
10841073
10851074 const globalizedBaseQuery = fetchBaseQuery ( {
10861075 baseUrl,
1087- fetchFn : fetchFn as any ,
10881076 responseHandler : 'content-type' ,
10891077 } )
10901078
@@ -1113,7 +1101,6 @@ describe('fetchBaseQuery', () => {
11131101
11141102 const globalizedBaseQuery = fetchBaseQuery ( {
11151103 baseUrl,
1116- fetchFn : fetchFn as any ,
11171104 responseHandler : 'content-type' ,
11181105 } )
11191106
@@ -1135,7 +1122,6 @@ describe('fetchBaseQuery', () => {
11351122 test ( 'Global validateStatus' , async ( ) => {
11361123 const globalizedBaseQuery = fetchBaseQuery ( {
11371124 baseUrl,
1138- fetchFn : fetchFn as any ,
11391125 validateStatus : ( response , body ) =>
11401126 response . status === 200 && body . success === false ? false : true ,
11411127 } )
@@ -1180,7 +1166,6 @@ describe('fetchBaseQuery', () => {
11801166
11811167 const globalizedBaseQuery = fetchBaseQuery ( {
11821168 baseUrl,
1183- fetchFn : fetchFn as any ,
11841169 timeout : 200 ,
11851170 } )
11861171
@@ -1192,7 +1177,7 @@ describe('fetchBaseQuery', () => {
11921177
11931178 expect ( result ?. error ) . toEqual ( {
11941179 status : 'TIMEOUT_ERROR' ,
1195- error : expect . stringMatching ( / ^ T i m e o u t E r r o r : / ) ,
1180+ error : expect . stringMatching ( / ^ T i m e o u t E r r o r / ) ,
11961181 } )
11971182 } )
11981183 } )
@@ -1266,7 +1251,6 @@ describe('FormData', () => {
12661251 // This test covers the exact scenario from issue #4669
12671252 const baseQueryWithJsonDefault = fetchBaseQuery ( {
12681253 baseUrl,
1269- fetchFn : fetchFn as any ,
12701254 prepareHeaders : ( headers ) => {
12711255 // Set default Content-Type for all requests
12721256 headers . set ( 'Content-Type' , 'application/json' )
@@ -1301,7 +1285,6 @@ describe('FormData', () => {
13011285 // This tests the workaround solution from the issue comments
13021286 const baseQueryWithConditionalHeader = fetchBaseQuery ( {
13031287 baseUrl,
1304- fetchFn : fetchFn as any ,
13051288 prepareHeaders : ( headers , { arg } ) => {
13061289 // Check if body is FormData and skip setting Content-Type
13071290 if ( ( arg as FetchArgs ) . body instanceof FormData ) {
@@ -1336,7 +1319,6 @@ describe('FormData', () => {
13361319 // This tests the fetch API quirk mentioned in the issue
13371320 const baseQueryWithJsonDefault = fetchBaseQuery ( {
13381321 baseUrl,
1339- fetchFn : fetchFn as any ,
13401322 prepareHeaders : ( headers ) => {
13411323 headers . set ( 'Content-Type' , 'application/json' )
13421324 return headers
@@ -1371,7 +1353,6 @@ describe('FormData', () => {
13711353 // Verify that the workaround doesn't break normal JSON requests
13721354 const baseQueryWithConditionalHeader = fetchBaseQuery ( {
13731355 baseUrl,
1374- fetchFn : fetchFn as any ,
13751356 prepareHeaders : ( headers , { arg } ) => {
13761357 if ( ! ( ( arg as FetchArgs ) . body instanceof FormData ) ) {
13771358 headers . set ( 'Content-Type' , 'application/json' )
@@ -1423,7 +1404,6 @@ describe('Accept header handling', () => {
14231404 // Create a baseQuery with text as the global responseHandler
14241405 const textBaseQuery = fetchBaseQuery ( {
14251406 baseUrl,
1426- fetchFn : fetchFn as any ,
14271407 responseHandler : 'text' ,
14281408 } )
14291409
@@ -1458,7 +1438,6 @@ describe('Accept header handling', () => {
14581438 test ( 'does not override Accept header set in prepareHeaders' , async ( ) => {
14591439 const customBaseQuery = fetchBaseQuery ( {
14601440 baseUrl,
1461- fetchFn : fetchFn as any ,
14621441 prepareHeaders : ( headers ) => {
14631442 headers . set ( 'Accept' , 'application/vnd.api+json' )
14641443 return headers
@@ -1494,7 +1473,6 @@ describe('Accept header handling', () => {
14941473 test ( 'respects global responseHandler for Accept header' , async ( ) => {
14951474 const textBaseQuery = fetchBaseQuery ( {
14961475 baseUrl,
1497- fetchFn : fetchFn as any ,
14981476 responseHandler : 'text' ,
14991477 } )
15001478
0 commit comments