The Problem
I am trying to setup a typescript project with jest. However typescript does not seem to pickup the jest types from @types/jest
, which is highlighting my keywords giving me the following error:
Cannot find name 'test'. Do you need to install type definitions for a test runner? Try 'npm i @types/jest' or 'npm i @types/mocha'. ts(2582)
Notes:
- I am using VS Code
- I have installed @types/jest
- I have attempted to reinstall all my packages
- I have reloaded my editor
- Here is my tsconfig.json
{
"compilerOptions": {
"types": ["jest", "node"]
},
"types": ["jest"],
"typeRoots": ["./src/types", "./node_modules/@types"],
}
- Here is my jest.config.js
module.exports = {
preset: 'ts-jest',
roots: ['<rootDir>/src'],
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
};
- Here is my .babelrc
{
"presets": [
["@babel/preset-env", {"targets": {"node": "current"}}],
"@babel/preset-typescript"
],
"plugins": ["@babel/transform-runtime"]
}
- Here are the dev dependencies in my package.json
My test runs fine with npm run test
, But it is still an annoying issue which I imagine is just a missing ./
in one of my configurations or something. Bit new to typescript/jest though so could be something else. Hopefully I have provided enough info, but am happy to add more if necessary Any help would be appreciated, cheers
The Problem
I am trying to setup a typescript project with jest. However typescript does not seem to pickup the jest types from @types/jest
, which is highlighting my keywords giving me the following error:
Cannot find name 'test'. Do you need to install type definitions for a test runner? Try 'npm i @types/jest' or 'npm i @types/mocha'. ts(2582)
Notes:
- I am using VS Code
- I have installed @types/jest
- I have attempted to reinstall all my packages
- I have reloaded my editor
- Here is my tsconfig.json
{
"compilerOptions": {
"types": ["jest", "node"]
},
"types": ["jest"],
"typeRoots": ["./src/types", "./node_modules/@types"],
}
- Here is my jest.config.js
module.exports = {
preset: 'ts-jest',
roots: ['<rootDir>/src'],
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
};
- Here is my .babelrc
{
"presets": [
["@babel/preset-env", {"targets": {"node": "current"}}],
"@babel/preset-typescript"
],
"plugins": ["@babel/transform-runtime"]
}
- Here are the dev dependencies in my package.json
My test runs fine with npm run test
, But it is still an annoying issue which I imagine is just a missing ./
in one of my configurations or something. Bit new to typescript/jest though so could be something else. Hopefully I have provided enough info, but am happy to add more if necessary Any help would be appreciated, cheers
@types/jest
already and have jest as a dependency in my package json. I attempted the typeAquisition solution, but no luck there either