testing-library / testing-library/dom-testing-library

Custom queries created with `buildQueries` do not play nice with `throwSuggestions`

Open
#1,189 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
3.3k
Forks
474
PR merge metrics
No merged PRs in 30d

Description

  • @testing-library/dom version: 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.