Cannot find name 'it' in Jest TypeScript
For me, the problem was that my tsconfig.json
was built with
"include": [
"src"
]
I had to change that to
"include": [
"src",
"tests"
]
(My tests all being in directory 'tests')
Install
npm install -D 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"]
}
In tsconfig.json add the below code
"types": ["jest"],
"typeRoots": ["./src/types", "node_modules/@types"],