Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

322
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda