Skip to content

Commit

Permalink
chore(has-alt): use virtualNode instead of node (dequelabs#1923)
Browse files Browse the repository at this point in the history
* chore(has-alt): use virtualNode instead of node

* chore(has-alt): ignore null alt
  • Loading branch information
WilcoFiers authored Dec 4, 2019
1 parent d4b2857 commit a9506a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
10 changes: 6 additions & 4 deletions lib/checks/shared/has-alt.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var nn = node.nodeName.toLowerCase();
return (
node.hasAttribute('alt') && (nn === 'img' || nn === 'input' || nn === 'area')
);
const { nodeName } = virtualNode.props;
if (!['img', 'input', 'area'].includes(nodeName)) {
return false;
}

return virtualNode.hasAttr('alt');
22 changes: 14 additions & 8 deletions test/checks/shared/has-alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@ describe('has-alt', function() {
'use strict';

var fixture = document.getElementById('fixture');
var checkSetup = axe.testUtils.checkSetup;

afterEach(function() {
fixture.innerHTML = '';
});

it('should return true if an alt is present', function() {
var node = document.createElement('img');
node.setAttribute('alt', 'woohoo');
fixture.appendChild(node);
var checkArgs = checkSetup('<img id="target" alt="woohoo" />');
assert.isTrue(checks['has-alt'].evaluate.apply(null, checkArgs));
});

assert.isTrue(checks['has-alt'].evaluate(node));
it('should return true if an empty alt is present', function() {
var checkArgs = checkSetup('<img id="target" alt="" />');
assert.isTrue(checks['has-alt'].evaluate.apply(null, checkArgs));
});

it('should return false if an alt is not present', function() {
var node = document.createElement('img');
fixture.appendChild(node);
it('should return true if a null alt is present', function() {
var checkArgs = checkSetup('<img id="target" alt />');
assert.isTrue(checks['has-alt'].evaluate.apply(null, checkArgs));
});

assert.isFalse(checks['has-alt'].evaluate(node));
it('should return false if an alt is not present', function() {
var checkArgs = checkSetup('<img id="target" />');
assert.isFalse(checks['has-alt'].evaluate.apply(null, checkArgs));
});
});

0 comments on commit a9506a0

Please sign in to comment.