-
Notifications
You must be signed in to change notification settings - Fork 252
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
Do not assume global HTMLSelectElement #550
Do not assume global HTMLSelectElement #550
Conversation
Codecov Report
@@ Coverage Diff @@
## master #550 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 13 13
Lines 684 684
Branches 214 214
=========================================
Hits 684 684
Continue to review full report at Codecov.
|
When it yields a |
I suppose you're right. It feels like that is starting to push the limits of assumptions made by this library and by the testing-library ecosystem. My understanding is that testing library expects to run against a DOM or a DOM-like thing, but not necessarily run in that environment, so assuming the global is not desirable. Maybe all usage of this "lookup from defaultView" pattern should be updated to safely guard against null. Here is another usage: Lines 259 to 260 in 0d30a79
All said, it feels much less likely that somebody would be using the testing-library ecosystem against a DOM that does not implement the spec compared with using it in a pure Node environment. Outside of Jest, most test runners I've seen do not pollute the global with DOM globals. |
Agreed.
My point being that when you have a pure Node environment you use some DOM implementation.
I think so. I think this whole "lookup from defaultView" is flawed because it assumes that the element constructor is on the
The clean solution might be to let the user plug in a callback to verify the interface.
So the vast majority of users is fine and those using exotic environments can plug in a workaround. Could be implemented in @testing-libary/dom. |
@ph-fritsche How would you suggest we proceed? Without this safety check I cannot use the latest release of this package. Overall I agree there should be a system wide solution for ensuring the library is runnable against all dom-like environments.
In theory you may be right, but in practice I think that a very strong majority of users will be using JSDOM, so my changes here are safer than what exists now, but agree there is room for improvement. As this change conforms with existing solutions within the codebase I propose we proceed in order to avoid runtime errors and then take the time to solve the larger issue. |
@nathanforce I added a helper that should solve your problem in #552. |
@nathanforce Your problem is fixed in v12.6.3 🎉 |
What: Do not assume that
HTMLSelectElement
is defined globally.Why: Running Node without a shimmed browser environment has no browser globals.
How: Following patterns elsewhere in the code, lookup HTMLSelectElement from the
document
Checklist:
I've not added any tests here. I think there may be value in a suite of tests that verifies the library functions in a non-dom environment but didn't want to bloat the PR.