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

312
Views
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 answers
Answer question

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 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!