小编Dem*_*sso的帖子

NodeJS - 使用 Jest 运行测试:TypeScript 配置文件出现错误

我正在尝试使用 Jest 运行一些测试,但我不断收到错误。这与 TypeScript 配置文件有关,我已经搜索过但没有找到太多。我正在使用 NodeJS、TypeORM 和 TypeScript。

我在运行时收到此错误 yarn test

错误:Jest:无法解析 TypeScript 配置文件

C:\Users\demis\Documents\Projects\Personal\nlw_node\jest.config.ts TypeError: registerer.enabled 不是 readConfigFileAndSetRootDir 处的函数*** (C:\Users\demis\Documents\Projects\Personal\nlw_node\ node_modules\jest-config\build\readConfigFileAndSetRootDir.js:150:13) 在 readConfig (C:\Users\demis\Documents\Projects\Personal\nlw_node\node_modules\jest-config\build\index.js:217:18)在 readConfigs (C:\Users\demis\Documents\Projects\Personal\nlw_node\node_modules\jest-config\build\index.js:406:26) 在 runCLI (C:\Users\demis\Documents\Projects\Personal\ nlw_node\node_modules@jest\core\build\cli\index.js:230:59) 在 Object.run (C:\Users\demis\Documents\Projects\Personal\nlw_node\node_modules\jest-cli\build\cli\索引.js:163:37)

First.test.ts:

describe("First", () => {
  it("should", () => {
    expect(2 + 2).toBe(4);
  });
});
Run Code Online (Sandbox Code Playgroud)

jest.config.ts:

export default {
  bail: true,
  clearMocks: true,
  coverageProvider: "v8",
  preset: "ts-jest",
  testEnvironment: "node",
  testMatch: ["**/tests/*.test.ts"]
};
Run Code Online (Sandbox Code Playgroud)

tsconfig.json:

{
   "compilerOptions": {
      "lib": [
         "es5",
         "es6"
      ],
      "target": "es5", …
Run Code Online (Sandbox Code Playgroud)

typescript jestjs ts-jest

13
推荐指数
2
解决办法
4万
查看次数

标签 统计

jestjs ×1

ts-jest ×1

typescript ×1