To iterate over the elements of a current subject, use the cy.each()
command.
cy
.get('.connectors-each-ul>li')
.each(function($el, index, $list){
console.log($el, index, $list)
})
To get the properties on the current subject, use the cy.its()
command.
cy
.get('.connectors-ul>li')
// calls the 'length' property returning that value
.its('length')
.should('be.gt', 2)
To invoke a function on a current subject, use the cy.invoke()
command.
cy
.get('.connectors-div').should('be.hidden')
// call the jquery method 'show' on the 'div.container'
.invoke('show')
.should('be.visible')
To spread an array as individual arguments to a callback function, use the cy.spread()
command.
var arr = ['foo', 'bar', 'baz']
cy.wrap(arr).spread(function(foo, bar, baz){
expect(foo).to.eq('foo')
expect(bar).to.eq('bar')
expect(baz).to.eq('baz')
})
To invoke a callback function with the current subject, use the cy.then()
command.
cy.get(".connectors-list>li").then(function($lis){
expect($lis).to.have.length(3)
expect($lis.eq(0)).to.contain("Walk the dog")
expect($lis.eq(1)).to.contain("Feed the cat")
expect($lis.eq(2)).to.contain("Write JavaScript")
})