UNPKG

@webcomponents/custom-elements

Version:
46 lines (35 loc) 1.21 kB
<!DOCTYPE html> <script src="../../resources/testharness.js"></script> <script src="../../resources/testharnessreport.js"></script> <script> 'use strict'; let reactions = []; let test = async_test('Constructor should run in the order elements are created'); test.step(() => { customElements.define('x-x', class extends HTMLElement { constructor() { super(); reactions.push(this); } }); assert_array_equals(reactions, [], 'Should not have parsed <x-x> yet'); }); </script> <x-x></x-x> <script> 'use strict'; test.step(() => { assert_equals(reactions.length, 1, 'Parser should invoke the custom element constructor'); }); let import1 = document.createElement('link'); import1.rel = 'import'; import1.href = 'resources/import-custom.html'; // TODO(kochi): crbug.com/640465 synchronous creation fails in imports. import1.onload = test.step_func_done(() => { let elementInMaster = document.querySelector('x-x'); let elementInImport = import1.import.querySelector('x-x'); assert_array_equals(reactions, [elementInMaster, elementInImport], 'Constructor should run in the order elements are created'); }); document.head.appendChild(import1); </script>