Description
I'm converting #100 by @tlrobinson to an issue. cc @twgraham, @intelligentspark, and @NicholasBoll.
Here's the original PR's comment (to save you a click)
What:
Changes the custom Cypress commands to respect the previously yielded subject, for example, with the following document:
<button>Button Text 1</button> <div id="nested"> <button>Button Text 2</button> </div>this
cy.get('#nested').findByText('Button Text 1').should('not.exist')would previously fail because
findByText
was not passed the result ofcy.get('#nested')
as itscontainer
(defaulting todocument
)Why:
It's a convenient way to scope commands to the result of a previous command, and for users of builtin Cypress commands it's surprising that
@testing-library/cypress
doesn't currently behave like this.How:
The
prevSubject
option is now passed toCypress.Commands.add()
(with a value of['optional', 'document', 'element', 'window']
which matches builtin commands likecontains
. This causes the subject (if any) to be passed as the first argument to the command. The subject is given lower precedence than thetesting-library
'scontainer
option, but higher precedence than the document itself.Checklist:
- Documentation N/A
- Tests
- Ready to be merged
Merging #100 caused a breaking change (#109). I've reverted it (0b73b69) and now we need to discuss whether we want to make this change and whether it's possible to solve the originally stated problem in the PR and have the testing style mentioned in #109.