Fix translation util tests

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
f5bf2d84ef).
This commit is contained in:
Samuel Mannehed 2016-11-28 16:11:47 +01:00
parent ffa819eec1
commit 77bc3a551b
1 changed files with 13 additions and 0 deletions

View File

@ -57,6 +57,19 @@ describe('Utils', function() {
}); });
describe('language selection', 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() { it('should use English by default', function() {
expect(Util.Localisation.language).to.equal('en'); expect(Util.Localisation.language).to.equal('en');
}); });