Skip to main content

Cypress._

Cypress automatically includes lodash and exposes it as Cypress._. Call any valid Lodash method on Cypress._

Syntax​

Cypress._.method()

Usage​

Correct Usage

Cypress._.keys(obj)

Incorrect Usage

cy._.keys(obj) // Errors, cannot be chained off 'cy'

Examples​

_.each​

// set local reference to lodash and jquery
const { _, $ } = Cypress

cy.get('li').then(($li) => {
// use the _.each function
_.each($li.get(), (el, i) => {
// use $(...) to wrap the DOM element
// into a jQuery object
expect($(el).parent()).to.match('ul')
})
})

_.chain​

cy
// use the _.chain, _.map, _.take, and _.value functions
.request('http://jsonplaceholder.typicode.com/users')
.then((response) => {
const ids = Cypress._.chain(response.body).map('id').take(3).value()

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

See also​