Skip to content

Commit

Permalink
feat(utils.getFlattenTree): default to documentElement (#2260)
Browse files Browse the repository at this point in the history
  • Loading branch information
straker authored Jun 5, 2020
1 parent c39ba9f commit 8b14ccc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/core/utils/get-flattened-tree.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import isShadowRoot from './is-shadow-root';
import VirtualNode from '../base/virtual-node/virtual-node';
import cache from '../base/cache';

/**
* This implemnts the flatten-tree algorithm specified:
Expand Down Expand Up @@ -134,13 +135,12 @@ function flattenTree(node, shadowId, parent) {
* Recursvely returns an array of the virtual DOM nodes at this level
* excluding comment nodes and the shadow DOM nodes <content> and <slot>
*
* @param {Node} node the current node
* @param {String} shadowId, optional ID of the shadow DOM that is the closest shadow
* @param {Node} [node=document.documentElement] optional node. NOTE: passing in anything other than body or the documentElement may result in incomplete results.
* @param {String} [shadowId] optional ID of the shadow DOM that is the closest shadow
* ancestor of the node
*/
function getFlattenedTree(node, shadowId) {
// TODO: es-modules_cache
axe._cache.set('nodeMap', new WeakMap());
function getFlattenedTree(node = document.documentElement, shadowId) {
cache.set('nodeMap', new WeakMap());
return flattenTree(node, shadowId);
}

Expand Down
6 changes: 6 additions & 0 deletions test/core/utils/flattened-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ describe('axe.utils.getFlattenedTree', function() {
);
}

it('should default to document', function() {
fixture.innerHTML = '';
var tree = axe.utils.getFlattenedTree();
assert(tree[0].actualNode === document.documentElement);
});

if (shadowSupport.v0) {
describe('shadow DOM v0', function() {
afterEach(function() {
Expand Down

0 comments on commit 8b14ccc

Please sign in to comment.