Wallabyjs React测试

时间:2016-04-21 13:06:58

标签: wallaby.js

如何使用带有React +浅渲染的Wallabyjs +带有css加载器的jsdom + webpack? 如果我没有将css导入我的组件而不使用webpack,它就可以工作。要将css导入组件我尝试使用css加载器配置webpack,但是没有定义最终错误'窗口'。

这是我当前用于测试组件的配置,它不需要css:

module.exports = function (wallaby) {
return {
  files: [
    {pattern: 'node_modules/babel-polyfill/dist/polyfill.js',   instrument: false},
  {pattern: 'node_modules/react/dist/react-with-addons.js', instrument: false},

  'src/**/*.js'
],

tests: [
  'test/**/*Spec.js'
],

compilers: {
  '**/*.js': wallaby.compilers.babel()
},
env: {
  type: 'node'
},
testFramework: 'mocha',

bootstrap: function() {
  global.expect = require('chai').expect;
},

setup: function() {
  global.React = require("react");

  // Taken from https://github.com/airbnb/enzyme/blob/master/docs/guides/jsdom.md
  var jsdom = require('jsdom').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'
  };
}

}; };

如何修改它,所以它支持将css导入组件?

0 个答案:

没有答案