Skip to content

feat: add generics to screen queries #1034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 29, 2021
Merged

Conversation

timdeschryver
Copy link
Member

@timdeschryver timdeschryver commented Sep 20, 2021

What:

Adding generics to screen queries.
Follow up to #1023, which added generics to query methods
Closes #1033

Why:

So users that use screen queries can also use generics.

screen.getByRole('button') as HTMLButtonElement
// becomes
screen.getByRole<HTMLButtonElement>('button')

How:

  • Added a type test and saw it fail.
  • Refactored BoundFunction to a generic type that removes the first argument (the container)
  • Manually added all of the queries to the screen type because it isn't possible to reuse the queries while keeping the generic

Checklist:

  • Documentation added to the
    docs site
  • Tests
  • TypeScript definitions updated
  • [] Ready to be merged

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 20, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit feb9b15:

Sandbox Source
react-testing-library-examples Configuration
react-testing-library demo Issue #1033

@codecov
Copy link

codecov bot commented Sep 20, 2021

Codecov Report

Merging #1034 (feb9b15) into main (669602c) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #1034   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines          920       920           
  Branches       284       284           
=========================================
  Hits           920       920           
Flag Coverage Δ
node-12 100.00% <ø> (ø)
node-14 100.00% <ø> (ø)
node-16.9.1 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 669602c...feb9b15. Read the comment docs.

text: infer P,
options: infer Q,
container: HTMLElement,
...args: infer P
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax is available from TS v3.0.1

@nstepien
Copy link
Contributor

@timdeschryver Could you check if the generics work with within() as well?

@timdeschryver
Copy link
Member Author

@nstepien Yep, we can do that in a follow up PR when this PR is approved.

@eps1lon
Copy link
Member

eps1lon commented Sep 28, 2021

@timdeschryver Feel free to merge.

@timdeschryver timdeschryver merged commit 99bc2c0 into main Sep 29, 2021
@timdeschryver timdeschryver deleted the feat/generic-screen-queries branch September 29, 2021 07:22
@github-actions
Copy link

🎉 This PR is included in version 8.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make screen query methods generic
3 participants