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

319
Vistas
how to test class methods with jest (on return values)

Im trying to write unit tests for class methods with jest ( new to jest) I have methods that e.g. take arrays and modify them and bring them into different form to satisfy algorithm needs. But I dont see a way how I simply can test class method receiving and returning values. Looks like there is a problem with classes, class methods cant be tested as simple functions. But if I look at the docs I dont see it covering these topics, it only covers e.g. was a class instance called, was a class method called..

Edited: this is my code example

import MyClass from "../MyClass.js";

// mocked data
const inputArrayMock=[{someObject}]
const outputArrayMock=[{modifiedObject}]

test("test MyClass method a", () => {
    const obj = new MyClass();
    const result = obj.methodA(inputArrayMock);
    expect(result).toEqual(outputArrayMock);
});

I just ran my code again, it's throwing the error:

Received: {Symbol(async_id_symbol): 293, Symbol(trigger_async_id_symbol): 281, Symbol(destroyed): {"destroyed": false}} 

Note: Both arrays (in- and output values I wrote as mock data. The expected array is correct, but the received not, which throws the error.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Without knowing your code I can only make a guess.

import MyClass from "../MyClass.js";

test("your test name", () => {
    const obj = new MyClass();
    const result = obj.theMethodYouWantToCheck();
    expect(result).toBe("the desired result");
});
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