Skip to content

Commit bb6591b

Browse files
authored
fix(get-selector): don't throw error for disconnected fragment (#1802)
* fix(get-selector): don't throw error for disconnected fragement * skip phantom * fix test
1 parent 9586f3b commit bb6591b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/core/utils/get-selector.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ axe.utils.getSelector = function createUniqueSelector(elm, options = {}) {
392392
// DOCUMENT_FRAGMENT
393393
let stack = [];
394394
while (doc.nodeType === 11) {
395+
if (!doc.host) {
396+
return '';
397+
}
395398
stack.push({ elm: elm, doc: doc });
396399
elm = doc.host;
397400
doc = elm.getRootNode();

test/core/utils/get-selector.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,4 +593,14 @@ describe('axe.utils.getSelector', function() {
593593
var test = document.querySelector(sel);
594594
assert.isTrue(test === top);
595595
});
596+
597+
it('should not error if fragment is no longer in the DOM', function() {
598+
var fragment = document.createDocumentFragment();
599+
var node = document.createElement('div');
600+
fragment.appendChild(node);
601+
fixtureSetup();
602+
assert.doesNotThrow(function() {
603+
axe.utils.getSelector(node);
604+
});
605+
});
596606
});

0 commit comments

Comments
 (0)