From a979579d1a490e4afd7fc93931b61d18c50d535e Mon Sep 17 00:00:00 2001 From: AdnoC Date: Mon, 29 Jul 2019 13:30:01 -0400 Subject: [PATCH 1/2] fix(flatten-tree): do not call deprecated getDistributedNodes --- lib/core/utils/flattened-tree.js | 5 ++++- 1 file changed, 4 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); From 4e0f357de9e6ac57bbd61935001786c57dd7cd28 Mon Sep 17 00:00:00 2001 From: AdnoC Date: Tue, 30 Jul 2019 11:38:45 -0400 Subject: [PATCH 2/2] add test --- test/core/utils/flattened-tree.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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() {