Skip to content

Commit

Permalink
DOM: test listener invocation order
Browse files Browse the repository at this point in the history
  • Loading branch information
annevk committed Mar 1, 2019
1 parent efbd80b commit d772ebe
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions dom/events/Event-dispatch-listener-order.window.js
@@ -0,0 +1,20 @@
test(t => {
const hostParent = document.createElement("section"),
host = hostParent.appendChild(document.createElement("div")),
shadowRoot = host.attachShadow({ mode: "closed" }),
targetParent = shadowRoot.appendChild(document.createElement("p")),
target = targetParent.appendChild(document.createElement("span")),
path = [hostParent, host, shadowRoot, targetParent, target],
expected = [],
result = [];
path.forEach((node, index) => {
expected.splice(index, 0, "capturing " + node.nodeName);
expected.splice(index + 1, 0, "bubbling " + node.nodeName);
});
path.forEach(node => {
node.addEventListener("test", () => { result.push("bubbling " + node.nodeName) });
node.addEventListener("test", () => { result.push("capturing " + node.nodeName) }, true);
});
target.dispatchEvent(new CustomEvent('test', { detail: {}, bubbles: true, composed: true }));
assert_array_equals(result, expected);
});

0 comments on commit d772ebe

Please sign in to comment.