feat: add isInstanceOfElement helper#885
Conversation
|
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 37907da:
|
Codecov Report
@@ Coverage Diff @@
## master #885 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 26 26
Lines 951 959 +8
Branches 288 290 +2
=========================================
+ Hits 951 959 +8
Continue to review full report at Codecov.
|
But only user-event needs this? Could you only implement this in user-event and then we'll see if we need it in other places as well and whether |
|
See testing-library/user-event#552 I've opened pull requests for both so we could implement it there and wait if this PR gets merged here. As far as I know only |
|
Thanks for the suggestions. We're going to let this incubate in user-event and see if and in what form we need it in /dom. I suspect that most use-cases can live with a much simpler nodeType+localName check. That's what we're doing in dom-accessibility-api and we haven't heard any problems so far. |
Add a helper to verify the element type across libraries using
testing-library/domunder the hood.What:
Export a helper in
@testing-library/dist/helpersto determine if an element is an instance of a specificHTMLElementtype.Why:
@testing-library/user-eventrequires a better way to determine the element type.As the requirement is not specific to
user-event, I think it would be the cleaner solution to add it here.How:
The helper tries to find the element constructor on the window.
As the window is neither required to be associated with the observed document nor is it required to provide any element constructors, the helper provides a fallback for other environments than Jest+JSDOM.
Checklist:
docs site
There are no typescript definitions for internal methods at the moment.