16812: Another way of testing href
[arvados-workbench2.git] / src / common / redirect-to.test.ts
index 94000a98c489beb49f990987bd52b31efb318600..3dad8233034711c93fb0b3b198a6aaa458263a6e 100644 (file)
@@ -5,16 +5,19 @@
 import { storeRedirects, handleRedirects } from './redirect-to';
 
 describe('redirect-to', () => {
+    const { location } = window;
     const redirectTo = 'http://localhost/test123';
 
+    afterAll((): void => {
+        window.location = location;
+    });
+
     describe('storeRedirects', () => {
         beforeEach(() => {
-            Object.defineProperty(window, 'location', {
-                value: {
-                    href: `${window.location.href}?redirectTo=${redirectTo}`
-                },
-                writable: true
-            });
+            delete window.location;
+            window.location = {
+                href: `${location.href}?redirectTo=${redirectTo}`,
+            };
             Object.defineProperty(window, 'sessionStorage', {
                 value: {
                     setItem: jest.fn(),
@@ -34,12 +37,10 @@ describe('redirect-to', () => {
 
     describe('handleRedirects', () => {
         beforeEach(() => {
-            Object.defineProperty(window, 'location', {
-                value: {
-                    href: ''
-                },
-                writable: true
-            });
+            delete window.location;
+            window.location = {
+                href: `${location.href}?redirectTo=${redirectTo}`,
+            };
             Object.defineProperty(window, 'sessionStorage', {
                 value: {
                     getItem: () => redirectTo,