Skip to content

Commit

Permalink
fix: help-same-as-label for shadow DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanb authored and marcysutton committed Jun 30, 2017
1 parent e64adbc commit dbbc544
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions build/templates.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
evaluate: 'function (node, options) {\n<%=source%>\n}',
evaluate: 'function (node, options, virtualNode) {\n<%=source%>\n}',
after: 'function (results, options) {\n<%=source%>\n}',
gather: 'function (context) {\n<%=source%>\n}',
matches: 'function (node) {\n<%=source%>\n}',
matches: 'function (node, virtualNode) {\n<%=source%>\n}',
source: '(function () {\n<%=source%>\n}())',
commons: '<%=source%>'
};
1 change: 1 addition & 0 deletions lib/checks/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"results": true,
"node": true,
"options": true,
"virtualNode": true,
"axe": true,
"document": true,
"window": true
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/label/help-same-as-label.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var labelText = axe.commons.text.label(node),
var labelText = axe.commons.text.label(virtualNode),
check = node.getAttribute('title');

if (!labelText) {
Expand Down
1 change: 1 addition & 0 deletions lib/commons/text/accessible-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function nonEmptyText(t) {
* @return {string}
*/
text.accessibleText = function(element, inLabelledByContext) {
//todo: implement shadowDOM
var accessibleNameComputation;
var encounteredNodes = [];

Expand Down
14 changes: 9 additions & 5 deletions test/checks/label/help-same-as-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('help-same-as-label', function () {

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

it('should return true if an element has a label and a title with the same text', function () {
Expand All @@ -14,8 +15,8 @@ describe('help-same-as-label', function () {
node.setAttribute('aria-label', 'Duplicate');

fixture.appendChild(node);

assert.isTrue(checks['help-same-as-label'].evaluate(node));
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
assert.isTrue(checks['help-same-as-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node)));
});

it('should return true if an element has a label and aria-describedby with the same text', function () {
Expand All @@ -30,7 +31,8 @@ describe('help-same-as-label', function () {
fixture.appendChild(node);
fixture.appendChild(dby);

assert.isTrue(checks['help-same-as-label'].evaluate(node));
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
assert.isTrue(checks['help-same-as-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node)));
});


Expand All @@ -41,7 +43,8 @@ describe('help-same-as-label', function () {

fixture.appendChild(node);

assert.isFalse(checks['help-same-as-label'].evaluate(node));
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
assert.isFalse(checks['help-same-as-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node)));

});

Expand All @@ -56,7 +59,8 @@ describe('help-same-as-label', function () {
fixture.appendChild(node);
fixture.appendChild(dby);

assert.isFalse(checks['help-same-as-label'].evaluate(node));
var tree = axe._tree = axe.utils.getFlattenedTree(fixture);
assert.isFalse(checks['help-same-as-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node)));
});

});

0 comments on commit dbbc544

Please sign in to comment.