How do I find a assertion for a value between two numbers
let lastArrayAmountValue=50;
assert.equal(lastArrayAmountValue, '5');
I want to assert whether the number is between 5-10
This is the test am doing on cypress.
CodePudding user response:
expect(lastArrayAmountValue).to.be.within(5,10)
https://docs.cypress.io/guides/references/assertions#BDD-Assertions
looks like that ability is built into cypress
CodePudding user response:
If you want to apply within
to an asynchronous element, move it into .should()
to trigger retry of the assertion.
For example,
cy.get(elementArraySelector)
.last()
.should($el => {
const value = $el.text() || 0;
expect(lastArrayAmountValue).to.be.within(5,10) // retry until timeout
})
CodePudding user response:
You can also do like this. Number is greater than equal to 5 and less than equal to 10.
cy.wrap(lastArrayAmountValue).should('be.gte', 5).and('be.lte', 10)