diff --git a/lib/commons/dom/shadow-elements-from-point.js b/lib/commons/dom/shadow-elements-from-point.js index 39a0f9535d..168fd0cc0b 100644 --- a/lib/commons/dom/shadow-elements-from-point.js +++ b/lib/commons/dom/shadow-elements-from-point.js @@ -14,7 +14,8 @@ dom.shadowElementsFromPoint = function(nodeX, nodeY, root = document, i = 0) { throw new Error('Infinite loop detected'); } return ( - Array.from(root.elementsFromPoint(nodeX, nodeY)) + // IE can return null when there are no elements + Array.from(root.elementsFromPoint(nodeX, nodeY) || []) // As of Chrome 66, elementFromPoint will return elements from parent trees. // We only want to touch each tree once, so we're filtering out nodes on other trees. .filter(nodes => dom.getRootNode(nodes) === root) diff --git a/test/commons/dom/shadow-elements-from-point.js b/test/commons/dom/shadow-elements-from-point.js index f11a9d860c..ac8af13cb6 100644 --- a/test/commons/dom/shadow-elements-from-point.js +++ b/test/commons/dom/shadow-elements-from-point.js @@ -43,4 +43,17 @@ describe('dom.shadowElementsFromPoint', function() { assert.notInclude(result2, shadowSpan); } ); + + it('does not throw when elementsFromPoints returns null', function() { + var mockDocument = { + elementsFromPoint: function() { + return null; + } + }; + var out; + assert.doesNotThrow(function() { + out = axe.commons.dom.shadowElementsFromPoint(10, 10, mockDocument); + }); + assert.deepEqual(out, []); + }); });