Reactjs TypeError:environment.teardown在应用解决方案后不是jest中的函数错误
我正在使用Linux Mint操作系统。我正在react.js中学习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'
测试
。我使用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);
});
});
我正在犯错误
我读书。按照那个帖子的指示,我做了以下步骤
但是我仍然收到错误。您不需要安装
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"
}