| title | spread |
|---|
Expand an array into multiple arguments.
{% note info %}
Identical to {% url .then() then %}, but always expects an array-like structure as its subject.
{% endnote %}
.spread(callbackFn)
.spread(options, callbackFn){% fa fa-check-circle green %} Correct Usage
cy.getCookies().spread(() => {}) // Yield all cookies{% fa fa-exclamation-triangle red %} Incorrect Usage
cy.spread(() => {}) // Errors, cannot be chained off 'cy'
cy.location().spread() // Errors, 'location' does not yield an array{% fa fa-angle-right %} fn (Function)
Pass a function that expands the array into its arguments.
{% fa fa-angle-right %} options (Object)
Pass in an options object to change the default behavior of .spread().
| Option | Default | Description |
|---|---|---|
timeout |
{% url defaultCommandTimeout configuration#Timeouts %} |
{% usage_options timeout .spread %} |
{% yields maybe_changes_subject .spread 'yields the return value of your callback function' %}
cy.server()
cy.route('/users/').as('getUsers')
cy.route('/activities/').as('getActivities')
cy.route('/comments/').as('getComments')
cy.wait(['@getUsers', '@getActivities', '@getComments'])
.spread((getUsers, getActivities, getComments) => {
// each XHR is now an individual argument
})cy.getCookies().spread((cookie1, cookie2, cookie3) => {
// each cookie is now an individual argument
}){% requirements spread .spread %}
{% assertions once .spread %}
{% timeouts promises .spread %}
.spread() does not log in the Command Log
{% history %}
{% url "0.5.9" changelog#0-5.9 %} | .spread() command added
{% endhistory %}
- {% url
.each()each %} - {% url
.then()then %}