From 5fb06e3a4e0e1e1506e6aa4b0857910e45624f4c Mon Sep 17 00:00:00 2001 From: Marcy Sutton Date: Fri, 30 Jun 2017 12:37:30 -0700 Subject: [PATCH] fix: use virtualNode in title-only check Closes https://github.com/dequelabs/axe-core/issues/388 --- lib/checks/label/title-only.js | 2 +- test/checks/label/title-only.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/checks/label/title-only.js b/lib/checks/label/title-only.js index 64251d46fd..8d92a917d0 100644 --- a/lib/checks/label/title-only.js +++ b/lib/checks/label/title-only.js @@ -1,2 +1,2 @@ -var labelText = axe.commons.text.label(node); +var labelText = axe.commons.text.label(virtualNode); return !labelText && !!(node.getAttribute('title') || node.getAttribute('aria-describedby')); \ No newline at end of file diff --git a/test/checks/label/title-only.js b/test/checks/label/title-only.js index 7918883d4f..c934be7d15 100644 --- a/test/checks/label/title-only.js +++ b/test/checks/label/title-only.js @@ -5,6 +5,7 @@ describe('title-only', function () { afterEach(function () { fixture.innerHTML = ''; + axe._tree = undefined; }); it('should return true if an element only has a title', function () { @@ -14,9 +15,11 @@ describe('title-only', function () { fixture.appendChild(node); - assert.isTrue(checks['title-only'].evaluate(node)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + + assert.isTrue(checks['title-only'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node))); node.setAttribute('aria-label', 'woop'); - assert.isFalse(checks['title-only'].evaluate(node)); + assert.isFalse(checks['title-only'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node))); }); it('should return true if an element only has aria-describedby', function () { @@ -30,9 +33,11 @@ describe('title-only', function () { fixture.appendChild(node); fixture.appendChild(dby); - assert.isTrue(checks['title-only'].evaluate(node)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + + assert.isTrue(checks['title-only'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node))); node.setAttribute('aria-label', 'woop'); - assert.isFalse(checks['title-only'].evaluate(node)); + assert.isFalse(checks['title-only'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node))); }); }); \ No newline at end of file