![](/img/trans.png)
[英]aws-sdk-mock not mocking when using Typescript and ts-jest
[英]ts-jest cannot find type information when using monorepo style tests directory in a typescript node project
我通過使用references
和composite
設置分離了 jest 的測試類型和項目類型。 但是 ts-jest 無法在測試文件中找到類型信息並拋出多個錯誤,例如: error TS2304: Cannot find name 'expect'
。
這是目錄結構:
.
├── package.json
├── src
│ └── index.ts
├── tests
│ ├── index.test.ts
│ └── tsconfig.json
├── tsconfig.json
tsconfig.json
:
{
"compilerOptions": {
"composite": true,
},
"include": ["src"]
}
tests/tsconfig.json
:
{
"extends": "../tsconfig.json",
"references": [
{
"name": "my-lib",
"path": ".."
}
],
"compilerOptions": {
"types": ["jest"],
"rootDir": "..",
"noEmit": true
},
"include": ["."]
}
package.json
:
{
"jest": {
"preset": "ts-jest",
"environment": "node"
}
}
如何將 ts-jest 集成到這樣的項目中?
更新 jest 配置以准確定義ts-jest
tsconfig 文件:
package.json
{
"jest": {
"preset": "ts-jest",
"environment": "node",
"globals": {
"ts-jest": {
"tsconfig": "./tests/tsconfig.json"
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.