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

537
Views
Error: Uncaught [TypeError:default is not a constructor] jest mock

I have a service class FooService.js which I'm using in my component

export default class FooService {
  saveInfo = (params) => {
    //method implementation here.
  };
}

I'm using this in my component Foo.tsx in saveData method as below:

const saveData = (message: string) => {
    const fooService = new FooService();
    fooService.saveInfo(params);
  };

I'm trying to mock my FooService as below in Foo.test.tsx

jest.mock('src/js/services/FooService', () => {
  return {
    _esModule: true,
    default: jest.fn().mockImplementation(() => {
      return {
        saveInfo: jest.fn(),
      };
    }),
  };

When I run my test case from Foo.test.tsx file in debug mode, I'm able to get inside saveData method. But, when I hit const fooService = new FooService(); line, it throws the following error: TypeError: FooService_1.default is not a constructor

Please let me know what is that I'm missing in jest.mock. Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Replacing _esModules with __esModules solved the issue.

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!