In Cypress, there is the usage of variables like var, let, and const. While working with closures, we can use the objects that were obtained without assignment. But, this is not the case, when we are working with mutable objects.
When an object modifies its characteristics, we may need to compare its prior value to its new value.
Code Implementation
We can do the code implementation by using the below-mentioned command −
cy.get('.btn').then(($span) => {
// value capture before button click and stored in const
const n = parseInt($span.text())
cy.get('b').click().then(() => {
// value capture after button click and stored in const
const m = parseInt($span.text())
// comparison
expect(n).to.eq(m)
})
})
In the above case, we are using const variables since object $span is undergoing change. While dealing with mutable objects and their value, it is recommended to use variables of type const.
Unquestionably believe that which you stated. Your favorite justification appeared to be on the internet the easiest thing to be aware of. I say to you, I definitely get annoyed while people consider worries that they just don’t know about. You managed to hit the nail upon the top and defined out the whole thing without having side-effects , people can take a signal. Will likely be back to get more. Thanks