question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple matching elements error message returns only new line characters

See original GitHub issue
  • 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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
istatesidecommented, Aug 26, 2021

@leschdom that was helpful, thank you!

PR’s linked above

I think the issue is not related to which Cypress version is used, but rather that, at the time the decision was made to stop logging in Cypress, there was no default enforced maximum length on the string output. So we should be safe to bring back the behavior, since people will need to opt into a version update in dom-testing-library or cypress-testing-library to get the new logs

2reactions
leschdomcommented, Aug 26, 2021

Thanks for checking the issue @istateside !

I also did a little research some weeks ago and came across this. Here are some links I noted:

When passing in Cypress window.document to prettyDOM, it crashes because document.outerHTML.length results in Cannot read property length of undefined error. (prettyDOM error when container is document #44)

So it seems older versions of Cypress (like v3.0.x) crashed with the implementation of prettyDOM (which was later changed for different reasons). But the newer versions don’t seem to have that problem, which makes me think if either the dom-testing-library should not contain any special logic just for Cypress at all or if this logic has to be “scoped” for the old versions only (to be backwards compatible).

Hope it is somewhat useful when opening a PR 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

regex - How do I match any character across multiple lines ...
Try this: ((.|\n)*)<FooBar>. It basically says "any character or a newline" repeated zero or more times.
Read more >
Return only the portion of a line after a matching pattern
I wanted to point out that grep doesn't recognize the \n as a newline, so your first example only matches to the first...
Read more >
String
Lines are returned as one string catenated back together with newlines. Possible trailing newline is never returned. The number of matching ...
Read more >
Findstr - Search for strings - Windows CMD
Search for a text string in a file (or multiple files) unlike the simple FIND command FINDSTR ... /O Print character offset before...
Read more >
Regular Expressions: Regexes in Python (Part 1)
The returned match object appears on line 7. ... metacharacter matches any character except a newline, so it functions like a wildcard:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found