Skip to content

Commit

Permalink
chore(non-empty-alt): use virtualNode instead of node (#1925)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers authored and straker committed Dec 11, 2019
1 parent a2f0247 commit 0b7522c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/checks/shared/non-empty-alt.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var label = node.getAttribute('alt');
const label = virtualNode.attr('alt');
return !!(label ? axe.commons.text.sanitize(label).trim() : '');
28 changes: 9 additions & 19 deletions test/checks/shared/non-empty-alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,29 @@ describe('non-empty-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);

assert.isTrue(checks['non-empty-alt'].evaluate(node));
var params = checkSetup('<img id="target" alt="woohoo" />');
assert.isTrue(checks['non-empty-alt'].evaluate.apply(null, params));
});

it('should return false if an alt is not present', function() {
var node = document.createElement('img');
fixture.appendChild(node);

assert.isFalse(checks['non-empty-alt'].evaluate(node));
var params = checkSetup('<img id="target" />');
assert.isFalse(checks['non-empty-alt'].evaluate.apply(null, params));
});

it('should return false if an alt is present, but empty', function() {
var node = document.createElement('img');
node.setAttribute('alt', ' ');
fixture.appendChild(node);

assert.isFalse(checks['non-empty-alt'].evaluate(node));
var params = checkSetup('<img id="target" alt=" " />');
assert.isFalse(checks['non-empty-alt'].evaluate.apply(null, params));
});

it('should collapse whitespace', function() {
var node = document.createElement('div');
node.setAttribute('alt', ' \t \n \r \t \t\r\n ');
fixture.appendChild(node);

assert.isFalse(checks['non-empty-alt'].evaluate(node));
var params = checkSetup('<img id="target" alt=" \t \n \r \t \t\r\n " />');
assert.isFalse(checks['non-empty-alt'].evaluate.apply(null, params));
});
});

0 comments on commit 0b7522c

Please sign in to comment.