I have a class in my project which has some code like below.
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;
}
}
This class is being used in one other service file which dynamically calls one of the functions of myRepo class based on some parameter.
service.js
const service=(myRepo)=>{
const queryType=getQueryType(); // Will return either 'Member' or 'Claim'
let reponse=myrepo.fnType[queryType](someParameters); // how to mock this line?
}
Using jest, how can write tests for service.js so that I am able to mock the dynamic method selection behaviour and not receive an undefined error on below line.
let reponse=myrepo.fnType[queryType](someParameters);