mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-19 14:49:43 -05:00
f947e0c55d
# Conflicts: # docs/source/guides/getting-started/installing-cypress.md
1.6 KiB
1.6 KiB
title, comments
| title | comments |
|---|---|
| spread | false |
Expand an array into multiple arguments.
{% note info %}
Similar to {% url .then() then %}, but always expects an array as it's subject.
{% endnote %}
Syntax
.spread(fn)
Usage
.spread() requires being chained off another cy command that yields an array.
{% fa fa-check-circle green %} Valid Usage
cy.getCookies.spread(function() {}) // Yield all cookies
{% fa fa-exclamation-triangle red %} Invalid Usage
cy.spread(function() {}) // Errors, cannot be chained off 'cy'
cy.location().spread() // Errors, 'location' does not yield an array
Arguments
{% fa fa-angle-right %} fn (Function)
Pass a function that expands the array into it's arguments.
Yields
Whatever was passed to the function is what is yielded.
Timeout
Examples
Aliased Routes
Expand the array of aliased routes
cy.server()
cy.route('/users/').as('getUsers')
cy.route('/activities/').as('getActivities')
cy.route('/comments/').as('getComments')
cy.wait(['@getUsers', '@getActivities', '@getComments'])
.spread(function(getUsers, getActivities, getComments){
// each XHR is now an individual argument
})
Cookies
Expand the array of cookies
cy.getCookies().spread(function(cookie1, cookie2, cookie3){
// each cookie is now an individual argument
})
Command Log
spread does not log in the command log
See also
- {% url
.each()each %} - {% url
cy.getCookies()getcookies %} - {% url
.then()then %} - {% url
cy.wait()wait %}