title |
---|
wrap |
Yield the object passed into .wrap()
.
cy.wrap(subject)
cy.wrap(subject, options)
{% fa fa-check-circle green %} Correct Usage
cy.wrap({ name: 'Jane Lane' })
{% 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 | Description |
---|---|---|
log |
true |
{% usage_options log %} |
timeout |
{% url defaultCommandTimeout configuration#Timeouts %} |
{% usage_options timeout cy.wrap %} |
{% yields sets_subject cy.wrap 'yields the object it was called with' %}
const getName = () => {
return 'Jane Lane'
}
cy.wrap({ name: getName }).invoke('name').should('eq', 'Jane Lane') // true
cy.get('form').within(($form) => {
// ... more commands
cy.wrap($form).should('have.class', 'form-container')
})
cy
.get('button')
.then(($button) => {
// $button is a wrapped jQuery element
if ($button.someMethod() === 'something') {
// wrap this element so we can
// use cypress commands on it
cy.wrap($button).click()
} else {
// do something else
}
})
{% requirements parent cy.wrap %}
{% assertions retry cy.wrap %}
{% timeouts assertions cy.wrap %}
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:
{% imgTag /img/api/wrap/wrapped-object-in-cypress-tests.png "Command Log wrap" %}
When clicking on the wrap
command within the command log, the console outputs the following:
{% imgTag /img/api/wrap/console-log-only-shows-yield-of-wrap.png "Console Log wrap" %}
{% history %}
{% url "3.2.0" changelog#3-2-0 %} | Retry cy.wrap()
if undefined
when followed by {% url ".should()
" should %}
{% url "0.4.5" changelog#0.4.5 %} | cy.wrap()
command added
{% endhistory %}
- {% url
.invoke()
invoke %} - {% url
.its()
its %} - {% url
.should()
should %} - {% url
.spread()
spread %} - {% url
.then()
then %}