testing-library / testing-library/dom-testing-library
Can't query multi-line strings
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 3.3k
- Forks
- 474
- PR merge metrics
- No merged PRs in 30d
Description
@testing-library/domversion: latest- Testing Framework and version: see repro
The closest issue to this I could find was https://github.com/testing-library/dom-testing-library/issues/798 , could be related.
Relevant code or config:
https://codesandbox.io/s/react-testing-library-demo-forked-km9q0p?file=/src/__tests__/hello.js
What you did:
I attempted to find the multi-line string using 3 different techniques as seen in the commented assertions.
What happened:
Uncomment each query to see how each one fails.
Reproduction:
https://codesandbox.io/s/react-testing-library-demo-forked-km9q0p?file=/src/__tests__/hello.js
Problem description:
The meaning of an non-"exact" match is not clear.
Putting a breakpoint in the matcher function reveals that it only seems to pass the first line of multilineString as text.
Attempting to use secondParameter.textContent in the query function results in multiple matches.
Suggested solution:
Make querying multi-line strings more intuitive. If a more obscure workaround is needed, consider updating "This could be because the text is broken up by multiple elements" message.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CodeSandbox reproduction and uncomment each of the three assertions to compare their failures. Read the matcher behavior around the reported first-line-only text and determine a clear expected result for multi-line queries; done means the intended query works consistently or the guidance message explains the required workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100