Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(utils.getFlattenTree): default to documentElement #2260

Merged
merged 1 commit into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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