Files
cypress/docs/source/api/commands/wrap.md
T
Loren Norman f947e0c55d Merge remote-tracking branch 'origin/master'
# Conflicts:
#	docs/source/guides/getting-started/installing-cypress.md
2017-06-13 15:49:54 -04:00

1.7 KiB

title, comments
title comments
wrap false

Yield the object passed into .wrap().

Syntax

cy.wrap(subject)
cy.wrap(subject, options)

Usage

cy.wrap() cannot be chained off any other cy commands, so should be chained off of cy for clarity.

{% fa fa-check-circle green %} Valid Usage

cy.wrap({name: "Jane Lane"})    

Arguments

{% fa fa-angle-right %} subject (Object)

An object to be yielded.

{% fa fa-angle-right %} options (Object)

Pass in an options object to change the default behavior of cy.wrap().

Option Default Notes
log true Whether to display command in Command Log

Yields

cy.wrap() yields the object that was passed into the command.

Timeout

Examples

Wrap

Invokes the function on the subject in wrap and returns the new value.

var getName = function() {
  return 'Jane Lane'
}

cy.wrap({name: getName}).invoke('name').should('eq', 'Jane Lane') // true

Command Log

Make assertions about object

cy.wrap({ amount: 10 })
  .should('have.property', 'amount')
  .and('eq', 10)

The commands above will display in the command log as:

screen shot 2017-05-31 at 3 16 58 pm

When clicking on the wrap command within the command log, the console outputs the following:

screen shot 2017-05-31 at 3 17 05 pm

See also

  • {% url .invoke() invoke %}
  • {% url .its() its %}
  • {% url .spread() spread %}
  • {% url .then() then %}