我的代码有问题 . 我正在使用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"
    }
});

为父级:

// 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"
  ]
}

我使用以下内容:

  • React v15.6.2

  • ReactDom v15.6.2

  • babel-polyfill v6.23.0

  • babel-jest v23.0.1

  • babel-preset-env v1.4.0

谢谢您的帮助