Console log inside if block prints but return value is empty, why ? i have create let emailHtml varaible to whom i am assigning value in the block
cy.request('GET', `https://api.testmail.app/api/json?apikey=${APIKEY}&namespace=${NAMESPACE}&tag=dev`).then(
(response) => {
if (response.body.emails.length != 0) {
response.body.emails.forEach((email: any) => {
if (email.subject === subject) {
emailHtml = email.html;
console.log(emailHtml); // prints
}
});
}
if (response.body.emails.length === 0) {
cy.wait(3000);
TestMailService.getLatestEmail(subject, ++attempts);
}
},
);
console.log(emailHtml); // empty
return emailHtml;
}