Skip to content

Commit

Permalink
fix(flatten-tree): do not call deprecated getDistributedNodes (#1729)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdnoC authored Jul 31, 2019
1 parent ecc99f2 commit 46a5d11
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/core/utils/flattened-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ function flattenTree(node, shadowId, parent) {

return [retVal];
} else {
if (nodeName === 'content') {
if (
nodeName === 'content' &&
typeof node.getDistributedNodes === 'function'
) {
realArray = Array.from(node.getDistributedNodes());
return realArray.reduce((res, child) => {
return reduceShadowDOM(res, child, parent);
Expand Down
15 changes: 15 additions & 0 deletions test/core/utils/flattened-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,21 @@ describe('axe.utils.getFlattenedTree', function() {
assert.isDefined(vNode);
assert.equal(virtualDOM[0].actualNode, vNode.actualNode);
});
it('should not throw if getDistributedNodes is missing', function() {
var getDistributedNodes = fixture.getDistributedNodes;
fixture.getDistributedNodes = undefined;
try {
var virtualDOM = axe.utils.getFlattenedTree(fixture);
var vNode = axe.utils.getNodeFromTree(
virtualDOM[0],
virtualDOM[0].actualNode
);
assert.isDefined(vNode);
assert.equal(virtualDOM[0].actualNode, vNode.actualNode);
} finally {
fixture.getDistributedNodes = getDistributedNodes;
}
});
});
} else {
it('does not throw when slot elements are used', function() {
Expand Down

0 comments on commit 46a5d11

Please sign in to comment.