Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs TypeError:environment.teardown在应用解决方案后不是jest中的函数错误_Reactjs_Testing_Jestjs - Fatal编程技术网

Reactjs TypeError:environment.teardown在应用解决方案后不是jest中的函数错误

Reactjs TypeError:environment.teardown在应用解决方案后不是jest中的函数错误,reactjs,testing,jestjs,Reactjs,Testing,Jestjs,我正在使用Linux Mint操作系统。我正在react.js中学习测试。我使用create react app创建了一个应用程序。我使用sudo npm I-g jest-cli安装了jest-cli。我的文件夹结构如下所示 我的测试如下 App.test.js import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; it('renders without crashing'

我正在使用Linux Mint操作系统。我正在react.js中学习
测试
。我使用
create react app
创建了一个应用程序。我使用sudo npm I-g jest-cli安装了jest-cli。我的文件夹结构如下所示

我的测试如下

App.test.js

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
  const div = document.createElement('div');
  ReactDOM.render(<App />, div);
  ReactDOM.unmountComponentAtNode(div);
});


describe('Addition', () => {
  it('knows that 2 and 2 make 4', () => {
    expect(2 + 2).toBe(4);
  });
});
我正在犯错误

我读书。按照那个帖子的指示,我做了以下步骤

  • 删除package-lock.json和node_模块
  • 从package.json中的依赖项中删除jest(这在我的设置中不存在)
  • 然后进行npm安装

  • 但是我仍然收到错误。

    您不需要安装
    jest cli
    ,这可能是导致错误的原因
    create react app
    已绑定jest,请尝试从全局依赖项中删除
    jest cli
    ,并运行
    npm test

    删除所有节点模块(删除节点模块文件夹)。然后使用
    纱线
    npm安装
    安装它们,使用
    npm测试
    纱线测试
    命令运行测试。

    谢谢@helloitsjoe。如何删除
    jest cli
    ?谢谢@helloitsjoe。我得到了这个输出
    foysal@laptop:~/Videos/my-app/client$jest-app.test.js bash:/usr/bin/jest:没有这样的文件或目录
    。谢谢。我错过了你说你从package.json中删除了jest的那部分
    npm安装jest
    (无
    -g
    ,无
    jest cli
    )谢谢@helloitsjoe。我再次收到上一个错误
    foysal@laptop:~/Videos/my app/client$jest app.test.js bash:/usr/bin/jest:没有这样的文件或目录
    。谢谢@Thuvarakan的回复。在应用您的解决方案后,我发现以下错误。
    {
      "name": "my-app",
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "axios": "^0.18.0",
        "babel-preset-es2015": "^6.24.1",
        "react": "^16.3.1",
        "react-bootstrap-sweetalert": "^4.4.1",
        "react-dom": "^16.3.1",
        "react-router": "^4.2.0",
        "react-router-dom": "^4.2.2",
        "react-scripts": "1.1.4",
        "react-smart-data-table": "^0.5.3",
        "react-table": "^6.8.2",
        "semantic-ui-react": "^0.79.1",
        "sweetalert": "^2.1.0"
      },
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
      },
      "devDependencies": {
        "babel": "^6.23.0",
        "babel-cli": "^6.26.0"
      },
      "proxy": "http://localhost:4000"
    }