From 46a5d110a904ba7939343b94cd6ee2864f51c0aa Mon Sep 17 00:00:00 2001 From: Adam Cutler Date: Wed, 31 Jul 2019 16:24:01 -0400 Subject: [PATCH] fix(flatten-tree): do not call deprecated getDistributedNodes (#1729) --- lib/core/utils/flattened-tree.js | 5 ++++- test/core/utils/flattened-tree.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/core/utils/flattened-tree.js b/lib/core/utils/flattened-tree.js index 2e40c9d69b..0a2e8136f5 100644 --- a/lib/core/utils/flattened-tree.js +++ b/lib/core/utils/flattened-tree.js @@ -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); diff --git a/test/core/utils/flattened-tree.js b/test/core/utils/flattened-tree.js index 739347daa8..66ce30968b 100644 --- a/test/core/utils/flattened-tree.js +++ b/test/core/utils/flattened-tree.js @@ -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() {