Skip to content

Commit

Permalink
fix(image-redundant-alt): check for parent before calculating text (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
straker committed Jul 18, 2019
1 parent cc5bd59 commit 1adbd02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/checks/label/duplicate-img-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const parent = dom.findUpVirtual(
virtualNode,
'button, [role="button"], a[href], p, li, td, th'
);

if (!parent) {
return false;
}

const parentVNode = axe.utils.getNodeFromTree(parent);
const visibleText = text.visibleVirtual(parentVNode, true).toLowerCase();
if (visibleText === '') {
Expand Down
14 changes: 14 additions & 0 deletions test/checks/label/duplicate-img-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ describe('duplicate-img-label', function() {
);
});

it('should return false if img does not have required parent', function() {
fixture.innerHTML =
'<main><img id="target" alt="Plain text and more"><p>Plain text</p></main>';
var node = fixture.querySelector('#target');
axe.testUtils.flatTreeSetup(fixture);
assert.isFalse(
checks['duplicate-img-label'].evaluate(
node,
undefined,
axe.utils.getNodeFromTree(node)
)
);
});

(shadowSupport.v1 ? it : xit)(
'should return true if the img is part of a shadow tree',
function() {
Expand Down

0 comments on commit 1adbd02

Please sign in to comment.