Skip to content

Commit

Permalink
fix: Solve a few tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	test/testutils.js
  • Loading branch information
WilcoFiers committed Jul 18, 2017
1 parent 0252218 commit 02daad1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
3 changes: 2 additions & 1 deletion lib/checks/label/explicit.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
22 changes: 9 additions & 13 deletions test/checks/shared/button-has-visible-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -16,32 +16,28 @@ describe('button-has-visible-text', function () {
});

it('should return false if button element is empty', function () {
fixture.innerHTML = '<button></button>';
var checkArgs = checkSetup('<button></button>', '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 = '<button>Name</button>';
var checkArgs = checkSetup('<button>Name</button>', '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 = '<div role="button">Text</div>';
var checkArgs = checkSetup('<div role="button">Text</div>>', '[role=button]');

var node = fixture.querySelector('div');
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, 'Text');
});

it('should return false if ARIA button has no text', function () {
fixture.innerHTML = '<div role="button"></div>';
var checkArgs = checkSetup('<div role="button"></div>>', '[role=button]');

var node = fixture.querySelector('div');
assert.isFalse(checks['button-has-visible-text'].evaluate.call(checkContext, node));
assert.isFalse(checks['button-has-visible-text'].evaluate.apply(checkContext, checkArgs));
});
});

0 comments on commit 02daad1

Please sign in to comment.