@webcomponents/custom-elements
Version:
HTML Custom Elements Polyfill
39 lines (29 loc) • 1.07 kB
HTML
<script>;
let constructors = [];
test(() => {
assert_equals(constructors.length, 0);
class MyElement extends HTMLElement {
constructor() {
super();
constructors.push(this);
}
}
customElements.define('a-a', MyElement);
// createElement should synchronously call constructor.
let a = document.createElement('a-a');
assert_equals(constructors.length, 1);
assert_equals(a.ownerDocument, document);
let importDoc = document.currentScript.ownerDocument;
// TODO(kochi): crbug.com/640465 createElement returns wrong ownerDocument
// createElement should work in imported document.
let b = importDoc.createElement('a-a')
assert_equals(b.ownerDocument, importDoc);
assert_equals(constructors.length, 2);
// new MyElement() should synchronously call constructor.
let c = new MyElement();
assert_equals(c.ownerDocument, document);
assert_equals(constructors.length, 3);
assert_array_equals(constructors, [a, b, c]);
}, 'createElement() and new MyElement should work in imported document.');
</script>