Skip to content

fix: preserve generic query element types in render result - #1469

Open
korkt-kim wants to merge 1 commit into
testing-library:mainfrom
korkt-kim:pr/fix-render-result-query-generics
Open

fix: preserve generic query element types in render result#1469
korkt-kim wants to merge 1 commit into
testing-library:mainfrom
korkt-kim:pr/fix-render-result-query-generics

Conversation

@korkt-kim

Copy link
Copy Markdown

What:

Preserve generic element types for the built-in queries returned by render and pure.render.

Why:

RenderResult currently wraps each query with BoundFunction<Q[P]>, which loses the generic signatures provided by DOM Testing Library's BoundFunctions<Q>.

As a result, calls such as the following do not type-check as expected:

view.getByRole<HTMLButtonElement>('button')

How:

Use BoundFunctions<Q> as the source for each mapped query property.

I kept the mapped property shape instead of intersecting with BoundFunctions<Q> directly because the direct intersection exposes built-in queries as methods and triggers @typescript-eslint/unbound-method for existing destructured queries.

Type tests were added for single- and multiple-element query variants.

Checklist:

  • Documentation added to the
    docs site — N/A
  • Tests
  • TypeScript definitions updated
  • Ready to be merged

@codesandbox-ci

codesandbox-ci Bot commented Sep 1, 2026

Copy link
Copy Markdown

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 15b2ca2:

Sandbox Source
react-testing-library-examples Configuration

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant