What you did:
Ran a cypress-testing-library command with a chained subject inside of a within() callback.
I expected the findByText to be scoped to the current subject yielded by the last command in the chain.
What happened:
The subject from the chained .get('#nested') is ignored - instead, the findByText is scoped to the subject yielded by the within() block above it.
TestingLibraryElementError
Timed out retrying after 4000ms: Found multiple elements with the text: /Button Text/
Problem description:
This is happening because the getContainer util used in this library gives priority to the element provided by cy.state('withinSubject'), regardless of whether there is an explicit subject provided to the command.
Suggested solution:
We should only scope to the withinSubject if cy.state('subject') returns undefined.
I have a PR up adding a new test for this functionality, and fixing the util with my suggestion.
cypress-testing-library
version: v8.0.0node
version: v14.17.3npm
(oryarn
) version: npm v6.14.13Relevant code or config
What you did: Ran a cypress-testing-library command with a chained subject inside of a
within()
callback.I expected the
findByText
to be scoped to the current subject yielded by the last command in the chain.What happened: The subject from the chained
.get('#nested')
is ignored - instead, thefindByText
is scoped to the subject yielded by thewithin()
block above it.Problem description: This is happening because the
getContainer
util used in this library gives priority to the element provided bycy.state('withinSubject')
, regardless of whether there is an explicit subject provided to the command.Suggested solution: We should only scope to the
withinSubject
ifcy.state('subject')
returnsundefined
.I have a PR up adding a new test for this functionality, and fixing the util with my suggestion.