@@ -2,6 +2,7 @@ import { createSlice } from '@reduxjs/toolkit'
22import { createApi , fetchBaseQuery } from '@reduxjs/toolkit/query'
33import { headersToObject } from 'headers-polyfill'
44import { HttpResponse , delay , http } from 'msw'
5+ // @ts -ignore
56import nodeFetch from 'node-fetch'
67import queryString from 'query-string'
78import { vi } from 'vitest'
@@ -852,6 +853,51 @@ describe('fetchBaseQuery', () => {
852853 expect ( _forced ) . toBe ( true )
853854 expect ( _extra ) . toBe ( fakeAuth0Client )
854855 } )
856+
857+ test ( 'can be instantiated with a `ExtraOptions` generic and `extraOptions` will be available in `prepareHeaders' , async ( ) => {
858+ const prepare = vitest . fn ( )
859+ const baseQuery = fetchBaseQuery ( {
860+ prepareHeaders ( headers , api ) {
861+ expectTypeOf ( api . extraOptions ) . toEqualTypeOf < unknown > ( )
862+ prepare . apply ( undefined , arguments as unknown as any [ ] )
863+ } ,
864+ } )
865+ baseQuery ( 'http://example.com' , commonBaseQueryApi , {
866+ foo : 'baz' ,
867+ bar : 5 ,
868+ } )
869+ expect ( prepare ) . toHaveBeenCalledWith (
870+ expect . anything ( ) ,
871+ expect . objectContaining ( { extraOptions : { foo : 'baz' , bar : 5 } } ) ,
872+ )
873+
874+ // ensure types
875+ createApi ( {
876+ baseQuery,
877+ endpoints ( build ) {
878+ return {
879+ testQuery : build . query ( {
880+ query : ( ) => ( { url : '/echo' , headers : { } } ) ,
881+ extraOptions : {
882+ foo : 'asd' ,
883+ bar : 1 ,
884+ } ,
885+ } ) ,
886+ testMutation : build . mutation ( {
887+ query : ( ) => ( {
888+ url : '/echo' ,
889+ method : 'POST' ,
890+ credentials : 'omit' ,
891+ } ) ,
892+ extraOptions : {
893+ foo : 'qwe' ,
894+ bar : 15 ,
895+ } ,
896+ } ) ,
897+ }
898+ } ,
899+ } )
900+ } )
855901 } )
856902
857903 test ( 'can pass `headers` into `fetchBaseQuery`' , async ( ) => {
0 commit comments