Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

313
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda