spread

Expand an array into multiple arguments.

Syntax

.spread(callbackFn)
.spread(options, callbackFn)

Usage

Correct Usage

cy.getCookies().spread(() => {}) // Yield all cookies

Incorrect Usage

cy.spread(() => {}) // Errors, cannot be chained off 'cy'
cy.clock().spread() // Errors, 'clock' does not yield an array

Arguments

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().

OptionDefaultDescription
timeoutdefaultCommandTimeoutTime to wait for .spread() to resolve before timing out

Yields

  • .spread() 'yields the return value of your callback function'
  • `.spread()` wll not change the subject if `null` or `undefined` is returned.

Examples

Aliased Routes

Expand the array of aliased routes

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
  }
)

Cookies

Expand the array of cookies

cy.getCookies().spread((cookie1, cookie2, cookie3) => {
  // each cookie is now an individual argument
})

Rules

Requirements

  • .spread() requires being chained off a previous command.
  • .spread() requires being chained off a command that yields an array-like structure.

Assertions

  • .spread() will only run assertions you have chained once, and will not retry .

Timeouts

  • .spread() can time out waiting for a promise you've returned to resolve.

Command Log

.spread() does not log in the Command Log

History

VersionChanges
0.5.9.spread() command added

See also