Skip to content

Multiple matching elements error message returns only new line characters #172

Open
@aitchiss

Description

@aitchiss
  • cypress-testing-library version: 7.0.3
  • node version: 14.14.0
  • npm (or yarn) version: yarn 1.22.5

Relevant code or config

// In the test file
findByLabelText('Label 1');

// In the HTML
<label for="by-text-input">Label 1</label>
<input type="text" placeholder="Input 1" id="by-text-input" />

<label for="by-text-input-1">Label 1</label>
<input type="text" placeholder="Input 1" id="by-text-input-1" />

What you did:

Run a Cypress test using the query cy.findByLabelText('Label 1') where more than one matching element existed on the page

What happened:

The expected TestingLibraryElementError is displayed, but the text below "Here are the matching elements:" contains only new line characters. See a screenshot of an example below:

screenshot showing the error and a large blank space underneath

NB: this screenshot is taken after I:

  • downloaded the cypress-testing-library repo
  • Added an extra input with "Label 1" to the test app
  • Ran the find* dom-testing-library commands spec

Suggested solution:

If it is possible to include the list of matching elements in the error message it will make failures much easier to debug, especially in CI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions