I am beyond confused by Cypress and its whole "chaining" thing. I have something like the following:
The logging message returns the correct message, but returning my value is undefined. What am I missing here? I don't actually want the log message, but it was the only way to get some insight into what was going on. If I replace the cy.log
with a return, I get undefined.
const getCardUniqueByTitle = (cardSearch: string) => {
cy.get(".card-title")).each((cardTitle) => {
if (cardTitle.text().indexOf(cardSearch) >= 0) {
cy.wrap(cardTitle)
.parents("find-parents-id-here"))
.find("some field")
.find("a field within")
.invoke("text")
.then((unique) => {
cy.log(`The unique for ${cardSearch} is '${unique}'`).then(
() => {
return unique;
});
});
}
});
};
So in my test I have something like:
describe( "Get sums for enabled cards", () => {
it("sum two cards values", () => {
const card1 = getCardUniqueByTitle("foo");
const card2 = getCardUniqueByTitle("bar");
const total = String(parseInt(card1) + parseInt(card2));
cy.get(".subtotal).invoke("text").should('eq', total);
});
});