Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript web组件快照测试_Javascript_Web_Components_Jestjs - Fatal编程技术网

Javascript web组件快照测试

Javascript web组件快照测试,javascript,web,components,jestjs,Javascript,Web,Components,Jestjs,给定此自定义组件: const style=` div{ 颜色:红色; } `; 常量html=` 示例WEB组件 `; const$element=document.createElement('template'); $element.innerHTML=` ${style} ${html} `; 导出默认类示例扩展HtmleElement{ 构造函数(){ 超级(); this.root=this.attachShadow({mode:'closed'}); this.root.appe

给定此自定义组件:

const style=`
div{
颜色:红色;
}
`;
常量html=`
示例WEB组件
`;
const$element=document.createElement('template');
$element.innerHTML=`
${style}
${html}
`;
导出默认类示例扩展HtmleElement{
构造函数(){
超级();
this.root=this.attachShadow({mode:'closed'});
this.root.appendChild($element.content.cloneNode(true));
}

}
我也有同样的问题,只需以序列化方式获取WebComponent(innerHTML)并检查快照即可:

it('should render correctly', () => {
    const myComponent = new MyComponent();

    expect(myComponent.innerHTML).toMatchSnapshot();
});

有趣的问题。jsdom似乎是,但我在他们的文档中没有找到任何特定的内容,我想知道
document.getElementById(…).shadowRoot是否可以为您提供访问权限,您可以像对普通HTML片段那样对其进行序列化(顺便说一句,您不知道任何序列化程序,是吗?)