【问题标题】:Why isn't ts-jest loading my custom tsconfig file?为什么 ts-jest 不加载我的自定义 tsconfig 文件?
【发布时间】:2021-08-05 02:10:42
【问题描述】:

出于某种原因,我的自定义 tsconfig 文件没有在 jest.config.ts 中被提取。这是我的 jest.config.ts:

module.exports = {
  setupFilesAfterEnv: [`./jest.setup.ts`],
  testEnvironment: `jsdom`,
  roots: [
    `<rootDir>/test`
  ],
  testMatch: [
    `**/__tests__/**/*.+(ts|tsx|js)`,
    `**/?(*.)+(spec|test).+(ts|tsx|js)`
  ],
  transform: {
    "^.+\\.(ts|tsx)$": `ts-jest`
  },
  globals: {
    "ts-jest": {
      tsConfig: `tsconfig.jest.json`
    }
  }
}

我知道正在应用此配置的其他部分。例如,如果我删除全局变量上方的键,我的测试将不会运行。另外,我知道在我的 tsconfig.jest.json 文件中指定的更改是修复我的测试的必要更改,因为如果我在我的主 tsconfig.json 文件中进行相同的更改,我的测试运行良好。

我也尝试将所需的 tsconfig 编译器选项直接放入 jest.config.ts 文件中,但这似乎也不起作用:

module.exports = {
  setupFilesAfterEnv: [`./jest.setup.ts`],
  testEnvironment: `jsdom`,
  roots: [
    `<rootDir>/test`
  ],
  testMatch: [
    `**/__tests__/**/*.+(ts|tsx|js)`,
    `**/?(*.)+(spec|test).+(ts|tsx|js)`
  ],
  transform: {
    "^.+\\.(ts|tsx)$": `ts-jest`
  },
  globals: {
    "ts-jest": {
      tsConfig: {
        jsx: `react`
      }
    }
  }
}

【问题讨论】:

    标签: reactjs jestjs next.js react-testing-library ts-jest


    【解决方案1】:

    正确的密钥是tsconfig 而不是tsConfig

    【讨论】:

    • 前几天为此苦苦挣扎了很长时间,因为还发现了那些愚蠢的文档 (huafu.github.io/ts-jest/user/config) 将您引向悬崖。 tsConfig 被忽略,tsconfig 有效。官方文档是jestjs.io/docs/getting-started
    • @Matriarx 是的,同样的事情也发生在我身上。希望这个问题最终出现在人们的谷歌搜索结果中
    猜你喜欢
    • 2022-10-17
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 2021-09-10
    • 2021-12-12
    • 2022-01-02
    • 2020-08-08
    • 2017-03-18
    相关资源
    最近更新 更多