@@ -5570,7 +5570,7 @@ describe("a router", () => {
5570
5570
} ) ;
5571
5571
} ) ;
5572
5572
5573
- it ( "processes external redirects if window is present" , async ( ) => {
5573
+ it ( "processes external redirects if window is present (push) " , async ( ) => {
5574
5574
let urls = [
5575
5575
"http://remix.run/blog" ,
5576
5576
"https://remix.run/blog" ,
@@ -5583,6 +5583,7 @@ describe("a router", () => {
5583
5583
// https://stackoverflow.com/a/60697570
5584
5584
let oldLocation = window . location ;
5585
5585
const location = new URL ( window . location . href ) as unknown as Location ;
5586
+ location . assign = jest . fn ( ) ;
5586
5587
location . replace = jest . fn ( ) ;
5587
5588
delete ( window as any ) . location ;
5588
5589
window . location = location as unknown as Location ;
@@ -5594,8 +5595,43 @@ describe("a router", () => {
5594
5595
formData : createFormData ( { } ) ,
5595
5596
} ) ;
5596
5597
5598
+ await A . actions . child . redirectReturn ( url ) ;
5599
+ expect ( window . location . assign ) . toHaveBeenCalledWith ( url ) ;
5600
+ expect ( window . location . replace ) . not . toHaveBeenCalled ( ) ;
5601
+
5602
+ window . location = oldLocation ;
5603
+ }
5604
+ } ) ;
5605
+
5606
+ it ( "processes external redirects if window is present (replace)" , async ( ) => {
5607
+ let urls = [
5608
+ "http://remix.run/blog" ,
5609
+ "https://remix.run/blog" ,
5610
+ "//remix.run/blog" ,
5611
+ "app://whatever" ,
5612
+ ] ;
5613
+
5614
+ for ( let url of urls ) {
5615
+ // This is gross, don't blame me, blame SO :)
5616
+ // https://stackoverflow.com/a/60697570
5617
+ let oldLocation = window . location ;
5618
+ const location = new URL ( window . location . href ) as unknown as Location ;
5619
+ location . assign = jest . fn ( ) ;
5620
+ location . replace = jest . fn ( ) ;
5621
+ delete ( window as any ) . location ;
5622
+ window . location = location as unknown as Location ;
5623
+
5624
+ let t = setup ( { routes : REDIRECT_ROUTES } ) ;
5625
+
5626
+ let A = await t . navigate ( "/parent/child" , {
5627
+ formMethod : "post" ,
5628
+ formData : createFormData ( { } ) ,
5629
+ replace : true ,
5630
+ } ) ;
5631
+
5597
5632
await A . actions . child . redirectReturn ( url ) ;
5598
5633
expect ( window . location . replace ) . toHaveBeenCalledWith ( url ) ;
5634
+ expect ( window . location . assign ) . not . toHaveBeenCalled ( ) ;
5599
5635
5600
5636
window . location = oldLocation ;
5601
5637
}
0 commit comments