@@ -295,15 +295,34 @@ describe("SSEClientTransport", () => {
295295 expect ( lastServerRequest . headers . authorization ) . toBe ( authToken ) ;
296296 } ) ;
297297
298- it ( "passes custom headers to fetch requests" , async ( ) => {
299- const customHeaders = {
300- Authorization : "Bearer test-token" ,
301- "X-Custom-Header" : "custom-value" ,
302- } ;
303-
298+ it . each ( [
299+ {
300+ description : "plain object headers" ,
301+ headers : {
302+ Authorization : "Bearer test-token" ,
303+ "X-Custom-Header" : "custom-value" ,
304+ } ,
305+ } ,
306+ {
307+ description : "Headers object" ,
308+ headers : ( ( ) : HeadersInit => {
309+ const h = new Headers ( ) ;
310+ h . set ( "Authorization" , "Bearer test-token" ) ;
311+ h . set ( "X-Custom-Header" , "custom-value" ) ;
312+ return h ;
313+ } ) ( ) ,
314+ } ,
315+ {
316+ description : "array of tuples" ,
317+ headers : ( ( ) : HeadersInit => ( [
318+ [ "Authorization" , "Bearer test-token" ] ,
319+ [ "X-Custom-Header" , "custom-value" ] ,
320+ ] ) ) ( ) ,
321+ } ,
322+ ] ) ( "passes custom headers to fetch requests ($description)" , async ( { headers } ) => {
304323 transport = new SSEClientTransport ( resourceBaseUrl , {
305324 requestInit : {
306- headers : customHeaders ,
325+ headers,
307326 } ,
308327 } ) ;
309328
@@ -337,12 +356,8 @@ describe("SSEClientTransport", () => {
337356
338357 const calledHeaders = ( global . fetch as jest . Mock ) . mock . calls [ 0 ] [ 1 ]
339358 . headers ;
340- expect ( calledHeaders . get ( "Authorization" ) ) . toBe (
341- customHeaders . Authorization ,
342- ) ;
343- expect ( calledHeaders . get ( "X-Custom-Header" ) ) . toBe (
344- customHeaders [ "X-Custom-Header" ] ,
345- ) ;
359+ expect ( calledHeaders . get ( "Authorization" ) ) . toBe ( "Bearer test-token" ) ;
360+ expect ( calledHeaders . get ( "X-Custom-Header" ) ) . toBe ( "custom-value" ) ;
346361 expect ( calledHeaders . get ( "content-type" ) ) . toBe ( "application/json" ) ;
347362 } finally {
348363 // Restore original fetch
0 commit comments