Skip to content

Commit

Permalink
fix(get-selector): don't throw error for disconnected fragment (#1802)
Browse files Browse the repository at this point in the history
* fix(get-selector): don't throw error for disconnected fragement

* skip phantom

* fix test
  • Loading branch information
straker committed Sep 10, 2019
1 parent 9586f3b commit bb6591b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/core/utils/get-selector.js
Expand Up @@ -392,6 +392,9 @@ axe.utils.getSelector = function createUniqueSelector(elm, options = {}) {
// DOCUMENT_FRAGMENT
let stack = [];
while (doc.nodeType === 11) {
if (!doc.host) {
return '';
}
stack.push({ elm: elm, doc: doc });
elm = doc.host;
doc = elm.getRootNode();
Expand Down
10 changes: 10 additions & 0 deletions test/core/utils/get-selector.js
Expand Up @@ -593,4 +593,14 @@ describe('axe.utils.getSelector', function() {
var test = document.querySelector(sel);
assert.isTrue(test === top);
});

it('should not error if fragment is no longer in the DOM', function() {
var fragment = document.createDocumentFragment();
var node = document.createElement('div');
fragment.appendChild(node);
fixtureSetup();
assert.doesNotThrow(function() {
axe.utils.getSelector(node);
});
});
});

0 comments on commit bb6591b

Please sign in to comment.