@@ -3013,13 +3013,17 @@ describe("a router", () => {
30133013
30143014 await A . actions . foo . resolve ( "FOO ACTION" ) ;
30153015 expect ( A . loaders . root . stub . mock . calls . length ) . toBe ( 1 ) ;
3016+ expect ( t . router . state . actionData ) . toEqual ( {
3017+ foo : "FOO ACTION" ,
3018+ } ) ;
30163019
30173020 let B = await A . loaders . foo . redirect ( "/bar" ) ;
30183021 await A . loaders . root . reject ( "ROOT ERROR" ) ;
30193022 await B . loaders . root . resolve ( "ROOT LOADER 2" ) ;
30203023 await B . loaders . bar . resolve ( "BAR LOADER" ) ;
30213024 expect ( B . loaders . root . stub . mock . calls . length ) . toBe ( 1 ) ;
30223025 expect ( t . router . state ) . toMatchObject ( {
3026+ actionData : null ,
30233027 loaderData : {
30243028 root : "ROOT LOADER 2" ,
30253029 bar : "BAR LOADER" ,
@@ -3051,8 +3055,11 @@ describe("a router", () => {
30513055 } ) ;
30523056 expect ( A . loaders . root . stub . mock . calls . length ) . toBe ( 0 ) ;
30533057
3054- await A . actions . foo . resolve ( null ) ;
3058+ await A . actions . foo . resolve ( "FOO ACTION" ) ;
30553059 expect ( A . loaders . root . stub . mock . calls . length ) . toBe ( 1 ) ;
3060+ expect ( t . router . state . actionData ) . toEqual ( {
3061+ foo : "FOO ACTION" ,
3062+ } ) ;
30563063
30573064 await A . loaders . foo . resolve ( "A LOADER" ) ;
30583065 expect ( t . router . state . navigation . state ) . toBe ( "loading" ) ;
@@ -3063,6 +3070,9 @@ describe("a router", () => {
30633070
30643071 await A . loaders . root . resolve ( "ROOT LOADER" ) ;
30653072 expect ( t . router . state . navigation . state ) . toBe ( "idle" ) ;
3073+ expect ( t . router . state . actionData ) . toEqual ( {
3074+ foo : "FOO ACTION" , // kept around on action reload
3075+ } ) ;
30663076 expect ( t . router . state . loaderData ) . toEqual ( {
30673077 foo : "A LOADER" ,
30683078 root : "ROOT LOADER" ,
@@ -3238,6 +3248,45 @@ describe("a router", () => {
32383248 } ) ;
32393249 } ) ;
32403250
3251+ it ( "removes action data after action redirect to current location" , async ( ) => {
3252+ let t = setup ( {
3253+ routes : [
3254+ {
3255+ path : "/" ,
3256+ id : "index" ,
3257+ action : true ,
3258+ loader : true ,
3259+ } ,
3260+ ] ,
3261+ } ) ;
3262+ let A = await t . navigate ( "/" , {
3263+ formMethod : "post" ,
3264+ formData : createFormData ( { gosh : "" } ) ,
3265+ } ) ;
3266+ await A . actions . index . resolve ( { error : "invalid" } ) ;
3267+ expect ( t . router . state . actionData ) . toEqual ( {
3268+ index : { error : "invalid" } ,
3269+ } ) ;
3270+
3271+ let B = await t . navigate ( "/" , {
3272+ formMethod : "post" ,
3273+ formData : createFormData ( { gosh : "dang" } ) ,
3274+ } ) ;
3275+
3276+ let C = await B . actions . index . redirectReturn ( "/" ) ;
3277+ expect ( t . router . state . actionData ) . toEqual ( {
3278+ index : { error : "invalid" } ,
3279+ } ) ;
3280+ expect ( t . router . state . loaderData ) . toEqual ( { } ) ;
3281+
3282+ await C . loaders . index . resolve ( "NEW" ) ;
3283+
3284+ expect ( t . router . state . actionData ) . toBeNull ( ) ;
3285+ expect ( t . router . state . loaderData ) . toEqual ( {
3286+ index : "NEW" ,
3287+ } ) ;
3288+ } ) ;
3289+
32413290 it ( "uses the proper action for index routes" , async ( ) => {
32423291 let t = setup ( {
32433292 routes : [
0 commit comments