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

973
Vistas
ReferenceError: TextEncoder is not defined with mongodb nodes

I am trying to run jest test cases but I am facing error -

ReferenceError: TextEncoder is not defined .

Node version -14.18.0.

Mongodb NPM - 4.1.3 .

Typescript version - 4.4.3.

Below is my test code --

beforeAll(() => {
  connection = new Connection();
});

Below is my connection class code

import { MongoClient, Db, MongoClientOptions } from 'mongodb';

class MongoConnection {
  
public async conn(){
    await MongoClient.connect('', options);
}
}

Error --

FAIL connection.test.ts

● Test suite failed to run

ReferenceError: TextEncoder is not defined

  
> 1 | import { MongoClient, Db, MongoClientOptions } from 'mongodb';
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Ok the problem got solved.

I have added at the top --

global.TextEncoder = require("util").TextEncoder;
global.TextDecoder = require("util").TextDecoder;

Not sure why the error was showing.

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