【发布时间】:2021-03-14 06:46:21
【问题描述】:
问题
我正在尝试用 jest 设置一个打字稿项目。但是 typescript 似乎没有从@types/jest 中提取笑话类型,这突出了我的关键字,给了我以下错误:
Cannot find name 'test'. Do you need to install type definitions for a test runner? Try 'npm i @types/jest' or 'npm i @types/mocha'. ts(2582)
注意事项:
- 我正在使用 VS 代码
- 我已经安装了@types/jest
- 我已尝试重新安装我的所有软件包
- 我已重新加载我的编辑器
- 这是我的 tsconfig.json
{
"compilerOptions": {
"types": ["jest", "node"]
},
"types": ["jest"],
"typeRoots": ["./src/types", "./node_modules/@types"],
}
- 这是我的 jest.config.js
module.exports = {
preset: 'ts-jest',
roots: ['<rootDir>/src'],
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
};
- 这是我的 .babelrc
{
"presets": [
["@babel/preset-env", {"targets": {"node": "current"}}],
"@babel/preset-typescript"
],
"plugins": ["@babel/transform-runtime"]
}
- 这是我的 package.json 中的开发依赖项
我的测试在npm run test 上运行良好,但这仍然是一个烦人的问题,我想这只是在我的配置或其他东西中缺少./。对 typescript/jest 有点陌生,但可能是别的东西。希望我已经提供了足够的信息,但如果有必要,我很乐意添加更多任何帮助将不胜感激,干杯
【问题讨论】:
-
@StefanWang 我已经安装了
@types/jest,并且在我的包 json 中有 jest 作为依赖项。我尝试了 typeAquisition 解决方案,但也没有运气????谢谢你的建议
标签: javascript node.js typescript jestjs config