@@ -12,12 +12,13 @@ describe('HostInfo', () => {
1212 hostApplicationId : 'expected-application-id' ,
1313 moduleApplicationId : 'expected-module-application-id'
1414 } as const satisfies MFEHostInformation ;
15+ let mockLocation : any ;
1516
1617 beforeEach ( ( ) => {
17- Object . defineProperty ( globalThis , 'location' , { value : {
18+ mockLocation = {
1819 search : '' ,
1920 ancestorOrigins : [ 'unexpected-url' ]
20- } , writable : true } ) ;
21+ } ;
2122 Object . defineProperty ( globalThis . document , 'referrer' , { value : 'unexpected-url' , writable : true } ) ;
2223 } ) ;
2324 afterEach ( ( ) => {
@@ -26,12 +27,12 @@ describe('HostInfo', () => {
2627
2728 describe ( 'getHostInfo' , ( ) => {
2829 it ( 'should get host info from search parameters' , ( ) => {
29- globalThis . location . search = new URLSearchParams ( {
30+ mockLocation . search = new URLSearchParams ( {
3031 [ MFE_HOST_APPLICATION_ID_PARAM ] : expectedHostInfo . hostApplicationId ,
3132 [ MFE_HOST_URL_PARAM ] : expectedHostInfo . hostURL ,
3233 [ MFE_MODULE_APPLICATION_ID_PARAM ] : expectedHostInfo . moduleApplicationId
3334 } ) . toString ( ) ;
34- const hostInfo = getHostInfo ( ) ;
35+ const hostInfo = getHostInfo ( mockLocation ) ;
3536 expect ( hostInfo . hostApplicationId ) . toBe ( expectedHostInfo . hostApplicationId ) ;
3637 expect ( hostInfo . moduleApplicationId ) . toBe ( expectedHostInfo . moduleApplicationId ) ;
3738 expect ( hostInfo . hostURL ) . toBe ( expectedHostInfo . hostURL ) ;
@@ -47,21 +48,21 @@ describe('HostInfo', () => {
4748 } ) ;
4849
4950 it ( 'should get host url from location ancestorOrigins' , ( ) => {
50- Object . defineProperty ( globalThis , 'location' , { value : {
51+ mockLocation = {
5152 search : '' ,
5253 ancestorOrigins : [ expectedHostInfo . hostURL ]
53- } } ) ;
54- const hostInfo = getHostInfo ( ) ;
54+ } ;
55+ const hostInfo = getHostInfo ( mockLocation ) ;
5556 expect ( hostInfo . hostURL ) . toBe ( expectedHostInfo . hostURL ) ;
5657 } ) ;
5758
5859 it ( 'should get host url from document referrer' , ( ) => {
59- Object . defineProperty ( globalThis , 'location' , { value : {
60+ mockLocation = {
6061 search : '' ,
6162 ancestorOrigins : [ ]
62- } } ) ;
63+ } ;
6364 Object . defineProperty ( globalThis . document , 'referrer' , { value : expectedHostInfo . hostURL } ) ;
64- const hostInfo = getHostInfo ( ) ;
65+ const hostInfo = getHostInfo ( mockLocation ) ;
6566 expect ( hostInfo . hostURL ) . toBe ( expectedHostInfo . hostURL ) ;
6667 } ) ;
6768 } ) ;
0 commit comments