-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8c1d91
commit 9ce2bb0
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/@glimmer-workspace/integration-tests/test/html/template-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { defineComponent, jitSuite, RenderTest, test } from '../..'; | ||
|
||
class TemplateElementTest extends RenderTest { | ||
static suiteName = '<template> (HTML template - declarative shadow dom)'; | ||
|
||
@test | ||
'<template> element can render'() { | ||
const Bar = defineComponent({}, '<template shadowrootmode="open" data-no><p>hi</p></template>'); | ||
|
||
this.renderComponent(Bar); | ||
|
||
/** | ||
* This is really hard to create a test for, because there is no JavaScript | ||
* api te assert that this succeeds without rendering it in to a browser. | ||
* So, to render this, they blog article here: | ||
* https://web.dev/articles/declarative-shadow-dom | ||
* | ||
* Recommends the following: | ||
* | ||
* (function attachShadowRoots(root) { | ||
root.querySelectorAll("template[shadowrootmode]").forEach(template => { | ||
const mode = template.getAttribute("shadowrootmode"); | ||
const shadowRoot = template.parentNode.attachShadow({ mode }); | ||
shadowRoot.appendChild(template.content); | ||
template.remove(); | ||
attachShadowRoots(shadowRoot); | ||
}); | ||
})(document); | ||
For now, since the template element is special, and only allows | ||
4 attributes, I've added a fake one, and asserted that it doesn't exist | ||
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template | ||
*/ | ||
this.assertHTML('<template shadowrootmode="open"><p>hi</p></template>'); | ||
} | ||
} | ||
|
||
jitSuite(TemplateElementTest); |