testing-library / cypress-testing-library

🐅 Simple and complete custom Cypress commands and utilities that encourage good testing practices.
http://npm.im/@testing-library/cypress
MIT License
1.8k stars 152 forks source link

Multiple elements wrongly detected #214

Closed nemonemi closed 2 years ago

nemonemi commented 2 years ago

Relevant code or config

cy.findByText(/^certificate type$/i).should('be.visible');

What you did: Trying to assert that the element is visible.

Problem description: I have a form in which there is only one Material-UI textfield.

This is the output from the test:

Timed out retrying after 5000ms: Found multiple elements with the text of: /^certificate name$/i

Here are the matching elements:

Ignored nodes: comments, <script />, <style />
<input
  aria-describedby="name-helper-text"
  aria-invalid="false"
  class="MuiInputBase-input-hieRCO MuiFilledInput-input-gnEWXF gVXmpM gqxwhg MuiFilledInput-input MuiInputBase-input Mui-disabled MuiInputBase-inputSizeSmall MuiInputBase-inputAdornedEnd"
  disabled=""
  id="name"
  name="name"
  type="text"
  value="Certificate name 6"
/>

Ignored nodes: comments, <script />, <style />
<span
  aria-label="Certificate name"
  class=""
  data-mui-internal-clone-element="true"
>
  Certificate name
</span>

image

Suggested solution: Only one element should be detected.

nemonemi commented 2 years ago

It basically detects and returns both the input and the span element that contains the label. This behavior is wrong.