-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
React Testing Library API types prevent usage of SVG elements #830
Comments
|
Oh, hadn't thought of that.
And I would be willing to put up a PR, but as I noted at the end of my issue, I'm having issues with the |
Commit with |
I've committed and opened a pull request, #833. |
Closed in #833 and released:
|
Should there not be a corresponding update to DOM Testing Library for these types? All of the queries take a container of type |
React Testing Library isn't written in TypeScript, it bundles types for the convenience of users but they aren't checked within the project beyond type tests. As a result, it doesn't matter what the types of DOM Testing Library are, they will continue to work. React Testing Library also replaces those queries with ones bound to rendered React elements, and those are already accurate because there is no element argument for the type check to fail against. This shouldn't break anything in the other libraries, but I'll still update them for consistency so users can use SVG elements. |
I suppose I should have clarified that by incompatible I was specifically referring to the types, not the actual JS implementations. The updated Appreciate the updates! |
React Testing Library queries have no |
I specifically was seeing an issue in a utility function in use in one of my company's repos that utilizes DOM Testing Library functions, but is sometimes supplied a container resulting from React Testing Library's |
In that case, you should be able to pass it an |
✨ This is an old work account. Please reference @brandonchinn178 for all future communication ✨ Retrospectively, should this have been a major version bump? This is a breaking change, and our |
We consider this a bugfix hence the SemVer patch. These can be considered breaking changes in dependent code but that means the dependent code relied on a bug. |
✨ This is an old work account. Please reference @brandonchinn178 for all future communication ✨ Did |
I considered it to be a bug fix in the types, as the types should have allowed what was allowed at runtime. Therefore the fix was semver minor, bumping from 11.2.0 to 11.2.1. If you want different developers or environments to use the same dependency versions, commit your package lock file. If you're getting errors with the DOM Testing Library API, this pull request will fix them. If you're having another issue, please open it on the appropriate repository. |
@testing-library/react
version: 11.1.1jest
25.1.0jsdom
Relevant code or config:
What you did:
Trying to set SVG as the container element for testing SVG React components.
What happened:
Typescript threw a type error stating that
render()
requires an HTMLElement.Reproduction:
I created a repository illustrating my problem.
Problem description:
React allows components to use HTML and SVG tags. SVG tags do not work properly in an HTML context, and consequently must be rendered inside an SVG context. This can be only done by using an SVG tag as the containing element. Since the API's types disallow this, users have to wrap all their SVG based components in SVG tags manually and introducing unnecessary nesting to the render output.
Suggested solution:
Propose the following patch to
@testing-library/react/types/index.d.ts
:I've implemented this patch locally in my project where I discovered the bug and it solves the issue. However, I'm having difficulty committing my patch to
react-testing-library
due todtslint
commit hook rejecting the types in the React dependency.The text was updated successfully, but these errors were encountered: