Expand an array into multiple arguments.
Identical to
.then(), but always expects an array-like structure as its subject.
.spread(callbackFn)
.spread(options, callbackFn)
Correct Usage
cy.getCookies().spread(() => {}) // Yield all cookies
Incorrect Usage
cy.spread(() => {}) // Errors, cannot be chained off 'cy'
cy.location().spread() // Errors, 'location' does not yield an array
fn (Function)
Pass a function that expands the array into its arguments.
options (Object)
Pass in an options object to change the default behavior of .spread().
| Option | Default | Description |
|---|---|---|
timeout |
defaultCommandTimeout |
Time to wait for .spread() to resolve before timing out
|
.spread() 'yields the return value of your callback function' cy.intercept('/users/*').as('getUsers')
cy.intercept('/activities/*').as('getActivities')
cy.intercept('/comments/*').as('getComments')
cy.wait(['@getUsers', '@getActivities', '@getComments']).spread(
(getUsers, getActivities, getComments) => {
// each interception is now an individual argument
}
)
cy.getCookies().spread((cookie1, cookie2, cookie3) => {
// each cookie is now an individual argument
})
.spread() requires being chained off a previous command. .spread() requires being chained off a command that yields an array-like structure. .spread() will only run assertions you have chained once, and will not retry . .spread() can time out waiting for a promise you've returned to resolve. .spread() does not log in the Command Log
| Version | Changes |
|---|---|
| 0.5.9 |
.spread() command added |
© 2017 Cypress.io
Licensed under the MIT License.
https://docs.cypress.io/api/commands/spread