Skip to content
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

fix(types): Allow all HTML and SVG elements in render. #833

Merged

Conversation

joebobmiles
Copy link
Contributor

What:

Types disallowed SVG elements, see #830.

Why:

To allow both HTML and SVG elements to be passed to React Testing Library functions without throwing type errors in TypeScript.

How:

Exchanged HTMLElement type for the broader Element type that encompasses all elements that can appear in the DOM, not just HTML.

Checklist:

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 19, 2020

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 f36ab6e:

Sandbox Source
React Configuration
react-testing-library-examples Configuration

@codecov
Copy link

codecov bot commented Nov 19, 2020

Codecov Report

Merging #833 (f36ab6e) into master (456424f) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #833   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines          140       140           
  Branches        28        28           
=========================================
  Hits           140       140           

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 456424f...f36ab6e. Read the comment docs.

@nickserv
Copy link
Member

I've noticed there are also types for Node (less specific) and HTMLOrSVGElement (more specific). Could either of those be better?

Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

I've noticed there are also types for Node (less specific) and HTMLOrSVGElement (more specific). Could either of those be better?

Element is the exact interface we need because that's what react-dom supports. Practically HTMLOrSVGElement works because only HTMLElement and SVGElement extend Element. But we don't need any properties from HTMLOrSVGElement so we should stick with the correct type.

Node would allow non-sense like Attr nodes or Text nodes.

@eps1lon
Copy link
Member

eps1lon commented Nov 19, 2020

Though there could be some fallout if we're now to generic for practical purposes. We'll see in the issue reports if we should add a type parameter for the container or if HTMLOrSVGElement is sufficient.

@eps1lon eps1lon changed the title Patched types to allow all HTML and SVG elements. fix(types): Allow all HTML and SVG elements in render. Nov 19, 2020
@eps1lon eps1lon merged commit 1dc33b2 into testing-library:master Nov 19, 2020
@github-actions
Copy link

🎉 This PR is included in version 11.2.1 🎉

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.

3 participants