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

165
Views
¿Cómo escribir pruebas para una clase usando broma para poder simular la inicialización del constructor?

Tengo una clase en mi proyecto que tiene un código como el siguiente.

myRepo.js

 class MyRepo{ constructor(){ this.fnType={ "Member":this.getMemberDetails, "Claim":this.getClaimDetails } } getMemberDetails=async({parameters})=>{ //some operation return someData; } getClaimDetails=async({parameters})=>{ //some operation return someData; } }

Esta clase se usa en otro archivo de servicio que llama dinámicamente a una de las funciones de la clase myRepo en función de algún parámetro.

servicio.js

 const service=(myRepo)=>{ const queryType=getQueryType(); // Will return either 'Member' or 'Claim' let reponse=myrepo.fnType[queryType](someParameters); // how to mock this line? }

Usando broma, ¿cómo puedo escribir pruebas para service.js para poder simular el comportamiento de selección de método dinámico y no recibir un error indefinido en la línea de abajo?

 let reponse=myrepo.fnType[queryType](someParameters);
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!