]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Fix translation util tests
authorSamuel Mannehed <samuel@cendio.se>
Mon, 28 Nov 2016 15:11:47 +0000 (16:11 +0100)
committerSamuel Mannehed <samuel@cendio.se>
Mon, 28 Nov 2016 15:14:55 +0000 (16:14 +0100)
We have to temporarily replace window.navigator due to the fact that
its property languages is read-only. The tests for the translation
utilities require different values of this property. The failing tests
were added in merge of PR #718 (in commit
f5bf2d84ef1bae02dfaff068de7565664a00fba3).

tests/test.util.js

index fbce2ef8c2a80c471c76986973af69564a9f8288..bce475da720210aa42ef21c3c877db08a165875d 100644 (file)
@@ -57,6 +57,19 @@ describe('Utils', function() {
     });
 
     describe('language selection', function () {
+        var origNavigator;
+        beforeEach(function () {
+            // window.navigator is a protected read-only property in many
+            // environments, so we need to redefine it whilst running these
+            // tests.
+            origNavigator = Object.getOwnPropertyDescriptor(window, "navigator");
+            Object.defineProperty(window, "navigator", {value: {}});
+            window.navigator.languages = [];
+        });
+        afterEach(function () {
+            Object.defineProperty(window, "navigator", origNavigator);
+        });
+
         it('should use English by default', function() {
             expect(Util.Localisation.language).to.equal('en');
         });