@@ -10,6 +10,7 @@ import type {
1010 RouterNavigateOptions ,
1111 StaticHandler ,
1212 StaticHandlerContext ,
13+ FutureConfig ,
1314} from "../index" ;
1415import {
1516 createMemoryHistory ,
@@ -289,6 +290,7 @@ type SetupOpts = {
289290 initialEntries ?: InitialEntry [ ] ;
290291 initialIndex ?: number ;
291292 hydrationData ?: HydrationState ;
293+ future ?: FutureConfig ;
292294} ;
293295
294296function setup ( {
@@ -297,6 +299,7 @@ function setup({
297299 initialEntries,
298300 initialIndex,
299301 hydrationData,
302+ future,
300303} : SetupOpts ) {
301304 let guid = 0 ;
302305 // Global "active" helpers, keyed by navType:guid:loaderOrAction:routeId.
@@ -424,6 +427,7 @@ function setup({
424427 history,
425428 routes : enhanceRoutes ( routes ) ,
426429 hydrationData,
430+ future,
427431 } ) . initialize ( ) ;
428432
429433 function getRouteHelpers (
@@ -3620,6 +3624,117 @@ describe("a router", () => {
36203624 "childIndex" ,
36213625 ] ) ;
36223626 } ) ;
3627+
3628+ describe ( "formMethod casing" , ( ) => {
3629+ it ( "normalizes to lowercase in v6" , async ( ) => {
3630+ let t = setup ( {
3631+ routes : [
3632+ {
3633+ id : "root" ,
3634+ path : "/" ,
3635+ children : [
3636+ {
3637+ id : "child" ,
3638+ path : "child" ,
3639+ loader : true ,
3640+ action : true ,
3641+ } ,
3642+ ] ,
3643+ } ,
3644+ ] ,
3645+ } ) ;
3646+ let A = await t . navigate ( "/child" , {
3647+ formMethod : "get" ,
3648+ formData : createFormData ( { } ) ,
3649+ } ) ;
3650+ expect ( t . router . state . navigation . formMethod ) . toBe ( "get" ) ;
3651+ await A . loaders . child . resolve ( "LOADER" ) ;
3652+ expect ( t . router . state . navigation . formMethod ) . toBeUndefined ( ) ;
3653+ await t . router . navigate ( "/" ) ;
3654+
3655+ let B = await t . navigate ( "/child" , {
3656+ formMethod : "POST" ,
3657+ formData : createFormData ( { } ) ,
3658+ } ) ;
3659+ expect ( t . router . state . navigation . formMethod ) . toBe ( "post" ) ;
3660+ await B . actions . child . resolve ( "ACTION" ) ;
3661+ await B . loaders . child . resolve ( "LOADER" ) ;
3662+ expect ( t . router . state . navigation . formMethod ) . toBeUndefined ( ) ;
3663+ await t . router . navigate ( "/" ) ;
3664+
3665+ let C = await t . fetch ( "/child" , "key" , {
3666+ formMethod : "GET" ,
3667+ formData : createFormData ( { } ) ,
3668+ } ) ;
3669+ expect ( t . router . state . fetchers . get ( "key" ) ?. formMethod ) . toBe ( "get" ) ;
3670+ await C . loaders . child . resolve ( "LOADER FETCH" ) ;
3671+ expect ( t . router . state . fetchers . get ( "key" ) ?. formMethod ) . toBeUndefined ( ) ;
3672+
3673+ let D = await t . fetch ( "/child" , "key" , {
3674+ formMethod : "post" ,
3675+ formData : createFormData ( { } ) ,
3676+ } ) ;
3677+ expect ( t . router . state . fetchers . get ( "key" ) ?. formMethod ) . toBe ( "post" ) ;
3678+ await D . actions . child . resolve ( "ACTION FETCH" ) ;
3679+ expect ( t . router . state . fetchers . get ( "key" ) ?. formMethod ) . toBeUndefined ( ) ;
3680+ } ) ;
3681+
3682+ it ( "normalizes to uppercase in v7 via v7_normalizeFormMethod" , async ( ) => {
3683+ let t = setup ( {
3684+ routes : [
3685+ {
3686+ id : "root" ,
3687+ path : "/" ,
3688+ children : [
3689+ {
3690+ id : "child" ,
3691+ path : "child" ,
3692+ loader : true ,
3693+ action : true ,
3694+ } ,
3695+ ] ,
3696+ } ,
3697+ ] ,
3698+ future : {
3699+ v7_normalizeFormMethod : true ,
3700+ } ,
3701+ } ) ;
3702+ let A = await t . navigate ( "/child" , {
3703+ formMethod : "get" ,
3704+ formData : createFormData ( { } ) ,
3705+ } ) ;
3706+ expect ( t . router . state . navigation . formMethod ) . toBe ( "GET" ) ;
3707+ await A . loaders . child . resolve ( "LOADER" ) ;
3708+ expect ( t . router . state . navigation . formMethod ) . toBeUndefined ( ) ;
3709+ await t . router . navigate ( "/" ) ;
3710+
3711+ let B = await t . navigate ( "/child" , {
3712+ formMethod : "POST" ,
3713+ formData : createFormData ( { } ) ,
3714+ } ) ;
3715+ expect ( t . router . state . navigation . formMethod ) . toBe ( "POST" ) ;
3716+ await B . actions . child . resolve ( "ACTION" ) ;
3717+ await B . loaders . child . resolve ( "LOADER" ) ;
3718+ expect ( t . router . state . navigation . formMethod ) . toBeUndefined ( ) ;
3719+ await t . router . navigate ( "/" ) ;
3720+
3721+ let C = await t . fetch ( "/child" , "key" , {
3722+ formMethod : "GET" ,
3723+ formData : createFormData ( { } ) ,
3724+ } ) ;
3725+ expect ( t . router . state . fetchers . get ( "key" ) ?. formMethod ) . toBe ( "GET" ) ;
3726+ await C . loaders . child . resolve ( "LOADER FETCH" ) ;
3727+ expect ( t . router . state . fetchers . get ( "key" ) ?. formMethod ) . toBeUndefined ( ) ;
3728+
3729+ let D = await t . fetch ( "/child" , "key" , {
3730+ formMethod : "post" ,
3731+ formData : createFormData ( { } ) ,
3732+ } ) ;
3733+ expect ( t . router . state . fetchers . get ( "key" ) ?. formMethod ) . toBe ( "POST" ) ;
3734+ await D . actions . child . resolve ( "ACTION FETCH" ) ;
3735+ expect ( t . router . state . fetchers . get ( "key" ) ?. formMethod ) . toBeUndefined ( ) ;
3736+ } ) ;
3737+ } ) ;
36233738 } ) ;
36243739
36253740 describe ( "action errors" , ( ) => {
0 commit comments