summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2020-01-23 14:27:37 +0100
committerPierre Ossman <ossman@cendio.se>2020-01-23 14:27:37 +0100
commiteb05b45b70d1704c59b6808f4c78968b578c4182 (patch)
tree4426458f3739c9d26059b68cc2801ac0aa7c1279
parent8394462356042e03f68be9f6d815f008be5c1404 (diff)
downloadnovnc-eb05b45b70d1704c59b6808f4c78968b578c4182.tar.gz
Make afterEach() hooks work when skipping tests
Mocha will now run afterEach() hooks when tests are skipped, so we need to make them more robust against things being partially set up.
-rw-r--r--tests/test.helper.js8
-rw-r--r--tests/test.keyboard.js24
-rw-r--r--tests/test.localization.js4
-rw-r--r--tests/test.webutil.js4
4 files changed, 30 insertions, 10 deletions
diff --git a/tests/test.helper.js b/tests/test.helper.js
index 0232819..b1f438e 100644
--- a/tests/test.helper.js
+++ b/tests/test.helper.js
@@ -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 () {
diff --git a/tests/test.keyboard.js b/tests/test.keyboard.js
index b49312d..3571d39 100644
--- a/tests/test.keyboard.js
+++ b/tests/test.keyboard.js
@@ -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 () {
diff --git a/tests/test.localization.js b/tests/test.localization.js
index 9570c17..301ab79 100644
--- a/tests/test.localization.js
+++ b/tests/test.localization.js
@@ -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 () {
diff --git a/tests/test.webutil.js b/tests/test.webutil.js
index 72e1942..2a166ee 100644
--- a/tests/test.webutil.js
+++ b/tests/test.webutil.js
@@ -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 () {