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.
This commit is contained in:
Pierre Ossman 2020-01-23 14:27:37 +01:00
parent 8394462356
commit eb05b45b70
4 changed files with 30 additions and 10 deletions

View File

@ -86,7 +86,9 @@ describe('Helpers', function () {
window.navigator.platform = "Mac x86_64"; window.navigator.platform = "Mac x86_64";
}); });
afterEach(function () { afterEach(function () {
Object.defineProperty(window, "navigator", origNavigator); if (origNavigator !== undefined) {
Object.defineProperty(window, "navigator", origNavigator);
}
}); });
it('should respect ContextMenu on modern browser', function () { it('should respect ContextMenu on modern browser', function () {
@ -150,7 +152,9 @@ describe('Helpers', function () {
} }
}); });
afterEach(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 () { it('should ignore printable character key on IE', function () {

View File

@ -272,7 +272,9 @@ describe('Key Event Handling', function () {
window.navigator.platform = "Mac x86_64"; window.navigator.platform = "Mac x86_64";
}); });
afterEach(function () { afterEach(function () {
Object.defineProperty(window, "navigator", origNavigator); if (origNavigator !== undefined) {
Object.defineProperty(window, "navigator", origNavigator);
}
}); });
it('should change Alt to AltGraph', function () { it('should change Alt to AltGraph', function () {
@ -336,7 +338,9 @@ describe('Key Event Handling', function () {
}); });
afterEach(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) { 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(); this.clock = sinon.useFakeTimers();
}); });
afterEach(function () { afterEach(function () {
Object.defineProperty(window, "navigator", origNavigator); if (origNavigator !== undefined) {
this.clock.restore(); Object.defineProperty(window, "navigator", origNavigator);
}
if (this.clock !== undefined) {
this.clock.restore();
}
}); });
it('should supress ControlLeft until it knows if it is AltGr', function () { 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(); this.clock = sinon.useFakeTimers();
}); });
afterEach(function () { afterEach(function () {
Object.defineProperty(window, "navigator", origNavigator); if (origNavigator !== undefined) {
this.clock.restore(); Object.defineProperty(window, "navigator", origNavigator);
}
if (this.clock !== undefined) {
this.clock.restore();
}
}); });
it('should fake a left Shift keyup', function () { it('should fake a left Shift keyup', function () {

View File

@ -27,7 +27,9 @@ describe('Localization', function () {
window.navigator.languages = []; window.navigator.languages = [];
}); });
afterEach(function () { afterEach(function () {
Object.defineProperty(window, "navigator", origNavigator); if (origNavigator !== undefined) {
Object.defineProperty(window, "navigator", origNavigator);
}
}); });
it('should use English by default', function () { it('should use English by default', function () {

View File

@ -42,7 +42,9 @@ describe('WebUtil', function () {
return WebUtil.initSettings(); return WebUtil.initSettings();
}); });
afterEach(function () { afterEach(function () {
Object.defineProperty(window, "localStorage", origLocalStorage); if (origLocalStorage !== undefined) {
Object.defineProperty(window, "localStorage", origLocalStorage);
}
}); });
describe('writeSetting', function () { describe('writeSetting', function () {