diff --git a/lib/checks/label/explicit.js b/lib/checks/label/explicit.js index bff93e1482..eee064f700 100644 --- a/lib/checks/label/explicit.js +++ b/lib/checks/label/explicit.js @@ -1,6 +1,7 @@ if (node.getAttribute('id')) { + const root = axe.commons.dom.getRootNode(node); const id = axe.commons.utils.escapeSelector(node.getAttribute('id')); - const label = document.querySelector(`label[for="${id}"]`); + const label = root.querySelector(`label[for="${id}"]`); if (label) { return !!axe.commons.text.accessibleText(label); diff --git a/test/checks/shared/button-has-visible-text.js b/test/checks/shared/button-has-visible-text.js index fb3d0fa565..3526aea46b 100644 --- a/test/checks/shared/button-has-visible-text.js +++ b/test/checks/shared/button-has-visible-text.js @@ -2,7 +2,7 @@ describe('button-has-visible-text', function () { 'use strict'; var fixture = document.getElementById('fixture'); - + var checkSetup = axe.testUtils.checkSetup; var checkContext = { _data: null, data: function (d) { @@ -16,32 +16,28 @@ describe('button-has-visible-text', function () { }); it('should return false if button element is empty', function () { - fixture.innerHTML = ''; + var checkArgs = checkSetup('', 'button'); - var node = fixture.querySelector('button'); - assert.isFalse(checks['button-has-visible-text'].evaluate.call(checkContext, node)); + assert.isFalse(checks['button-has-visible-text'].evaluate.apply(checkContext, checkArgs)); }); it('should return true if a button element has text', function () { - fixture.innerHTML = ''; + var checkArgs = checkSetup('', 'button'); - var node = fixture.querySelector('button'); - assert.isTrue(checks['button-has-visible-text'].evaluate.call(checkContext, node)); + assert.isTrue(checks['button-has-visible-text'].evaluate.apply(checkContext, checkArgs)); assert.deepEqual(checkContext._data, 'Name'); }); it('should return true if ARIA button has text', function () { - fixture.innerHTML = '