创建反应应用程序错误 - 找不到名称'describe'



我正在使用带有Jest的create-react应用程序,并收到以下错误:

Cannot find name 'describe'.
Do you need to install type definitions for a test runner?
Try `npm i @types/jest`
or `npm i @types/mocha`
and then add `jest` or `mocha` to the types field in your tsconfig.

我看到了这个问题,但我无法按照建议删除types属性,所以这对我没有帮助。

还试图把所有的东西都放在依赖关系中。。。如果我运行npm test,测试正在运行,但我在IDE中遇到了很多错误。

我的tsconfig.json:

{
"compilerOptions": {
"experimentalDecorators": true,
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"types": ["reflect-metadata","node"],
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"strictPropertyInitialization": false,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"emitDecoratorMetadata": true   
},
"include": [
"src",
"node_modules/@types/jest"
]
}

我的package.json:

{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.9.2",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/node": "^12.12.27",
"@types/react": "^16.9.19",
"@types/react-dom": "^16.9.0",
"@types/react-redux": "^7.1.7",
"@types/react-router": "^5.1.4",
"@types/redux-logger": "^3.0.7",
"add": "^2.0.6",
"axios": "^0.19.2",
"class-transformer": "^0.2.3",
"class-validator": "^0.11.0",
"connected-react-router": "^6.7.0",
"history": "^4.10.1",
"immer": "^5.3.4",
"inversify": "^5.0.1",
"inversify-react": "^0.4.3",
"log4js": "^6.1.2",
"loglevel": "^1.6.7",
"loglevel-plugin-prefix": "^0.8.4",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-intl": "^3.12.0",
"react-intl-redux": "^2.2.0",
"react-redux": "^7.1.3",
"react-router": "^5.1.2",
"react-scripts": "3.3.1",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"reflect-metadata": "^0.1.13",
"typescript": "~3.7.5"
},
"devDependencies": {
"@craco/craco": "^5.6.3",
"@types/jest": "^24.0.0",
"@types/react-intl-redux": "^0.1.14",
"@types/redux-mock-store": "^1.0.2",
"@typescript-eslint/eslint-plugin": "^2.19.0",
"@typescript-eslint/parser": "^2.19.0",
"cross-env": "^7.0.0",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jest": "^23.7.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-react-hooks": "^2.3.0",
"husky": "^4.2.1",
"lint-staged": "^10.0.7",
"prettier": "^1.19.1",
"redux-mock-store": "^1.5.4"
},
then add `jest` or `mocha` to the types field in your tsconfig.

运行测试时收到的错误消息建议将jest添加到types字段中,但您只有以下内容:

"types": ["reflect-metadata","node"],

将其更改为具有

"types": ["reflect-metadata","node", "jest"],

我想这是Javascript项目的一个常见问题。您可以尝试在找不到解决方案名称描述:

还有一个问题,我在参考问题中没有提到,那就是你没有在根目录中用VS代码打开你的项目。

解决方案是:

  • 使用其根目录打开项目

相关内容

  • 没有找到相关文章

最新更新