Skip to content

Commit

Permalink
fix(rule/dlitem): use a case-insenstive tagName test (#652)
Browse files Browse the repository at this point in the history
In XHTML, `element.tagName` preserves the case.

In the `dlitem` check, the tag name is now upper-cased before
being tested as 'DL', to make the rule work on XHTML documents.

Fixes #581
  • Loading branch information
rdeltour authored and WilcoFiers committed Dec 15, 2017
1 parent 08af138 commit e67a913
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checks/lists/dlitem.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
return node.parentNode.tagName === 'DL';
return node.parentNode.tagName.toUpperCase() === 'DL';

52 changes: 52 additions & 0 deletions test/integration/full/definition-list/dlitem-xhtml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

describe('dlitem XHTML test', function () {
'use strict';

var results;

before(function (done) {
axe.run({ runOnly: { type: 'rule', values: ['dlitem'] } }, function (err, r) {
assert.isNull(err);
results = r;
done();
});
});

describe('violations', function() {

it('should find 2', function () {
assert.lengthOf(results.violations, 1);
assert.lengthOf(results.violations[0].nodes, 2);
});

it('should find #uncontained and #also', function () {
assert.equal(results.violations[0].nodes[0].any[0].id, 'dlitem');
assert.deepEqual(results.violations[0].nodes[0].target, ['#uncontained']);
});

it('should find #alsouncontained', function () {
assert.equal(results.violations[0].nodes[1].any[0].id, 'dlitem');
assert.deepEqual(results.violations[0].nodes[1].target, ['#alsouncontained']);
});

});

describe('passes', function() {

it('should find 2', function () {
assert.lengthOf(results.passes, 1);
assert.lengthOf(results.passes[0].nodes, 2);
});

it('should find #uncontained and #also', function () {
assert.equal(results.passes[0].nodes[0].any[0].id, 'dlitem');
assert.deepEqual(results.passes[0].nodes[0].target, ['#contained']);
});

it('should find #alsouncontained', function () {
assert.equal(results.passes[0].nodes[1].any[0].id, 'dlitem');
assert.deepEqual(results.passes[0].nodes[1].target, ['#alsocontained']);
});

});
});
30 changes: 30 additions & 0 deletions test/integration/full/definition-list/dlitem-xhtml.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>axe.utils.getSelector test</title>
<meta charset="utf-8"/>
<link rel="stylesheet" type="text/css" href="/node_modules/mocha/mocha.css" />
<script src="/node_modules/mocha/mocha.js"></script>
<script src="/node_modules/chai/chai.js"></script>
<script src="/axe.js"></script>
<script>
mocha.setup({
timeout: 10000,
ui: 'bdd'
});
var assert = chai.assert;
</script>
</head>
<body>
<div id="fixture">
<dd id="uncontained">Should belong to a list.</dd>
<dt id="alsouncontained">Should belong to a list.</dt>
<dl>
<dt id="contained">Does belong to a list.</dt>
<dd id="alsocontained">Also belongs to a list.</dd>
</dl>
</div>
<div id="mocha"></div>
<script src="dlitem-xhtml.js"></script>
<script src="/test/integration/adapter.js"></script>
</body>
</html>

0 comments on commit e67a913

Please sign in to comment.