@@ -5052,12 +5052,21 @@ describe("a router", () => {
5052
5052
// Assert request internals, cannot do a deep comparison above since some
5053
5053
// internals aren't the same on separate creations
5054
5054
let request = nav . actions . tasks . stub . mock . calls [ 0 ] [ 0 ] . request ;
5055
- expect ( request . url ) . toBe ( "http://localhost/tasks" ) ;
5056
5055
expect ( request . method ) . toBe ( "POST" ) ;
5056
+ expect ( request . url ) . toBe ( "http://localhost/tasks" ) ;
5057
5057
expect ( request . headers . get ( "Content-Type" ) ) . toBe (
5058
5058
"application/x-www-form-urlencoded;charset=UTF-8"
5059
5059
) ;
5060
5060
expect ( ( await request . formData ( ) ) . get ( "query" ) ) . toBe ( "params" ) ;
5061
+
5062
+ await nav . actions . tasks . resolve ( "TASKS ACTION" ) ;
5063
+ let rootLoaderRequest = nav . loaders . root . stub . mock . calls [ 0 ] [ 0 ] . request ;
5064
+ expect ( rootLoaderRequest . method ) . toBe ( "GET" ) ;
5065
+ expect ( rootLoaderRequest . url ) . toBe ( "http://localhost/tasks" ) ;
5066
+
5067
+ let tasksLoaderRequest = nav . loaders . tasks . stub . mock . calls [ 0 ] [ 0 ] . request ;
5068
+ expect ( tasksLoaderRequest . method ) . toBe ( "GET" ) ;
5069
+ expect ( tasksLoaderRequest . url ) . toBe ( "http://localhost/tasks" ) ;
5061
5070
} ) ;
5062
5071
5063
5072
it ( "sends proper arguments to actions (using query string)" , async ( ) => {
@@ -10379,9 +10388,12 @@ describe("a router", () => {
10379
10388
}
10380
10389
10381
10390
function createSubmitRequest ( path : string , opts ?: RequestInit ) {
10391
+ let searchParams = new URLSearchParams ( ) ;
10392
+ searchParams . append ( "key" , "value" ) ;
10393
+
10382
10394
return createRequest ( path , {
10383
10395
method : "post" ,
10384
- body : createFormData ( { key : "value" } ) ,
10396
+ body : searchParams ,
10385
10397
...opts ,
10386
10398
} ) ;
10387
10399
}
@@ -10851,6 +10863,75 @@ describe("a router", () => {
10851
10863
} ) ;
10852
10864
} ) ;
10853
10865
10866
+ it ( "should send proper arguments to loaders" , async ( ) => {
10867
+ let rootLoaderStub = jest . fn ( ( ) => "ROOT" ) ;
10868
+ let childLoaderStub = jest . fn ( ( ) => "CHILD" ) ;
10869
+ let { query } = createStaticHandler ( [
10870
+ {
10871
+ id : "root" ,
10872
+ path : "/" ,
10873
+ loader : rootLoaderStub ,
10874
+ children : [
10875
+ {
10876
+ id : "child" ,
10877
+ path : "child" ,
10878
+ loader : childLoaderStub ,
10879
+ } ,
10880
+ ] ,
10881
+ } ,
10882
+ ] ) ;
10883
+ await query ( createRequest ( "/child" ) ) ;
10884
+
10885
+ // @ts -expect-error
10886
+ let rootLoaderRequest = rootLoaderStub . mock . calls [ 0 ] [ 0 ] ?. request ;
10887
+ // @ts -expect-error
10888
+ let childLoaderRequest = childLoaderStub . mock . calls [ 0 ] [ 0 ] ?. request ;
10889
+ expect ( rootLoaderRequest . method ) . toBe ( "GET" ) ;
10890
+ expect ( rootLoaderRequest . url ) . toBe ( "http://localhost/child" ) ;
10891
+ expect ( childLoaderRequest . method ) . toBe ( "GET" ) ;
10892
+ expect ( childLoaderRequest . url ) . toBe ( "http://localhost/child" ) ;
10893
+ } ) ;
10894
+
10895
+ it ( "should send proper arguments to actions" , async ( ) => {
10896
+ let actionStub = jest . fn ( ( ) => "ACTION" ) ;
10897
+ let rootLoaderStub = jest . fn ( ( ) => "ROOT" ) ;
10898
+ let childLoaderStub = jest . fn ( ( ) => "CHILD" ) ;
10899
+ let { query } = createStaticHandler ( [
10900
+ {
10901
+ id : "root" ,
10902
+ path : "/" ,
10903
+ loader : rootLoaderStub ,
10904
+ children : [
10905
+ {
10906
+ id : "child" ,
10907
+ path : "child" ,
10908
+ action : actionStub ,
10909
+ loader : childLoaderStub ,
10910
+ } ,
10911
+ ] ,
10912
+ } ,
10913
+ ] ) ;
10914
+ await query ( createSubmitRequest ( "/child" ) ) ;
10915
+
10916
+ // @ts -expect-error
10917
+ let actionRequest = actionStub . mock . calls [ 0 ] [ 0 ] ?. request ;
10918
+ expect ( actionRequest . method ) . toBe ( "POST" ) ;
10919
+ expect ( actionRequest . url ) . toBe ( "http://localhost/child" ) ;
10920
+ expect ( actionRequest . headers . get ( "Content-Type" ) ) . toBe (
10921
+ "application/x-www-form-urlencoded;charset=UTF-8"
10922
+ ) ;
10923
+ expect ( ( await actionRequest . formData ( ) ) . get ( "key" ) ) . toBe ( "value" ) ;
10924
+
10925
+ // @ts -expect-error
10926
+ let rootLoaderRequest = rootLoaderStub . mock . calls [ 0 ] [ 0 ] ?. request ;
10927
+ // @ts -expect-error
10928
+ let childLoaderRequest = childLoaderStub . mock . calls [ 0 ] [ 0 ] ?. request ;
10929
+ expect ( rootLoaderRequest . method ) . toBe ( "GET" ) ;
10930
+ expect ( rootLoaderRequest . url ) . toBe ( "http://localhost/child" ) ;
10931
+ expect ( childLoaderRequest . method ) . toBe ( "GET" ) ;
10932
+ expect ( childLoaderRequest . url ) . toBe ( "http://localhost/child" ) ;
10933
+ } ) ;
10934
+
10854
10935
describe ( "statusCode" , ( ) => {
10855
10936
it ( "should expose a 200 status code by default" , async ( ) => {
10856
10937
let { query } = createStaticHandler ( [
0 commit comments