Open jgoux opened 2 years ago
Experiencing similar issues with findByRole
and a Dialog that gets added to the Dom while loading the page.
get('#uc-btn-accept-banner')
β
findByText(/^accept$/i, { role: 'button' })
β
findByRole('button', { name: /^accept$/i })
β After adding hidden
to 3. findByRole('button', { name: /^accept$/i, hidden: true })
as suggested by the error log i get the following error:
Timed out retrying after 4000ms: Unable to find an element with the role "button" and name /^accept$/i
There are no available roles.
Ignored nodes: comments, <script />, <style />
<button
aria-label="Accept"
class="uc-btn-new uc-btn-accept"
id="uc-btn-accept-banner"
>
Accept
<span
id="uc-optin-timer-display"
/>
</button>
...
findByText(/^accept$/i, { role: 'button' }) β
I get typescript errors about the key not existing and it does not work as expected. If there was a span inside of the button, the span would be yielded instead of the button.
Just ran into this β surprised this doesnβt get more attention
hello, same here with the following configuration
"cypress": "^13.6.6",
"@testing-library/cypress": "10.0.1",
The code in the test:
cy.wrap(element)
.trigger('mouseenter')
.within(() => cy.findByRole('button', { name: 'container '}).click());
// etc.
In our case, the button appear after a mouseover (we use cypress trigger('mouseenter')
function in the test)
any update on this issue ?
Hello,
I think there is a race condition / an issue with matching the name of elements that are mount to the DOM during the test. I use
findByRole
along with itsname
option heavily in all my tests, but I have this one case where it doesn't seem to be able to match the element by name (a toaster with aria-role="status"). It does match the element on its role, because chaining withcontains()
makes the test pass.cypress-testing-library
version: 8.0.1node
version: v14.17.3npm
(oryarn
) version: 1.22.15cypress
: 8.6.0Relevant code or config
What you did: I run the above test
What happened: The
cy.findByRole("status", { name: /Your project has been created/i }) .should("exist");
fail with a timeout because thename
part is never found.Reproduction repository:
Problem description:
Suggested solution:
EDIT : It seems that something seriously broke cypress-testing-library when bumping to the
v8
of testing-library-dom.I just downgraded to
v7.0.7
and all my tests are back to normal.I'm not sure what changed in v8 but every
findBy*
selectors seem to enter in conflict with cypress runtime. This is why for example in the above code snippet, I had to intercept a query and wait for its result before I could call testing-library selector. If I don't, both the http query and the selector and called and stuck forever until the timeout kicks in.