-
Notifications
You must be signed in to change notification settings - Fork 466
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
feat: support TransitionEvent init properties #865
base: main
Are you sure you want to change the base?
feat: support TransitionEvent init properties #865
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 f83aa35:
|
aabea34
to
41864cd
Compare
Could you provide a repro that we can test in jsdom and a real browser. We need to verify this doesn't pollute actual browser tests and why this fix can't be applied upstream i.e. to jsdom. |
@eps1lon, I'm happy to do that, but can you clarify what exactly you're looking for? 😅 I'm not sure I entirely understand. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already working in a browser: https://codesandbox.io/s/jsdom-polyfill-transitionevent-bgfz1
You either want to fix that in jsdom
or apply a polyfill locally to your testing envrionment. The above codesandbox contains a test that has a minimal polyfill for TransitionEvent
.
Hi @VinceMalone could you please rebase this branch with master? |
41864cd
to
4421397
Compare
Codecov Report
@@ Coverage Diff @@
## master #865 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 26 26
Lines 951 957 +6
Branches 291 291
=========================================
+ Hits 951 957 +6
Continue to review full report at Codecov.
|
4421397
to
76bd76f
Compare
@eps1lon I added a check to see if |
Yeah, I'm not comfortable with monkey patching incomplete environments. This can become super confusing if other libraries don't do that. Why does a polyfill like https://codesandbox.io/s/jsdom-polyfill-transitionevent-bgfz1 doesn't work for you? |
The polyfill works, but this change might still be worth it for the sake of others. There's a silent failure when an event type isn't supported — because I definitely get that monkey patching this isn't really ideal, but is it worth doing (like |
I consider monkey-patching
I don't believe we're actually improving the problem. Rather we're just kicking the problem to someone else by diverging even more. Before we had JSDOM vs browsers. Now we have JSDOM vs browsers vs testing-library in JSDOM. By using testing-library you're tied to a special environment that's more and more diverging from existing environments and I don't think this is the responsible thing to do. So yeah, ultimately we should not fall back to
That's a bit debateable because in the end you're getting an I I just don't have a good feeling about these monkey-patches since we have to maintain a very specific use case ("support a partial implementation of the Transition spec") which leaves us open to "how much should we fix in testing-library?" debates. I'd be way more comfortable if we had a package like |
src/events.js
Outdated
// TransitionEvent is not supported in jsdom: https://github.com/jsdom/jsdom/issues/1781 | ||
if ( | ||
EventType === 'TransitionEvent' && | ||
window.TransitionEvent !== 'function' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
window.TransitionEvent !== 'function' | |
typeof window.TransitionEvent !== 'function' |
76bd76f
to
b0a0343
Compare
@eps1lon those are all really good points; I definitely understand the urge to resist going down this path. It's tough to balance the pros can cons of existing decisions (falling back to |
This comment is to help others who might stumble on that issue If anyone is looking for a polyfill or something, here's how we've managed to make it work with hello-pangea/dnd@5ec5a74#diff-3ab6990a471fa18593a64b7c0de508ff724cd1cd0676d882d475fb40fe624660= |
For Vitest I took the approach of I've created a codesandbox to show it working with tests/fireEvent. |
What:
Add support for the init arguments that can be passed to
TransitionEvent
—propertyName
,elapsedTime
, andpseudoElement
.Why:
This should be supported out-of-the-box, but jsdom doesn't currently support the
TransitionEvent
constructor jsdom/jsdom#1781Because
window.TransitionEvent
is undefined,window.Event
ends up being used to create the event.dom-testing-library/src/events.js
Line 50 in accb6cc
Which will, of course, ignore the transitionEventInit object.
How:
When the event is being created, look at the event type, if it's
TransitionEvent
, manually attach the aforementioned properties fromeventInit
.Checklist:
docs site