.each()

To iterate over the elements of a current subject, use the .each() command.

cy.get('.connectors-each-ul>li')
  .each(function($el, index, $list){
    console.log($el, index, $list)
  })
  • Lara Williams
  • William Grey
  • Monica Pharrel

.its()

To get the properties on the current subject, use the .its() command.

cy.get('.connectors-its-ul>li')
  // calls the 'length' property returning that value
  .its('length')
  .should('be.gt', 2)
  • Chai
  • Chai-jQuery
  • Chai-Sinon

.invoke()

To invoke a function on a current subject, use the .invoke() command.

cy.get('.connectors-div').should('be.hidden')

  // call the jquery method 'show' on the 'div.container'
  .invoke('show')
  .should('be.visible')
This is a div

.spread()

To spread an array as individual arguments to a callback function, use the .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')
})

.then()

To invoke a callback function with the current subject, use the .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')
})
  • Walk the dog
  • Feed the cat
  • Write JavaScript