I have this function below :- checkStatusCode
I check if a response is OK then I try to return a value and based on that I try to visit the URL (ex:- if response status is 200)
checkStatusCode(href) {
cy.request({
url: href,
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.eq(200);
return true;
});
}
This is how I call the function, but I am getting following Cypress error
Cannot read properties of undefined (reading ‘then’)
even if the assertion expect(response.status).to.eq(200)
passes, what am I doing wrong here?
navigatetoHomepage(url) {
this.checkStatusCode(url).then((isStatus200) => {
if (isStatus200) {
cy.visit(url);
} else {
cy.log("Fail");
}
});
}