
Description
shadow-dom-testing-library extends DOM Testing Library so you can query elements inside shadow DOM. DOM Testing Library does not check shadow roots, which makes it hard to find something like a button nested inside a shadow root. This library adds a Shadow-prefixed version of each query type. Its screen object comes with the query functions bound to the document, and every query accepts a shallow option that searches only one shadow root deep. It also exports deepQuerySelector and deepQuerySelectorAll for finer control, and a within function that binds the queries to a particular container element. The README warns that the shadow and deep queries recurse through every shadow root, which can find unintended elements in tests, and that recursing can be expensive in a DOM with many elements. For setup, Jest users need jsdom 16.2 or later and Jest 26.2 or later. The README describes the library as very new and asks users to report any issues they find.…
Highlights
- Shadow-prefixed queries for shadow DOM
- Screen object and within helpers
- deepQuerySelector and deepQuerySelectorAll
- Shallow option to search one shadow root deep
- Requires jsdom 16.2+ and Jest 26.2+ for Jest users
Ratings & Reviews
No ratings yet
Be the first to rate shadow-dom-testing-library.
People also visit
shadow-dom-testing-library FAQ
What problem does it solve?
DOM Testing Library does not check shadow roots, so elements nested inside them, such as a button, are hard to query. This library adds shadow queries.
How do I query shadow elements?
Each query has a version with a Shadow prefix before the query type. You can use these through the screen object, or through a within container.
What is the shallow option?
It limits a query to one shadow root deep. The README says a recurseDepth option may come in the future.
Which versions does it need?
For Jest, the README says you need jsdom 16.2 or later and Jest 26.2 or later.
Are there risks with deep queries?
Yes. The README warns that shadow and deep queries recurse through every shadow root, so they can find unintended elements, and that they can be expensive on large DOMs.
What are the best shadow-dom-testing-library alternatives?
Popular alternatives to shadow-dom-testing-library include query-selector-shadow-dom, @webcomponents/shadydom and @lwc/synthetic-shadow. See all shadow-dom-testing-library alternatives















