【发布时间】:2015-11-26 16:51:51
【问题描述】:
我正在尝试测试一个反应组件。
Foo.jsx
import * as React from 'react';
require('css/foo'); // foo.scss but using resolve in the webpack
...rest of code
Foo.spec.js(这只是一个测试的锅炉)
import * as React from 'react';
import * as TestUtils from 'react-addons-test-utils';
import Foo from '../src/js/Foo';
function setup() {
const renderer = TestUtils.createRenderer();
renderer.render(<Menu />);
const output = renderer.getRenderOutput();
return {
props: props,
output: output,
renderer: renderer
}
}
describe('Menu Component', () => {
it('should render', () => {
setup();
})
});
tests.js
function noop() {
return null;
}
require.extensions['.scss'] = noop;
尝试从 CLI 加载 mocha 时
./node_modules/.bin/mocha tests.js ./test/**/*.spec.js
我遇到了一个错误
Error: Cannot find module 'css/foo' ...
我试过了: Handle WebPack CSS imports when testing with Mocha
但它也不起作用。
如果我注释掉该行,则测试正在执行。
【问题讨论】:
标签: javascript reactjs mocha.js webpack