@@ -323,6 +323,41 @@ describe('session', () => {
323
323
} ) ;
324
324
} ) ;
325
325
326
+ it ( 'should pass through non-JSON responses with just the cookie added' , async ( ) => {
327
+ // Set up a custom loader that returns HTML
328
+ const htmlContent = '<html><body><h1>Hello World!</h1></body></html>' ;
329
+ const customLoader = jest . fn ( ) . mockReturnValue (
330
+ new Response ( htmlContent , {
331
+ headers : {
332
+ 'Content-Type' : 'text/html' ,
333
+ 'X-Custom-Header' : 'test-value' ,
334
+ } ,
335
+ } ) ,
336
+ ) ;
337
+
338
+ // Call authkitLoader with the HTML-returning loader
339
+ const result = await authkitLoader ( createLoaderArgs ( createMockRequest ( ) ) , customLoader ) ;
340
+
341
+ // Verify we got back a Response, not a DataWithResponseInit
342
+ assertIsResponse ( result ) ;
343
+
344
+ // Check that the response body wasn't modified
345
+ const resultText = await result . clone ( ) . text ( ) ;
346
+ expect ( resultText ) . toBe ( htmlContent ) ;
347
+
348
+ // Check that original headers were preserved
349
+ expect ( result . headers . get ( 'Content-Type' ) ) . toBe ( 'text/html' ) ;
350
+ expect ( result . headers . get ( 'X-Custom-Header' ) ) . toBe ( 'test-value' ) ;
351
+
352
+ // Check that session cookie was added
353
+ expect ( result . headers . get ( 'Set-Cookie' ) ) . toBe ( 'session-cookie' ) ;
354
+
355
+ // Verify that the JSON parsing method was not called
356
+ const jsonSpy = jest . spyOn ( Response . prototype , 'json' ) ;
357
+ expect ( jsonSpy ) . not . toHaveBeenCalled ( ) ;
358
+ jsonSpy . mockRestore ( ) ;
359
+ } ) ;
360
+
326
361
it ( 'should return authorized data with session claims' , async ( ) => {
327
362
const { data } = await authkitLoader ( createLoaderArgs ( createMockRequest ( ) ) ) ;
328
363
@@ -371,7 +406,7 @@ describe('session', () => {
371
406
const { data, init } = await authkitLoader ( createLoaderArgs ( createMockRequest ( ) ) , customLoader ) ;
372
407
373
408
expect ( getHeaderValue ( init ?. headers , 'Custom-Header' ) ) . toBe ( 'test-header' ) ;
374
- expect ( getHeaderValue ( init ?. headers , 'Content-Type' ) ) . toBe ( 'application/json; charset=utf-8 ' ) ;
409
+ expect ( getHeaderValue ( init ?. headers , 'Content-Type' ) ) . toBe ( 'application/json' ) ;
375
410
376
411
expect ( data ) . toEqual (
377
412
expect . objectContaining ( {
0 commit comments