-
Notifications
You must be signed in to change notification settings - Fork 470
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
Queries can not find elements in open shadow dom (& weird prettyDOM output) #742
Comments
Hi @aryzing, Check out this thread: #413 TL;DR, the only way to get this support today is to use this: https://www.npmjs.com/package/testing-library__dom It works exactly the same as |
Hello! Has anyone made this change and successfully accessed elements from shadow dom? |
@aryzing Thanks for the quick answer. I can see you are testing with a click-event. Did you try to change the value in an input field? |
I too am having difficulty using the proposed replacement 'testing-library__dom', even after looking at aryzing's repo. Can this solution be documentend properly by the maintainer, as I didn't find any documentation relating to it, and the repo link in npm just points to the spectrum components repo. I tried using it, but no queries executed on the 'screen' exported by the library are able to find elements within the shadow dom. So it seems like the statement that 'It works exactly the same as @testing-library/dom except it also supports the shadow DOM' is false. Unless I'm missing something ??? Again, documentation would be nice. I'm frustrated that shadow DOM is not something supported out of the box as it is a standard part of the web platform now for a couple of years and jsdom supports it apparently. If it is not going to be supported, I (& many others!) will have to abandon @testing-library/* and use something else like Playwright, which does support shadow dom queries transparently. |
Please reopen this issue. I think shadow dom should be supported. |
Anyone know if this issue got resolved ? I have same issue of shadow dom as above mentioned. |
No this is not resolved on the testing-library app. If you have your own components wrapping imported web components, you should still be able to test your them (no need to have shadow dom supported to test that in most cases). If you have implemented your own web components and would like to test them with the testing-library app, it will not work because shadow dom is not supported for now. In htis case you can look at testing-library__dom, Stencil or Puppeteer. |
Im with the same problem. Any more suggestions? |
I agree. If this is a DOM testing library then it should be able to test all forms of DOM. |
Just recently a package appeared which makes it really easy to interact with the shadow Dom using Testing Library methods: |
@testing-library/dom
version:"7.22.0"
"26.2.2"
"16.3.0"
Relevant code or config:
After appending a custom element to the DOM,
What you did:
Queried for text that is in the DOM.
What happened:
Assertion fails b/c query is unable to find element in shadow DOM. Also, interestingly when using
prettyDOM
, the custom element is shown as an object rather than with its tag,<test-component>
:Reproduction:
(do you have a non-React Codesandbox I could use?)
Managed to pull this together in the one suggested, but even the
expect
that is working on my local fails in the codesandbox. https://codesandbox.io/s/react-testing-library-demo-forked-126wx?file=/src/__tests__/hello.jsProblem description:
The queries are described as being able to find relevant nodes in DOM, yet are unable to find elements when they are in a custom element's shadow DOM.
Suggested solution:
I'm sorry, i am unable to provide any suggestions beyond having queries meet the expectation that they find elements in the DOM, including when they are inside the shadow DOM of a custom element.
The text was updated successfully, but these errors were encountered: