cannot find name it in jest typescript

你离开我真会死。 提交于 2019-12-06 06:07:45

install ::

npm install jest @types/jest ts-jest

-- jest.config.js -- at root --

 module.exports = {
  roots: ['<rootDir>/src'],
  transform: {
    '^.+\\.tsx?$': 'ts-jest',
  },
  testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
}

----tsconfig.json---

{
    "compilerOptions": {
     ...

      "types": ["reflect-metadata", "jest"],
      "typeRoots": ["./types", "./node_modules/@types"]

     ...
    },
    "exclude": ["node_modules", "**/*.spec.ts", "**/*.test.ts"],
    "include": ["./src/**/*.tsx", "./src/**/*.ts"]
  }

Hope it will work for you... :)

In tsconfig.json add the below code

"types": ["jest"],
"typeRoots": ["./src/types", "node_modules/@types"],

Updating ts-loader to v6.0.1 or above can do a trick.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!