You are having trouble with the “Cannot find name ‘describe'” error in TypeScript. This article will show you the solutions to resolve this problem quickly. Read on it now.
The cause of the “Cannot find name ‘describe'” error in TypeScript
When you try to use the describe()
function in TypeScript, an error message appears because TypeScript could not find the type definition for the package. Here is a situation when the error occurs:
How to fix this error?
The solution for this issue is installing the type definitions for the corresponding testing framework. There are 3 test frameworks you can choose to install for your project: Jest, Mocha and Jasmine.
Install the Jest test framework
If you choose to install the Jest framework, open the terminal and run this command:
npm i -D ts-jest @types/jest
After installing successfully:
- Open file tsconfig.json.
- Look for object ‘compilerOptions’.
- Add the framework you just installed in the ‘types‘ array.
{ … "compilerOptions": { "types": [ "jest", … ], } … }
Install the Mocha test framework
In case you use the Mocha framework, run the following command in the terminal to install:
npm i -D @types/mocha mocha
Just like you install the Jest framework, open the tsconfig.json file and find the object ‘compilerOptions’, then add the framework you just installed in the ‘types‘ array. Here is your tsconfig.json:
{ … "compilerOptions": { "types": [ "mocha", … ], } … }
Install the Jasmine test framework
Run the following command to install Jasmine in your project:
npm i -D @types/jasmine jasmine
Similar to the above two approaches, you must add typing in the ‘types‘ array after installing successfully. Here is your tsconfig.json when you install Jasmine:
{ … "compilerOptions": { "types": [ "jasmine", … ], } … }
You can also use the import
statement at the top of each file where you want to use the describe()
function instead of editing the tsconfig.json file. See the following example:
import "jest"; describe("demo", () => { it("prime number", () => { expect(19).toBe(true); }); });
If the error persists, check if the ‘include‘ array is set in the tsconfig.json file or not. If yes, ensure that the array elements match the directory paths where your test files are located. Doing so will help Typescript not miss the directory of your test files.
For instance, you place the test files in the ‘test_files‘ folder. You must add this directory into the ‘include‘ array so that Typescript can find them:
{ "compilerOptions": {}, "include": [ "test_files/**/*" ] }
Note: In some cases, it would be helpful to restart the IDE after successfully installing and configuring the type definitions.
Summary
Above are some solutions that I have suggested to help you fix the error “Cannot find name ‘describe'” in TypeScript. Try using one of the methods and see the result. Good luck with your chosen solution.
Maybe you are interested:
- Ignore ‘Property does not exist on type’
- Cannot redeclare block-scoped variable in TypeScript
- Cannot find name ‘jQuery’ Error in TypeScript

My name’s Christopher Gonzalez. I graduated from HUST two years ago, and my major is IT. So I’m here to assist you in learning programming languages. If you have any questions about Python, JavaScript, TypeScript, Node.js, React.js, let’s contact me. I will back you up.
Name of the university: HUST
Major: IT
Programming Languages: Python, JavaScript, TypeScript, Node.js, React.js