Provide Navigator and allow locale override in test environment setup
This commit is contained in:
parent
8fc8e50bf1
commit
03d019a554
|
@ -2,10 +2,19 @@ var JSDOM = require('jsdom').JSDOM;
|
|||
|
||||
/**
|
||||
* Set up the test environment by simulating browser globals.
|
||||
* @param {string} [locale=en] A locale to set in navigator.language
|
||||
* @return {void}
|
||||
*/
|
||||
module.exports = function setUpTestEnvironment() {
|
||||
module.exports = function setUpTestEnvironment(locale) {
|
||||
if (!locale) {
|
||||
locale = 'en'
|
||||
}
|
||||
|
||||
var dom = new JSDOM('...');
|
||||
global.window = dom.window;
|
||||
global.document = dom.window.document;
|
||||
global.navigator = dom.window.navigator;
|
||||
|
||||
// JSDom has no setter defined for navigator.language, so defineProperty is necessary in order to override it
|
||||
Object.defineProperty(navigator, 'language', {value: locale})
|
||||
};
|
Loading…
Reference in New Issue