-
Notifications
You must be signed in to change notification settings - Fork 211
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
[RFC] feat(testing-library-dom): add esm mirror of testing-library-dom #420
Conversation
I'm definitely in favor of our tests moving away from snapshot and towards testing semantics and exposed interface surface (content) rather than internal shadowdom details. One thought came up when looking at the hacks being made to the |
Also, looks like jsdom is going to very soon support custom elements: jsdom/jsdom#2548 Would this eliminate the need for some of this hackery? |
I'll take a look at what's going on with JSDom, however my understanding is that the project is targeting being spec compliant, which would leave it in the same issue of needing to patch the query code to see through the shadow DOM. As for the |
Diving into the actual implementation of My idea was to just have a simple helper which you could apply to a container element to create a Proxy over the HTMLElement instance of the container, and intercept Would definitely be better to just get this into the core library I think. |
At least a little bit of interest seems to have peeked up on that end: testing-library/dom-testing-library#413 We'll see what they think of the approach so far 🤞 |
14baf96
to
5c603b2
Compare
import alias from '@rollup/plugin-alias'; | ||
import replace from '@rollup/plugin-replace'; | ||
|
||
export default [ |
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 gets skinnier and skinnier! Now, knowing testing-library/dom-testing-library#413 (comment) I'd almost say that instead of processing the dependency that we replace it with a warning that says you need to be using this library in an environment that supports MutationObserver
to make the code to manage here even smaller.
aac8678
to
48c07eb
Compare
48c07eb
to
86dac95
Compare
0c4fde9
to
7df44bb
Compare
ffe8566
to
a8f6fb2
Compare
a8f6fb2
to
a8794d3
Compare
c5867d6
to
5ad1f22
Compare
5ad1f22
to
fe1fee0
Compare
3ba125a
to
a1f91f4
Compare
fe1fee0
to
3eaa43e
Compare
8bd318a
to
1545c67
Compare
75339d9
to
14beda1
Compare
Branch Preview URLsWhen a visual regression test fails (or has previously failed while working on this branch), its results will be avaialable at the associated URL below:
|
Tachometer results for changed packagesaction-bar permalink
sidenav permalink
|
436aeab
to
f643721
Compare
ea3ddcf
to
1190340
Compare
f05b27d
to
513aa2f
Compare
9f77111
to
9f314a3
Compare
Explainer
I really like the ideas behind the testing philosophy that
@testing-library/dom
espouses. Beyond its philosophy it also sets the table for a more uniform testing approach by focusing on the content of an element and how that content effects the accessibility of the element. However, the library is distributed with a number of CJS dependencies that prevent it from working with Karma, not to mention the issues of introspecting Shadow DOM. I'm not fully decided myself as to whether the cost outlined in this PR are worth the benefits of being able to use Testing Library generally and hoped to share my thoughts and findings to empower gather ideas in this are from the rest of the team.Description
Add an ES Module mirror of
@testing-library/dom
to the project with a little bit of Shadow DOM hacking so that we can leverage the a11y/content centric selectors of the library in our code. I was hoping to be able to avoid majorly monkey patching the actual code here, but one is needed:Even with this one change, it feels like we could easily keep up with changes upstream. That being so, I think we'd be in an OK place to take on the publishing responsibilities outline here
The switch from
querySelectorAll
toquerySelectorAllWithShadowDOM
is also trouble. I wanted to adjustHTMLElement.prototype.querySelectorAll
directly, but it alters element functionality, too. This allows the query to act more like the render does and avoid not slotted light DOM content while being able to pierce shadow roots. Being it's for tests, any performance issues seem like they'd be less devastating.Usage
Generally, the issue that
@testing-library/dom
attempts to correct for in the testing lifecycle is the tendency to rely too heavily on implementation details to ensure coverage.One place where this arises in the use of snapshot testing, while the DOM is one form of output for an element it is subsequently reprocessed at its intersection with CSS in a way that can find it changing more often than a human can process the diffs in a snapshot test. Here I've shown how ensuring that actual content (and not just a specific DOM element) is available can replace this sort of test. Notice the change in the
sp-actionbar
test to no longer rely on snapshot testing and instead query elements by content rather than by structure or selector.Even when not relying on snapshot testing, it is easy to fall into the trap of relying on DOM implementation testing. See the changes to
sp-sidenav
that updates a recently created test to rely on presence of content as opposed to the details of a template. The value of this may not be immediately clear for this element in particular, but imaging a world where the expanded content needed to be displayed in an overlay, in that way thequeryByText(el, 'Section 1')
calls would only need theel
to be updated todocument
in order to use the same over structure of test, greatly reducing refactoring costs. This would be very clearly felt via #157 which will require just that sort of change.Motivation and Context
While testing a unit of shadow DOM is pretty straight forward the steps required to move towards integrations or e2e testing can be less clear, this will hopefully surface some possibilities there.
How Has This Been Tested?
It's test?
Types of changes
Checklist: