cannot find name it in jest typescript

后端 未结 4 1257
Happy的楠姐
Happy的楠姐 2020-12-30 02:40

I try to create an intial setup for jest in react + typescript.I have completed the initial setup and try to check whether the test runs. When i run the test using the comma

4条回答
  •  一向
    一向 (楼主)
    2020-12-30 03:15

    Install

    npm install jest @types/jest ts-jest
    

    jest.config.js -- at root

     module.exports = {
      roots: ['/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"]
      }
    

提交回复
热议问题