Skip to content
This repository has been archived by the owner on Mar 19, 2018. It is now read-only.

Commit

Permalink
fix(testSetup): setup globals before react is imported to avoid dange…
Browse files Browse the repository at this point in the history
…rouslyReplaceNodeWithMarkup

See enzymejs/enzyme#58
  • Loading branch information
kire321 committed Nov 25, 2016
1 parent 4f03a95 commit ae04fe6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -6,7 +6,7 @@
"author": "",
"scripts": {
"test": "npm-watch",
"test:all": "./node_modules/cucumber/bin/cucumber.js ./src/features --tags=@only --compiler es6:babel-core/register"
"test:all": "./node_modules/cucumber/bin/cucumber.js ./src/features --tags=@only --compiler es6:babel-core/register --require ./testSetup.js --require ./src/features"
},
"watch": {
"test:all": {
Expand Down
19 changes: 0 additions & 19 deletions src/features/support/world.js
Expand Up @@ -3,7 +3,6 @@
import register from 'ignore-styles'
register(['.scss'])
require("babel-polyfill")
const jsdom = require('jsdom').jsdom;
const tools = require('./tools');

module.exports = function() {
Expand All @@ -15,26 +14,8 @@ function World() {
this.tools = tools;
this.container = require('../../client/container');
setupConfig(this.container.get('config'));
setupDOM();
}

function setupConfig(config) {
config.update('newsService','memory');
}

function setupDOM() {
const exposedProperties = ['window', 'navigator', 'document'];

global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
exposedProperties.push(property);
global[property] = document.defaultView[property];
}
});

global.navigator = {
userAgent: 'node.js'
};
}
16 changes: 16 additions & 0 deletions testSetup.js
@@ -0,0 +1,16 @@
import {jsdom} from 'jsdom'

const exposedProperties = ['window', 'navigator', 'document'];

global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
exposedProperties.push(property);
global[property] = document.defaultView[property];
}
});

global.navigator = {
userAgent: 'node.js'
};

0 comments on commit ae04fe6

Please sign in to comment.