16812: Another way of testing href
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Mon, 28 Sep 2020 15:31:27 +0000 (17:31 +0200)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Mon, 28 Sep 2020 15:31:27 +0000 (17:31 +0200)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

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,