From 926c7c7d8bc9d5cf46b7b3474884d08483b2a735 Mon Sep 17 00:00:00 2001 From: Laurent Bossavit Date: Sat, 1 Jul 2017 11:17:22 +0200 Subject: [PATCH] :white_check_mark: Permettre le test de composants React --- __tests__/helpers/browser.js | 20 ++++++++++++++++++++ package.json | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 __tests__/helpers/browser.js diff --git a/__tests__/helpers/browser.js b/__tests__/helpers/browser.js new file mode 100644 index 000000000..b7c9d4b2a --- /dev/null +++ b/__tests__/helpers/browser.js @@ -0,0 +1,20 @@ +require('babel-register')(); + +var jsdom = require('jsdom/lib/old-api').jsdom; + +var 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' +}; + +documentRef = document; diff --git a/package.json b/package.json index cf3e278a9..12a389075 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "file-loader": "^0.11.1", "html-loader": "^0.4.5", "img-loader": "^2.0.0", + "jsdom": "^11.0.0", "json-loader": "^0.5.4", "mocha": "^3.4.2", "mocha-webpack": "^0.7.0", @@ -74,6 +75,6 @@ "start": "node source/server.js", "compile": "NODE_ENV='production' webpack --config source/webpack.config.js", "surge": "npm run compile && surge --domain scientific-wish.surge.sh -p ./ && rm -rf dist/", - "test": "mocha-webpack --webpack-config source/webpack.config.js --require source-map-support/register \"__tests__/**/*.test.js\"" + "test": "mocha-webpack --webpack-config source/webpack.config.js --require source-map-support/register --require __tests__/helpers/browser.js \"__tests__/**/*.test.js\"" } }