testing-library / testing-library/dom-testing-library
Custom queries created with `buildQueries` do not play nice with `throwSuggestions`
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: 8.19.0- Testing Framework and version: N/A
- DOM Environment: N/A
Relevant code or config:
// Setup
import { configure } from '@testing-library/dom';
configure({
throwSuggestions: true,
});
// Later build Custom Queries
const [
queryByCustom,
getAllByCustom,
getByCustom,
findAllByCustom,
findByCustom,
] = buildQueries(queryAllByCustom, getMultipleError, getMissingError);
(Actual example of real-world custom queries from shadow-dom-testing-library.)
What you did:
When calling one of these custom queries created with buildQueries it'll try to suggest better queries which often don't work because these queries are custom for a reason.
What happened:
Testing Library will fail the test and suggest a different query despite it not being correct.
Reproduction:
It's not easy to reproduce in CodeSandbox but hopefully the description here is clear enough.
Problem description:
Using custom queries require { suggest: false } options in many places as tests are incorrectly failing due to bad suggestions.
Suggested solution:
Easiest solution, give an option to disable suggestions when using buildQueries. Custom queries should rarely if ever be treated the same as native queries and suggestions don't make sense for them.
The perfect world solution would be to make throwSuggestions aware of all custom queries to be able to accurately suggest those too and take them into account. But I highly doubt this is possible or reasonable.
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 by tracing the buildQueries entry point and the throwSuggestions configuration described in the issue. Determine how custom queries are handled during suggestion checks, then verify that custom-query suggestions can be disabled without changing native-query behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100