Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

In FindAllBy and FindAll query helper types: spread Arguments to support no arguments #1230

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

Open
dturcotte wants to merge 1 commit into testing-library:main
base: main
Choose a base branch
Loading
from dturcotte:pr/custom-find-by-types

Conversation

Copy link

@dturcotte dturcotte commented May 5, 2023
edited
Loading

What: Custom queries returned by buildQueries whose implementation required no arguments (besides container) still required one argument for find* and findAll* even when used on screen or within.

Without the query-helpers.d.ts changes introduced by this PR, see these TS errors in the updated type-tests:
Screen Shot 2023年05月05日 at 11 48 12 AM

Why: There was a lot of great work done on these types here and here, I want to build on that to solve this one additional edge case.

For context on why we have queries with no arguments: we have a library with UI components that other teams consume. We also provide a few custom queries for things we don't want the consumers to worry about. For example: We provide a DataGrid component with the option to select rows. It's possible to find the input to select a row using base testing-library features but consumers shouldn't need to know how the sausage is made, for their convenience we want them to be able to simply say:
await userEvent.click(within(row).getGridRowSelectionInput())

This works, however I noticed that for the find and findAll queries the first arg is always required. It would end up looking like this to make TS happy:
await within(row).findGridRowSelectionInput(undefined)

How: Spreading Arguments in FindBy and FindAllBy types would fix this; the resulting queries should better match the types passed into buildQueries. If there are no arguments after container then the resulting query would have two: container and waitForOptions. This would also allow for more than two args if needed. Lastly, this doesn't change the fact that container is required:

Screen Shot 2023年05月05日 at 11 46 16 AM

Checklist:

  • Documentation added to the
    docs site N/A
  • Tests (in type-tests.ts, I think this is right based on previous PRs but it failed the pre-commit hook validation)
  • TypeScript definitions updated
  • Ready to be merged

Copy link

codesandbox-ci bot commented May 5, 2023

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 0781b30:

Sandbox Source
react-testing-library-examples Configuration

Copy link

codecov bot commented May 5, 2023

Codecov Report

Merging #1230 (0781b30) into main (39a64d4) will not change coverage.
The diff coverage is n/a.

@@ Coverage Diff @@
## main #1230 +/- ##
=========================================
 Coverage 100.00% 100.00% 
=========================================
 Files 24 24 
 Lines 1042 1042 
 Branches 351 347 -4 
=========================================
 Hits 1042 1042 
Flag Coverage Δ
node-14 100.00% <ø> (ø)
node-16 100.00% <ø> (ø)
node-18 100.00% <ø> (ø)

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

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link

@astorije astorije left a comment

Choose a reason for hiding this comment

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

@eps1lon, @MatanBobi, @timdeschryver, what do you all think about this? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
1 more reviewer

@astorije astorije astorije approved these changes

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /