@@ -828,19 +828,8 @@ describe("special character tests", () => {
828
828
} ) ;
829
829
830
830
describe ( "browser routers" , ( ) => {
831
- let testWindow : Window ;
832
-
833
- beforeEach ( ( ) => {
834
- // Need to use our own custom DOM in order to get a working history
835
- const dom = new JSDOM ( `<!DOCTYPE html><html><body></body></html>` , {
836
- url : "https://remix.run/" ,
837
- } ) ;
838
- testWindow = dom . window as unknown as Window ;
839
- testWindow . history . pushState ( { } , "" , "/" ) ;
840
- } ) ;
841
-
842
831
it ( "encodes characters in BrowserRouter" , ( ) => {
843
- testWindow . history . replaceState ( null , "" , "/with space" ) ;
832
+ let testWindow = getWindow ( "/with space" ) ;
844
833
845
834
let ctx = render (
846
835
< BrowserRouter window = { testWindow } >
@@ -857,7 +846,7 @@ describe("special character tests", () => {
857
846
} ) ;
858
847
859
848
it ( "encodes characters in BrowserRouter (navigate)" , ( ) => {
860
- testWindow . history . replaceState ( null , "" , "/" ) ;
849
+ let testWindow = getWindow ( "/" ) ;
861
850
862
851
function Start ( ) {
863
852
let navigate = useNavigate ( ) ;
@@ -882,7 +871,7 @@ describe("special character tests", () => {
882
871
} ) ;
883
872
884
873
it ( "encodes characters in createBrowserRouter" , ( ) => {
885
- testWindow . history . replaceState ( null , "" , "/with space" ) ;
874
+ let testWindow = getWindow ( "/with space" ) ;
886
875
887
876
let router = createBrowserRouter (
888
877
[ { path : "/with space" , element : < ShowPath /> } ] ,
@@ -897,7 +886,7 @@ describe("special character tests", () => {
897
886
} ) ;
898
887
899
888
it ( "encodes characters in createBrowserRouter (navigate)" , ( ) => {
900
- testWindow . history . replaceState ( null , "" , "/with space ") ;
889
+ let testWindow = getWindow ( "/ ") ;
901
890
902
891
function Start ( ) {
903
892
let navigate = useNavigate ( ) ;
@@ -923,19 +912,8 @@ describe("special character tests", () => {
923
912
} ) ;
924
913
925
914
describe ( "hash routers" , ( ) => {
926
- let testWindow : Window ;
927
-
928
- beforeEach ( ( ) => {
929
- // Need to use our own custom DOM in order to get a working history
930
- const dom = new JSDOM ( `<!DOCTYPE html><html><body></body></html>` , {
931
- url : "https://remix.run/" ,
932
- } ) ;
933
- testWindow = dom . window as unknown as Window ;
934
- testWindow . history . pushState ( { } , "" , "/" ) ;
935
- } ) ;
936
-
937
915
it ( "encodes characters in HashRouter" , ( ) => {
938
- testWindow . history . replaceState ( null , "" , "/#/with space" ) ;
916
+ let testWindow = getWindow ( "/#/with space" ) ;
939
917
940
918
let ctx = render (
941
919
< HashRouter window = { testWindow } >
@@ -953,7 +931,7 @@ describe("special character tests", () => {
953
931
} ) ;
954
932
955
933
it ( "encodes characters in HashRouter (navigate)" , ( ) => {
956
- testWindow . history . replaceState ( null , "" , "/" ) ;
934
+ let testWindow = getWindow ( "/" ) ;
957
935
958
936
function Start ( ) {
959
937
let navigate = useNavigate ( ) ;
@@ -979,7 +957,7 @@ describe("special character tests", () => {
979
957
} ) ;
980
958
981
959
it ( "encodes characters in createHashRouter" , ( ) => {
982
- testWindow . history . replaceState ( null , "" , "/#/with space" ) ;
960
+ let testWindow = getWindow ( "/#/with space" ) ;
983
961
984
962
let router = createHashRouter (
985
963
[ { path : "/with space" , element : < ShowPath /> } ] ,
@@ -995,7 +973,7 @@ describe("special character tests", () => {
995
973
} ) ;
996
974
997
975
it ( "encodes characters in createHashRouter (navigate)" , ( ) => {
998
- testWindow . history . replaceState ( null , "" , "/" ) ;
976
+ let testWindow = getWindow ( "/" ) ;
999
977
1000
978
function Start ( ) {
1001
979
let navigate = useNavigate ( ) ;
@@ -1022,3 +1000,13 @@ describe("special character tests", () => {
1022
1000
} ) ;
1023
1001
} ) ;
1024
1002
} ) ;
1003
+
1004
+ function getWindow ( initialPath ) {
1005
+ // Need to use our own custom DOM in order to get a working history
1006
+ const dom = new JSDOM ( `<!DOCTYPE html><html><body></body></html>` , {
1007
+ url : "https://remix.run/" ,
1008
+ } ) ;
1009
+ let testWindow = dom . window as unknown as Window ;
1010
+ testWindow . history . pushState ( { } , "" , initialPath ) ;
1011
+ return testWindow ;
1012
+ }
0 commit comments