'use strict';
require('./MyComponent.less');
var React = require('react');
var MyComponent = React.createClass({
render() {
return (
<div className="my-component">
Hello World
</div>
);
}
});
module.exports = MyComponent;
现在,我想使用jest来测试这个组件。以下是我package.json
中相关的部分:
"scripts": {
"test": "jest"
},
"jest": {
"rootDir": ".",
"testDirectoryName": "tests",
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"unmockedModulePathPatterns": [
"react"
]
}
当运行
npm test
时,我遇到了以下错误:
看起来像是webpack需要在jest运行测试之前处理SyntaxError: /Users/mishamoroshko/react-component/src/tests/MyComponent.js:/Users/mishamoroshko/react-component/src/MyComponent.js:/Users/mishamoroshko/react-component/src/MyComponent.less: Unexpected token ILLEGAL
require('./MyComponent.less')
。我想知道是否需要使用类似jest-webpack的东西。如果需要,有没有办法指定多个
scriptPreprocessor
?(请注意,我已经使用了babel-jest
)