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

154
Views
jest fn mock no funciona si no está asignado en él y asignado para cada

Estoy tratando de escribir pruebas usando jest. La integración es una llamada que tiene una función privada llamada prueba. FuncTest la llama tratando de simular la implementación antes de cada una, sin embargo, la simulación no funciona y va a la función real "prueba". cuando pongo la tarea (integration['test']=mockFn;) dentro de "it" funciona perfectamente. ejemplo de código de trabajo:

 describe('test', () => { const mockFn: jest.Mock = jest.fn(); beforeEach(async () => { const integration = new integrationTest(); }) afterEach(() => { jest.restoreAllMocks(); }); it('call mock implemntaion', async () => { integration['test']=mockFn; mockFn.mockImplementation(() => { throw new Error('error'); }); try { await integration.funcTest(); } catch (e) { expect(e).toBeInstanceOf(Error); } }); })

ejemplo de código que no funciona:

 describe('test', () => { const mockFn: jest.Mock = jest.fn(); beforeEach(async () => { const integration = new integrationTest(); integration['test']=mockFn; }) afterEach(() => { jest.restoreAllMocks(); }); it('call mock implemntaion', async () => { mockFn.mockImplementation(() => { throw new Error('error'); }); try { await integration.funcTest(); } catch (e) { expect(e).toBeInstanceOf(Error); } }); })

porque pasa esto y como solucionarlo gracias

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!