Not able to return a value inside each loop in Cypress with Typescript. patientBalance
value is undefined.
Main class code
let patientBalance: number = getPatientBalance(claimNumber);
Function as below:
let amountInDollar1: string[];
let amount1: number;
export let getPatientBalance = (claimNumber: string) => {
getClaimNumberCells().each((input, index) => {
const claimText = input.text();
getChargesTable().scrollTo('right');
if (claimText.includes(claimNumber)) {
getPatientBalanceCell()
.eq(index)
.each((data) => {
amountInDollar1 = data.text().split('$');
amount1 = parseFloat(amountInDollar[1]);
console.log('Amount in loop', +amount1);
});
}
});
return amount1;
};
Also, I want to use this patientBalance
at multiple points throughout the test. How can I assign this value to a variable?