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

Leverage levenshtein distance to help users debug easily when there are close matches

Open
#582 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the feature you'd like:

Sometimes, due to minor typo or an extra space here and there, a match is not successful and queries throw the error. Due to the typo being non-obvious (like double-space or a dash instead of em-dash etc), it isn't always an instantaneous pin-point to where the problem is.

I think it might be very useful for the users if they see something like this:

Unable to find an element with exact match: 15-25

Found close matches. Did you mean one of these:
  15–25
  19–22

<div>
	<ul> ... </ul>
</div>
Suggested implementation:

When a candidate node is tested for a match, also calculate levenshtein distance from its textContent to the target string, and push the score to an array (along with the node itself). After all nodes are tested, and no match is found, sort the array on distance score and suggest top 3 close candidates to the user.

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

No files or tests are named in the issue. Start by locating the query-matching and error-reporting paths, then determine how close candidates should be selected and displayed; done means failed queries present useful close-match suggestions without changing successful matches.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.