我的代码有问题。我正在使用JEST&Enzyme对我的项目进行测试。
ChildComponent:
// Shortened for simplicity
Object.assign(ReactTableDefaults.column, {
style: {"textAlign": "left"},
headerStyle: {
"fontWeight": "600",
"fontSize": "0.9em",
"backgroundColor": "#DDE7ED",
"color": "#1D3557",
"borderColor": "#1D3557",
"textAlign": "left"
}
});
ParentComponent:
// Shortened for simplicity
render() {
let ChildComponent;
if (!this.state.submittedSearch) {
ChildComponent = (
<div style={{ textAlign: "center" }}>
<hr />
<h3>Please ensure that you fill up all the fields.</h3>
</div>
);
} else {
ChildComponent = (
<div>
<Row>
<ChildComponent
{...props} />
</Row>
</div>
);
这是我遇到的错误:
//Shortened for simplicity
●测试套件无法运行
E:\cv_UserTemp\*****\node_modules\react-table\react-table.css:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){.ReactTable{position:relative;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;border:1px solid rgba(0,0,0,0.1);}.ReactTable *{box-sizing:border-box}.ReactTable .rt-table{-webkit-box-flex:1;-ms-flex:auto 1;flex:auto 1;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch;width:100%;border-collapse:collapse;overflow:auto}.ReactTable .rt-thead{-webkit-box-flex:1;-ms-flex:1 0 auto;flex:1 0 auto;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;-webkit-user-select:none;-moz-
SyntaxError: Unexpected token .
17 | "fontWeight": "600",
18 | "fontSize": "0.9em",
> 19 | "backgroundColor": "#DDE7ED",
20 | "color": "#1D3557",
21 | "borderColor": "#1D3557",
22 | "textAlign": "left"
at ScriptTransformer._transformAndBuildScript (I:/*****/node_modules/jest-runtime/build/script_transformer.js:316:17)
我不确定导致此错误的原因。起初,我怀疑这与我的webpack.config.js
或.babelrc
有关。但是在修改我的代码之后,我仍然不确定发生了什么。以下是我的.babelrc
的样子:
//.babelrc
{
"presets": [
"babel-preset-flow",
"babel-preset-latest",
"babel-preset-env",
"babel-preset-stage-2",
"react",
[
"env",
{
"modules": false
}
]
],
"plugins": [
"react-hot-loader/babel"
]
}
我正在使用以下内容:
谢谢您的帮助