I'm in the process of upgrading Cypress from version 8 to version 13. In version 8, I was able to do something like this:
cy.getBySel('mealList-totalCalories').invoke('text').as('totalCals');
This accesses the original value of a value that will change later on once a new item is added to the meal list. Once the calorie value changes, I want to ensure the new value is equal to the previous value plus the caloric value of the item that was added. This used to work:
cy.get('@totalCals').then((totalCals) => {
console.log(totalCals) // This used to equal the original value, 2020, now is 2300.
const expected = parseInt(totalCals) + 280;
cy.getBySel('mealList-totalCalories').should('have.text', expected);
});
It appears that previously Cypress was storing the original text value of totalCals, which I could later access. However, now the totalCals value is already equal to the previous value + 280, which makes me think Cypress is just running the previous query again to access the current value.
Is there a new way to store the text of an element in Cypress for later access?
There's a switch to handle that. Please refer to as - options