Files
cypress/docs/source/api/utilities/_.md
T
2017-05-15 14:10:01 -04:00

901 B

title: cypress-underscore comments: true

Cypress._.method()

Cypress automatically proxies Underscore and exposes it as Cypress._

Call any valid Underscore method with Cypress._


Usage

Use _.each

// set local reference to underscore
var _ = Cypress._

cy.get("li").then(function($li){
  // use the _.each function
  _.each($li.get(), function(el, i){

    // use Cypress.$(...) to wrap the DOM element
    // into a jQuery object
    expect(Cypress.$(el).parent()).to.match("ul")
  })
})

Chain underscore methods

cy
  // use the _.chain, _.pluck, _.first, and _.value functions
  .request('http://jsonplaceholder.typicode.com/users').then(function(response){
    var _ = Cypress._
    var ids = _.chain(response.body).pluck('id').first(3).value()

    expect(ids).to.deep.eq([1, 2, 3])
  })