]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Make afterEach() hooks work when skipping tests
authorPierre Ossman <ossman@cendio.se>
Thu, 23 Jan 2020 13:27:37 +0000 (14:27 +0100)
committerPierre Ossman <ossman@cendio.se>
Thu, 23 Jan 2020 13:27:37 +0000 (14:27 +0100)
Mocha will now run afterEach() hooks when tests are skipped, so we need
to make them more robust against things being partially set up.

tests/test.helper.js
tests/test.keyboard.js
tests/test.localization.js
tests/test.webutil.js

index 02328197c2748df1c791a702f85939ab5edb87ba..b1f438ee50f1866ac7a7295a96f99ca89427cc5f 100644 (file)
@@ -86,7 +86,9 @@ describe('Helpers', function () {
                 window.navigator.platform = "Mac x86_64";
             });
             afterEach(function () {
-                Object.defineProperty(window, "navigator", origNavigator);
+                if (origNavigator !== undefined) {
+                    Object.defineProperty(window, "navigator", origNavigator);
+                }
             });
 
             it('should respect ContextMenu on modern browser', function () {
@@ -150,7 +152,9 @@ describe('Helpers', function () {
                 }
             });
             afterEach(function () {
-                Object.defineProperty(window, "navigator", origNavigator);
+                if (origNavigator !== undefined) {
+                    Object.defineProperty(window, "navigator", origNavigator);
+                }
             });
 
             it('should ignore printable character key on IE', function () {
index b49312dd6bd670aa74b7700323480d7d477012ff..3571d39ce0e646068b6d0f1ffd6332b9230c3c2e 100644 (file)
@@ -272,7 +272,9 @@ describe('Key Event Handling', function () {
             window.navigator.platform = "Mac x86_64";
         });
         afterEach(function () {
-            Object.defineProperty(window, "navigator", origNavigator);
+            if (origNavigator !== undefined) {
+                Object.defineProperty(window, "navigator", origNavigator);
+            }
         });
 
         it('should change Alt to AltGraph', function () {
@@ -336,7 +338,9 @@ describe('Key Event Handling', function () {
         });
 
         afterEach(function () {
-            Object.defineProperty(window, "navigator", origNavigator);
+            if (origNavigator !== undefined) {
+                Object.defineProperty(window, "navigator", origNavigator);
+            }
         });
 
         it('should toggle caps lock on key press on iOS', function (done) {
@@ -413,8 +417,12 @@ describe('Key Event Handling', function () {
             this.clock = sinon.useFakeTimers();
         });
         afterEach(function () {
-            Object.defineProperty(window, "navigator", origNavigator);
-            this.clock.restore();
+            if (origNavigator !== undefined) {
+                Object.defineProperty(window, "navigator", origNavigator);
+            }
+            if (this.clock !== undefined) {
+                this.clock.restore();
+            }
         });
 
         it('should supress ControlLeft until it knows if it is AltGr', function () {
@@ -559,8 +567,12 @@ describe('Key Event Handling', function () {
             this.clock = sinon.useFakeTimers();
         });
         afterEach(function () {
-            Object.defineProperty(window, "navigator", origNavigator);
-            this.clock.restore();
+            if (origNavigator !== undefined) {
+                Object.defineProperty(window, "navigator", origNavigator);
+            }
+            if (this.clock !== undefined) {
+                this.clock.restore();
+            }
         });
 
         it('should fake a left Shift keyup', function () {
index 9570c1798a9dd02d4060e198800ffcc633f4d416..301ab79f4b71c7beaf26c2fcfa51c66f0be817cb 100644 (file)
@@ -27,7 +27,9 @@ describe('Localization', function () {
             window.navigator.languages = [];
         });
         afterEach(function () {
-            Object.defineProperty(window, "navigator", origNavigator);
+            if (origNavigator !== undefined) {
+                Object.defineProperty(window, "navigator", origNavigator);
+            }
         });
 
         it('should use English by default', function () {
index 72e194210d57b7c23439ec07979154c229508727..2a166ee05f84f168862d930cc543be4f5bf0b6a0 100644 (file)
@@ -42,7 +42,9 @@ describe('WebUtil', function () {
                 return WebUtil.initSettings();
             });
             afterEach(function () {
-                Object.defineProperty(window, "localStorage", origLocalStorage);
+                if (origLocalStorage !== undefined) {
+                    Object.defineProperty(window, "localStorage", origLocalStorage);
+                }
             });
 
             describe('writeSetting', function () {