mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-12 10:21:07 -05:00
docs: es6 lodash examples
This commit is contained in:
@@ -27,19 +27,19 @@ cy._.keys(obj) // Errors, cannot be chained off 'cy'
|
||||
|
||||
# Examples
|
||||
|
||||
## `_.forEach`
|
||||
## `_.each`
|
||||
|
||||
```javascript
|
||||
// set local reference to lodash
|
||||
var _ = Cypress._
|
||||
// set local reference to lodash and jquery
|
||||
const { _, $ } = Cypress
|
||||
|
||||
cy.get("li").then(function($li){
|
||||
// use the _.forEach function
|
||||
_.forEach($li.get(), function(el, i){
|
||||
// use the _.each function
|
||||
_.each($li.get(), function(el, i){
|
||||
|
||||
// use Cypress.$(...) to wrap the DOM element
|
||||
// use $(...) to wrap the DOM element
|
||||
// into a jQuery object
|
||||
expect(Cypress.$(el).parent()).to.match("ul")
|
||||
expect($(el).parent()).to.match("ul")
|
||||
})
|
||||
})
|
||||
```
|
||||
@@ -49,8 +49,9 @@ cy.get("li").then(function($li){
|
||||
```javascript
|
||||
cy
|
||||
// use the _.chain, _.map, _.take, and _.value functions
|
||||
.request('http://jsonplaceholder.typicode.com/users').then(function(response){
|
||||
var ids = Cypress._.chain(response.body).map('id').take(3).value()
|
||||
.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])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user