@@ -9914,7 +9914,37 @@ describe("a router", () => {
9914
9914
} ) ;
9915
9915
9916
9916
describe ( "headers" , ( ) => {
9917
- it ( "should expose headers from loader responses" , async ( ) => {
9917
+ it ( "should expose headers from action/loader responses" , async ( ) => {
9918
+ let { query } = createStaticHandler ( [
9919
+ {
9920
+ id : "root" ,
9921
+ path : "/" ,
9922
+ loader : ( ) => new Response ( null , { headers : { two : "2" } } ) ,
9923
+ children : [
9924
+ {
9925
+ id : "child" ,
9926
+ index : true ,
9927
+ action : ( ) => new Response ( null , { headers : { one : "1" } } ) ,
9928
+ loader : ( ) => new Response ( null , { headers : { three : "3" } } ) ,
9929
+ } ,
9930
+ ] ,
9931
+ } ,
9932
+ ] ) ;
9933
+ let context = ( await query (
9934
+ createSubmitRequest ( "/?index" )
9935
+ ) ) as StaticHandlerContext ;
9936
+ expect ( Array . from ( context . actionHeaders . child . entries ( ) ) ) . toEqual ( [
9937
+ [ "one" , "1" ] ,
9938
+ ] ) ;
9939
+ expect ( Array . from ( context . loaderHeaders . root . entries ( ) ) ) . toEqual ( [
9940
+ [ "two" , "2" ] ,
9941
+ ] ) ;
9942
+ expect ( Array . from ( context . loaderHeaders . child . entries ( ) ) ) . toEqual ( [
9943
+ [ "three" , "3" ] ,
9944
+ ] ) ;
9945
+ } ) ;
9946
+
9947
+ it ( "should expose headers from loader error responses" , async ( ) => {
9918
9948
let { query } = createStaticHandler ( [
9919
9949
{
9920
9950
id : "root" ,
@@ -9924,7 +9954,9 @@ describe("a router", () => {
9924
9954
{
9925
9955
id : "child" ,
9926
9956
index : true ,
9927
- loader : ( ) => new Response ( null , { headers : { two : "2" } } ) ,
9957
+ loader : ( ) => {
9958
+ throw new Response ( null , { headers : { two : "2" } } ) ;
9959
+ } ,
9928
9960
} ,
9929
9961
] ,
9930
9962
} ,
@@ -9940,18 +9972,18 @@ describe("a router", () => {
9940
9972
] ) ;
9941
9973
} ) ;
9942
9974
9943
- it ( "should expose headers from action responses" , async ( ) => {
9975
+ it ( "should expose headers from action error responses" , async ( ) => {
9944
9976
let { query } = createStaticHandler ( [
9945
9977
{
9946
9978
id : "root" ,
9947
9979
path : "/" ,
9948
- loader : ( ) => new Response ( null , { headers : { two : "2" } } ) ,
9949
9980
children : [
9950
9981
{
9951
9982
id : "child" ,
9952
9983
index : true ,
9953
- action : ( ) => new Response ( null , { headers : { one : "1" } } ) ,
9954
- loader : ( ) => new Response ( null , { headers : { three : "3" } } ) ,
9984
+ action : ( ) => {
9985
+ throw new Response ( null , { headers : { one : "1" } } ) ;
9986
+ } ,
9955
9987
} ,
9956
9988
] ,
9957
9989
} ,
@@ -9962,12 +9994,6 @@ describe("a router", () => {
9962
9994
expect ( Array . from ( context . actionHeaders . child . entries ( ) ) ) . toEqual ( [
9963
9995
[ "one" , "1" ] ,
9964
9996
] ) ;
9965
- expect ( Array . from ( context . loaderHeaders . root . entries ( ) ) ) . toEqual ( [
9966
- [ "two" , "2" ] ,
9967
- ] ) ;
9968
- expect ( Array . from ( context . loaderHeaders . child . entries ( ) ) ) . toEqual ( [
9969
- [ "three" , "3" ] ,
9970
- ] ) ;
9971
9997
} ) ;
9972
9998
} ) ;
9973
9999
} ) ;
0 commit comments