小编pau*_*krg的帖子

尝试将 Jest 与 Typescript 结合使用时,tsconfig.json 文件出现问题

我收到的错误消息是:

File 'd:/Project/server/jest.config.ts' is not under 'rootDir' 
'd:/Project/server/src'. 'rootDir' is expected to contain all source files.
The file is in the program because:
Matched by include pattern '**/*' in 'd:/Project/server/tsconfig.json'
Run Code Online (Sandbox Code Playgroud)

我的 tsconfig.json 文件是:

{
 "compilerOptions": {
    "target": "es2020",
    "module": "commonjs",

    "rootDir": "./src",
    "outDir": "./dist",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}
Run Code Online (Sandbox Code Playgroud)

我的 jest.config.ts 文件是:

export default {
    clearMocks: true,
    collectCoverage: true,
    coverageDirectory: "coverage",
    coverageProvider: "v8",
    transform: {
        "^.+\\.(t|j)sx?$": ["@swc/jest"],
    },
};
Run Code Online (Sandbox Code Playgroud)

我试图完全遵循每个文档的指示。

我在这里做错了什么?

typescript jestjs

5
推荐指数
1
解决办法
3830
查看次数

标签 统计

jestjs ×1

typescript ×1