最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to Access the Shadow DOM of a Custom Element in Vue Vitest - Stack Overflow

programmeradmin4浏览0评论

I’m working on a Vue component that contains a custom element with a shadow DOM. I want to test the content inside the shadow root of this custom element using Vue Test Utils. However, when I use wrapper.find("custom-element").html(), it only returns the outer HTML of the wrapper element, not the content inside the shadow DOM.

What I’ve Tried: I’ve tried using

wrapper.find("custom-element").shadowRoot

and

wrapper.find("custom-element").element.shadowRoot

, but I’m still unable to access the HTML inside the shadow DOM. Meaning this below code give null value,

 const root = await wrapper.find("custom-header").element.shadowRoot;
 console.log('***** : ', root.querySelector("nav"))

Note: the web component shadowRoot is open only.

Expected Behavior: I want to be able to access and test the content inside the shadow DOM of the custom element.

What I Need Help With: How can I correctly access the shadow DOM of a custom element in Vue Test Utils and retrieve its HTML content for testing purposes? Are there any additional steps or considerations I need to keep in mind when working with shadow DOMs in unit tests?

Any help would be greatly appreciated! Thank you in advance!

发布评论

评论列表(0)

  1. 暂无评论