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

93
Views
Jest: mock object used inside tested function

I would like to mock an object used inside called tested function. All I have found I another tickets was calling function in tested function, but I need to replace certain object that is used there. Is something like that possible in Jest?

util.test.js

describe('testname', function () {
    it('import test', function () {
      Utils.generateRandomPoints(10); // inside this function, I'd like to mock used object
    });
});

utils.js

export function generateRandomPoints(arrayLength) {    
    const result = [];

    for (let i = 0; i < 100; i++) {
        // instead of "new Point" I'd like to use "new MockedPoint" for testing.
        result.push(new Point(i)); 
    }
    
    return result;
};
about 4 years ago · Juan Pablo Isaza
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!