I have to check whether a variable is less than a constant value in Cypress. How can we achieve this?
e.g: check whether a given variable is less than 30.
I'm making a few assumptions here, but, something like the following should work.
// define constant
const maxValue = 30;
cy.get('foo') // get element with variable text
.then(($el) => { // use the yielded element in a .then()
// get the text of the element using JQuery's `.text()`
// and compare the value using Chai's `lessThan`.
expect($el.text()).to.be.lessThan(maxValue);
});
References for inline comments: