Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

318
Views
Jest - Cannot find name describe for jest

After a year and a half that I have finished a project, I'm about to start testing another project with Jest and there for I had installed the necessary packages on the development level:

"devDependencies": {
    "@types/jest": "^27.4.1",
    "supertest": "^6.1.6"
  }

When I have start to right automated testing code, right away I'm getting Errors warning:

Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.ts(2582)

I have search for this matter and found this article https://stackoverflow.com/questions/54139158/cannot-find-name-describe-do-you-need-to-install-type-definitions-for-a-test

As suggested I've tried to do adjustments in the tsconfig.json, but unfortunately this didn't resolve my problem. Here is my tsconfig.json:

{
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig.json to read more about this file */

    /* Language and Environment */
    "target": "es6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,

    /* Modules */
    "module": "commonjs" /* Specify what module code is generated. */,
    "types": [
      "jest"
    ] /* Specify type package names to be included without being referenced in a source file. */,

    /* Interop Constraints */
    "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
  "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,

    /* Type Checking */
    "strict": true /* Enable all strict type-checking options. */,

    /* Completeness */
    "skipLibCheck": true /* Skip type checking all .d.ts files. */
  },
  "include": ["src/**/*, tests/*.js"],
  "exclude": ["node_modules"]
}

For the tsconfig, it is also complaining the following:

No inputs were found in config file tsconfig.ts.
Specified  "include" paths where `["src/**/*, tests/*.js"]` and 'exclude' paths where '["node_modules"]'

How can I resolve these weird issues noticing that I'm not using typescript in my project and I'm not familiar with typescript at this moment.

Thank you in advanced

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After taking a break from this problem and do some research, I have manage to come up with a solution. The solution is to install the package @jest/globals

With that installed I have import it to my test file. Here is an example below:

const jest = require("@jest/globals");
const mongoose = require("mongoose");
const request = require("supertest");
const app = require("../express-app");

let server;

jest.describe("Testing Auth Service", () => {
  jest.describe("/api/v1/", () => {
    jest.beforeEach(() => {
      server = require("../index");
    });
    jest.afterAll(async () => {
      await server.close();
    });
  });
});

If there is a better approach for this, please leave a comment. I would appreciate it.

Kind regards.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!