Let's say I have three spans in a div.
<div>
<span></span>
<span></span>
<span></span>
</div>
And let's say I have some janky code that counts the number of those spans and outputs the value somewhere else
<p>3</p>
In cypress I want to get the length of those spans and get the value that I've produced in my janky code and compare the two.
I've tried cy.get('div span').its('length'), but that yields the spans as an object...
You can do something like this. its('length') will return a number. <p>3</p> on invoking text gives a string, adding a + in front will convert it into a number +count.
cy.get('div span')
.its('length')
.then((len) => {
cy.get('p')
.invoke('text')
.then((count) => {
expect(len).to.equal(+count)
})
})