diff --git a/src/mock-doc/serialize-node.ts b/src/mock-doc/serialize-node.ts
index 75e6d5726fa..905fce9aa84 100644
--- a/src/mock-doc/serialize-node.ts
+++ b/src/mock-doc/serialize-node.ts
@@ -132,7 +132,11 @@ function* streamToHtml(
*/
if (
tag === 'template' &&
- (!(node as Element).getAttribute || !(node as Element).getAttribute('shadowrootmode'))
+ (!(node as Element).getAttribute || !(node as Element).getAttribute('shadowrootmode')) &&
+ /**
+ * If the node is a shadow root, we want to add the `shadowrootmode` attribute
+ */
+ ('host' in node || node.nodeName.toLocaleLowerCase() === shadowRootTag)
) {
const mode = ` shadowrootmode="open"`;
yield mode;
diff --git a/src/mock-doc/test/html-parse.spec.ts b/src/mock-doc/test/html-parse.spec.ts
index 2ab979698f3..d42a5610efd 100644
--- a/src/mock-doc/test/html-parse.spec.ts
+++ b/src/mock-doc/test/html-parse.spec.ts
@@ -127,11 +127,11 @@ describe('parseHtml', () => {
text
`);
- expect(doc.head.innerHTML).toBe(`text`);
+ expect(doc.head.innerHTML).toBe(`text`);
const tmplElm: HTMLTemplateElement = doc.head.firstElementChild as any;
- expect(tmplElm.outerHTML).toBe(`text`);
+ expect(tmplElm.outerHTML).toBe(`text`);
expect(tmplElm.content?.firstChild?.textContent).toBe(`text`);
expect(tmplElm.childNodes).toHaveLength(0);
});
diff --git a/src/mock-doc/test/serialize-node.spec.ts b/src/mock-doc/test/serialize-node.spec.ts
index a7da936eb16..961990a5573 100644
--- a/src/mock-doc/test/serialize-node.spec.ts
+++ b/src/mock-doc/test/serialize-node.spec.ts
@@ -166,7 +166,7 @@ describe('serializeNodeToHtml', () => {
doc.body.innerHTML = input;
const output = serializeNodeToHtml(doc.body);
- expect(output).toBe(`text`);
+ expect(output).toBe(`text`);
});
it('svg', () => {