酶的安装困难

时间:2018-07-24 02:09:58

标签: reactjs testing installation jestjs enzyme

所以我一直在使用create-react-app并想实施测试。因此,我阅读并遵循了create-react-app存储库以安装Enzyme。 Enzyme intsallation link

我安装并运行了冒烟测试。

  

npm测试

import React from 'react';
import { shallow } from 'enzyme';
import App from './App';

it('renders without crashing', () => {
  shallow(<App />);
});

然后在控制台中出现此错误。

  

确定要运行的测试套件... events.js:167         投掷者//未处理的“错误”事件         ^

     

错误:生成hg EACCES       在Process.ChildProcess._handle.onexit(内部/child_process.js:217:19)       在onErrorNT(internal / child_process.js:394:16)       在process._tickCallback(internal / process / next_tick.js:174:19)在以下位置发出了“错误”事件:       在Process.ChildProcess._handle.onexit(内部/child_process.js:223:12)       在onErrorNT(internal / child_process.js:394:16)       在process._tickCallback(内部/process/next_tick.js:174:19)npm错误!测试失败。有关更多详细信息,请参见上文。

这是我的package.json:

{
      "name": "jest",
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "enzyme": "^3.3.0",
        "enzyme-adapter-react-16": "^1.1.1",
        "react": "^16.4.1",
        "react-dom": "^16.4.1",
        "react-scripts": "1.1.4",
        "react-test-renderer": "^16.4.1"
      },
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
      }
    }

如果我将“测试”脚本更改为:

"test":"jest",

然后运行

  

npm测试

此后我收到此错误:Unexpected Token

请帮助,我已经待了几个小时了。

1 个答案:

答案 0 :(得分:0)

您是否创建了文件src/setupTests.js

import { configure } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; configure({ adapter: new Adapter() });

这是必需的,请注意酶-适配器-反应-'version_specific'