Cannot find name 'describe'. Do you need to install type definitions for a test runner?
I'm using VSCode as my IDE and in my Angular project, I had to comment-out/remove types in tsconfig.json and add jest in types at tsconfig.spec.json.
tsconfig.json
{
"compilerOptions": {
// "types": []
}
}
tsconfig.spec.json
{
"compilerOptions": {
"types": ["jest", "node"]
}
}
Simple checklist to solve this (for TypeScript and Jest).
- Make sure you have
@types/jest
and@types/node
installed. - Make sure you have linked these types in
tsconfig.json
so that:types: ["jest", "node"]
- Make sure you don't have your tests or the tests directory excluded from
tsconfig.json
configuration inexcluded
property.
If you transpile to JS then you will need a separate tsconfig.json
in your tests that includes your test files along with the necessary compiler options and files to build the appropriate context.
After fiddling with the tsconfig.json
for a while I finally figured, that commenting the "types": [],
will work.
failing config (before)
// tsconfig.json
{
"compilerOptions": {
"types": []
}
}
working config
// tsconfig.json
{
"compilerOptions": {
// "types": []
}
}