diff --git a/lib/checks/lists/listitem.js b/lib/checks/lists/listitem.js
index a53deec328..d6fd712275 100644
--- a/lib/checks/lists/listitem.js
+++ b/lib/checks/lists/listitem.js
@@ -12,6 +12,7 @@ if (parentRole === 'list') {
}
if (parentRole && axe.commons.aria.isValidRole(parentRole)) {
+ this.data('roleNotValid');
return false;
}
diff --git a/lib/checks/lists/listitem.json b/lib/checks/lists/listitem.json
index 1f7057a0aa..b1cd6fcce4 100644
--- a/lib/checks/lists/listitem.json
+++ b/lib/checks/lists/listitem.json
@@ -5,7 +5,7 @@
"impact": "serious",
"messages": {
"pass": "List item has a
, or role=\"list\" parent element",
- "fail": "List item does not have a , or role=\"list\" parent element"
+ "fail": "List item does not have a , {{? it.data === 'roleNotValid'}} without a role, or a role=\"list\"{{?}} parent element"
}
}
}
diff --git a/test/checks/lists/listitem.js b/test/checks/lists/listitem.js
index 72c3e52f64..670748e707 100644
--- a/test/checks/lists/listitem.js
+++ b/test/checks/lists/listitem.js
@@ -2,65 +2,71 @@ describe('listitem', function() {
'use strict';
var fixture = document.getElementById('fixture');
- var checkSetup = axe.testUtils.checkSetup;
var shadowSupport = axe.testUtils.shadowSupport;
+ var checkContext = axe.testUtils.MockCheckContext();
afterEach(function() {
fixture.innerHTML = '';
+ checkContext.reset();
});
it('should pass if the listitem has a parent ', function() {
- var checkArgs = checkSetup('- My list item
');
- assert.isTrue(checks.listitem.evaluate.apply(null, checkArgs));
+ fixture.innerHTML = '- My list item
';
+ var target = fixture.querySelector('#target');
+ assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
});
it('should pass if the listitem has a parent ', function() {
- var checkArgs = checkSetup('');
- assert.isTrue(checks.listitem.evaluate.apply(null, checkArgs));
+ fixture.innerHTML = '';
+ var target = fixture.querySelector('#target');
+ assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
});
it('should pass if the listitem has a parent role=list', function() {
- var checkArgs = checkSetup(
- '- My list item
'
- );
- assert.isTrue(checks.listitem.evaluate.apply(null, checkArgs));
+ fixture.innerHTML =
+ '- My list item
';
+ var target = fixture.querySelector('#target');
+ assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
});
it('should fail if the listitem has an incorrect parent', function() {
- var checkArgs = checkSetup('- My list item
');
- assert.isFalse(checks.listitem.evaluate.apply(null, checkArgs));
+ fixture.innerHTML = '- My list item
';
+ var target = fixture.querySelector('#target');
+ assert.isFalse(checks.listitem.evaluate.call(checkContext, target));
});
it('should fail if the listitem has a parent with changed role', function() {
- var checkArgs = checkSetup(
- '- My list item
'
- );
- assert.isFalse(checks.listitem.evaluate.apply(null, checkArgs));
+ fixture.innerHTML =
+ '- My list item
';
+ var target = fixture.querySelector('#target');
+ assert.isFalse(checks.listitem.evaluate.call(checkContext, target));
+ assert.equal(checkContext._data, 'roleNotValid');
});
it('should pass if the listitem has a parent with an invalid role', function() {
- var checkArgs = checkSetup(
- '- My list item
'
- );
- assert.isTrue(checks.listitem.evaluate.apply(null, checkArgs));
+ fixture.innerHTML =
+ '- My list item
';
+ var target = fixture.querySelector('#target');
+ assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
});
it('should pass if the listitem has a parent with an abstract role', function() {
- var checkArgs = checkSetup(
- '- My list item
'
- );
- assert.isTrue(checks.listitem.evaluate.apply(null, checkArgs));
+ fixture.innerHTML =
+ '- My list item
';
+ var target = fixture.querySelector('#target');
+ assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
});
(shadowSupport.v1 ? it : xit)(
'should return true in a shadow DOM pass',
function() {
var node = document.createElement('div');
- node.innerHTML = '- My list item
';
+ node.innerHTML = '- My list item
';
var shadow = node.attachShadow({ mode: 'open' });
shadow.innerHTML = '';
- var checkArgs = checkSetup(node, 'li');
- assert.isTrue(checks.listitem.evaluate.apply(null, checkArgs));
+ fixture.appendChild(node);
+ var target = node.querySelector('#target');
+ assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
}
);
@@ -68,11 +74,12 @@ describe('listitem', function() {
'should return false in a shadow DOM fail',
function() {
var node = document.createElement('div');
- node.innerHTML = '- My list item
';
+ node.innerHTML = '- My list item
';
var shadow = node.attachShadow({ mode: 'open' });
shadow.innerHTML = '
';
- var checkArgs = checkSetup(node, 'li');
- assert.isFalse(checks.listitem.evaluate.apply(null, checkArgs));
+ fixture.appendChild(node);
+ var target = node.querySelector('#target');
+ assert.isFalse(checks.listitem.evaluate.call(checkContext, target));
}
);
});