Skip to content

Commit

Permalink
fix: Don't crash with slot elements without shadowDOM (#977)
Browse files Browse the repository at this point in the history
* fix: Don't crash with slot elements without shadowDOM

* test: Test flattenedTree with slot for non-shadowDOM
  • Loading branch information
WilcoFiers authored Jun 28, 2018
1 parent db3ed40 commit cc044af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/core/utils/flattened-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ axe.utils.getFlattenedTree = function (node, shadowId) {
if (nodeName === 'content') {
realArray = Array.from(node.getDistributedNodes());
return realArray.reduce(reduceShadowDOM, []);
} else if (nodeName === 'slot') {
} else if (nodeName === 'slot' && typeof node.assignedNodes === 'function') {
realArray = Array.from(node.assignedNodes());
if (!realArray.length) {
// fallback content
Expand Down
7 changes: 7 additions & 0 deletions test/core/utils/flattened-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ describe('axe.utils.getFlattenedTree', function() {
assert.equal(virtualDOM[0].actualNode, vNode.actualNode);
});
});
} else {
it('does not throw when slot elements are used', function () {
fixture.innerHTML = '<button><slot></slot></button>';
assert.doesNotThrow(function () {
axe.utils.getFlattenedTree(fixture);
});
});
}

if (shadowSupport.undefined) {
Expand Down

0 comments on commit cc044af

Please sign in to comment.