Multiple matching elements error message returns only new line characters
See original GitHub issuecypress-testing-library
version: 7.0.3node
version: 14.14.0npm
(oryarn
) 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:

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:
- Created 3 years ago
- Reactions:4
- Comments:6 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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
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:
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 😃