@@ -2,6 +2,7 @@ import { createSlice } from '@reduxjs/toolkit'
2
2
import { createApi , fetchBaseQuery } from '@reduxjs/toolkit/query'
3
3
import { headersToObject } from 'headers-polyfill'
4
4
import { HttpResponse , delay , http } from 'msw'
5
+ // @ts -ignore
5
6
import nodeFetch from 'node-fetch'
6
7
import queryString from 'query-string'
7
8
import { vi } from 'vitest'
@@ -852,6 +853,51 @@ describe('fetchBaseQuery', () => {
852
853
expect ( _forced ) . toBe ( true )
853
854
expect ( _extra ) . toBe ( fakeAuth0Client )
854
855
} )
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
+ } )
855
901
} )
856
902
857
903
test ( 'can pass `headers` into `fetchBaseQuery`' , async ( ) => {
0 commit comments