@@ -24,8 +24,10 @@ describe('RestoreRoute', () => {
2424 let sanitizer : DomSanitizer ;
2525 let routeMemorizeService : RouteMemorizeService ;
2626 let activatedRoute : ActivatedRoute ;
27+ let mockWindow : { location : { href : string } ; origin ?: string } ;
2728
2829 beforeEach ( ( ) => {
30+ mockWindow = { location : { href : window . location . href } } ;
2931 const routeMemorizeServiceMock = {
3032 getRoute : jest . fn ( ) ,
3133 memorizeRoute : jest . fn ( ( ) => { } )
@@ -40,6 +42,7 @@ describe('RestoreRoute', () => {
4042 } ) ;
4143
4244 pipe = TestBed . inject ( RestoreRoute ) ;
45+ ( pipe as any ) . window = mockWindow ; // Inject the mock window into the pipe
4346 sanitizer = TestBed . inject ( DomSanitizer ) ;
4447 routeMemorizeService = TestBed . inject ( RouteMemorizeService ) ;
4548 activatedRoute = TestBed . inject ( ActivatedRoute ) ;
@@ -74,7 +77,7 @@ describe('RestoreRoute', () => {
7477 const options : RestoreRouteOptions = { propagateQueryParams : true } ;
7578 jest . spyOn ( sanitizer , 'sanitize' ) . mockReturnValue ( url ) ;
7679
77- Object . defineProperty ( window , 'location' , {
80+ Object . defineProperty ( mockWindow , 'location' , {
7881 value : { href : 'http://example-top-window.com?param2=value2' } ,
7982 writable : true
8083 } ) ;
@@ -89,7 +92,7 @@ describe('RestoreRoute', () => {
8992 const options : RestoreRouteOptions = { propagateQueryParams : true } ;
9093 jest . spyOn ( sanitizer , 'sanitize' ) . mockReturnValue ( url ) ;
9194
92- Object . defineProperty ( window , 'location' , {
95+ Object . defineProperty ( mockWindow , 'location' , {
9396 value : { href : 'http://example-top-window.com?param2=value2' } ,
9497 writable : true
9598 } ) ;
@@ -103,7 +106,7 @@ describe('RestoreRoute', () => {
103106 const url = 'http://example.com?param1=value1' ;
104107 const options : RestoreRouteOptions = { propagateQueryParams : true , overrideQueryParams : true } ;
105108 jest . spyOn ( sanitizer , 'sanitize' ) . mockReturnValue ( url ) ;
106- Object . defineProperty ( window , 'location' , {
109+ Object . defineProperty ( mockWindow , 'location' , {
107110 value : { href : 'http://example-to-window.com?param1=value2' } ,
108111 writable : true
109112 } ) ;
@@ -116,7 +119,7 @@ describe('RestoreRoute', () => {
116119 it ( 'should append the correct pathname and remove the module path from top window url' , ( ) => {
117120 const url = 'http://example.com' ;
118121 jest . spyOn ( sanitizer , 'sanitize' ) . mockReturnValue ( url ) ;
119- Object . defineProperty ( window , 'location' , {
122+ Object . defineProperty ( mockWindow , 'location' , {
120123 value : { href : 'http://example-top-window.com/module-path/in-module-path' } ,
121124 writable : true
122125 } ) ;
@@ -131,7 +134,7 @@ describe('RestoreRoute', () => {
131134 const url = 'http://example.com' ;
132135 jest . spyOn ( sanitizer , 'sanitize' ) . mockReturnValue ( url ) ;
133136
134- Object . defineProperty ( window , 'origin' , {
137+ Object . defineProperty ( mockWindow , 'origin' , {
135138 value : 'http://example-top-window.com'
136139 } ) ;
137140
0 commit comments