docs: es6 lodash examples

This commit is contained in:
Brian Mann
2017-06-30 12:38:38 -04:00
parent 28f6b394ee
commit c10735183c
+10 -9
View File
@@ -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])
})