testing-library / testing-library/react-testing-library
Generics not supported when using bound functions
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 19.7k
- Forks
- 1.2k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 1
Description
Describe the feature you'd like:
Happy to give this a try myself!
I've found myself repeating the same pattern of typecasting elements returned from queries when using render when I need to access specific element properties as the return type for queries is always HTMLElement as seen in the two below screenshots:
Suggested implementation:
Firstly I thought about using function overloads and literal types to fix this problem but then realised any HTML element can be assigned a role so I then thought about using generics and came across this old issue which was implemented several years ago. In that thread it said the generics got lost when using screen, which was addressed and fixed but it looks like the same problem applies to render.
I imagine the fix will be similar to that found when adding generics to screen queries
Describe alternatives you've considered:
Open to suggestions
Teachability, Documentation, Adoption, Migration Strategy:
Allow users to pass generics to queries returned from render:
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 queries returned from render and compare their generic handling with screen queries, using the linked screen-generics implementation as the reference. The work is done when callers can pass element generics to render-returned queries without repeated typecasts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react, typescript
- Domain
- frontend, testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100