2019-02-16 21:01:30 +08:00
|
|
|
var JSDOM = require('jsdom').JSDOM;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up the test environment by simulating browser globals.
|
2019-03-05 05:09:52 +08:00
|
|
|
* @param {string} [locale=en] A locale to set in navigator.language
|
2019-02-16 21:01:30 +08:00
|
|
|
* @return {void}
|
|
|
|
*/
|
2019-03-05 05:09:52 +08:00
|
|
|
module.exports = function setUpTestEnvironment(locale) {
|
|
|
|
if (!locale) {
|
|
|
|
locale = 'en'
|
|
|
|
}
|
|
|
|
|
2019-02-16 21:01:30 +08:00
|
|
|
var dom = new JSDOM('...');
|
|
|
|
global.window = dom.window;
|
|
|
|
global.document = dom.window.document;
|
2019-03-05 05:09:52 +08:00
|
|
|
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})
|
2019-02-16 21:01:30 +08:00
|
|
|
};
|