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

358
Views
TypeError: ClassName.methodName no es una función

Me estoy burlando de una clase ES6 que se importa desde un módulo de nodo con broma, así:

 // creating mocks const mockMethodName = jest.fn() jest.mock('../node_modules/my-module', () => { const actualMyModule = jest.requireActual('../node_modules/my-module') return { ...actualMyModule, ClassName: jest.fn().mockImplementation(() => { return { methodName: mockMethodName } }) } }) const { ClassName } = require('my-module') // the test it('does something successfully', () => { // test logic that triggers ClassName.methodName() expect(mockMethodName).toHaveBeenCalledTimes(1) })

Pero me sale el siguiente error:

 [UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "TypeError: ClassName.methodName is not a function".] { code: 'ERR_UNHANDLED_REJECTION' }

También he intentado definir el método simulado de esta manera:

 const mockMethodName = jest.fn(() => {})
 const mockMethodName = jest.fn(() => null)
 const mockMethodName = jest.fn(() => true)
 const mockMethodName = jest.fn(() => jest.fn)

pero el error sigue ahí.

¿Qué estoy haciendo mal? ¿Cómo me burlo de la clase correctamente?

PD: el método ClassName.methodName() se llama dentro de una función asíncrona pero ClassName.methodName() no devuelve una promesa

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!