diff --git a/lib/checks/lists/listitem-evaluate.js b/lib/checks/lists/listitem-evaluate.js
index 0fa6382506..b09c5414bb 100644
--- a/lib/checks/lists/listitem-evaluate.js
+++ b/lib/checks/lists/listitem-evaluate.js
@@ -1,15 +1,14 @@
-import { getComposedParent } from '../../commons/dom';
-import { isValidRole } from '../../commons/aria';
+import { isValidRole, getExplicitRole } from '../../commons/aria';
-function listitemEvaluate(node) {
- const parent = getComposedParent(node);
+export default function listitemEvaluate(node, options, virtualNode) {
+ const { parent } = virtualNode;
if (!parent) {
// Can only happen with detached DOM nodes and roots:
return undefined;
}
- const parentTagName = parent.nodeName.toUpperCase();
- const parentRole = (parent.getAttribute('role') || '').toLowerCase();
+ const parentNodeName = parent.props.nodeName;
+ const parentRole = getExplicitRole(parent);
if (['presentation', 'none', 'list'].includes(parentRole)) {
return true;
@@ -21,8 +20,5 @@ function listitemEvaluate(node) {
});
return false;
}
-
- return ['UL', 'OL'].includes(parentTagName);
+ return ['ul', 'ol', 'menu'].includes(parentNodeName);
}
-
-export default listitemEvaluate;
diff --git a/test/checks/lists/listitem.js b/test/checks/lists/listitem.js
index 8d69f1fc2c..b9045e3937 100644
--- a/test/checks/lists/listitem.js
+++ b/test/checks/lists/listitem.js
@@ -1,74 +1,81 @@
describe('listitem', function() {
'use strict';
- var fixture = document.getElementById('fixture');
var shadowSupport = axe.testUtils.shadowSupport;
var checkContext = axe.testUtils.MockCheckContext();
+ var checkSetup = axe.testUtils.checkSetup;
+ var fixtureSetup = axe.testUtils.fixtureSetup;
+ var checkEvaluate = axe.testUtils.getCheckEvaluate('listitem');
afterEach(function() {
- fixture.innerHTML = '';
checkContext.reset();
});
it('should pass if the listitem has a parent
', function() {
- fixture.innerHTML = '- My list item
';
- var target = fixture.querySelector('#target');
- assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
+ var params = checkSetup('- My list item
');
+ var result = checkEvaluate.apply(checkContext, params)
+ assert.isTrue(result);
});
it('should pass if the listitem has a parent ', function() {
- fixture.innerHTML = '';
- var target = fixture.querySelector('#target');
- assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
+ var params = checkSetup('');
+ var result = checkEvaluate.apply(checkContext, params)
+ assert.isTrue(result);
});
it('should pass if the listitem has a parent role=list', function() {
- fixture.innerHTML =
- '- My list item
';
- var target = fixture.querySelector('#target');
- assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
+ var params = checkSetup(
+ '- My list item
'
+ );
+ var result = checkEvaluate.apply(checkContext, params)
+ assert.isTrue(result);
});
it('should pass if the listitem has a parent role=none', function() {
- fixture.innerHTML =
- '';
- var target = fixture.querySelector('#target');
- assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
+ var params = checkSetup(
+ ''
+ );
+ var result = checkEvaluate.apply(checkContext, params)
+ assert.isTrue(result);
});
it('should pass if the listitem has a parent role=presentation', function() {
- fixture.innerHTML =
- '';
- var target = fixture.querySelector('#target');
- assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
+ var params = checkSetup(
+ ''
+ );
+ var result = checkEvaluate.apply(checkContext, params)
+ assert.isTrue(result);
});
it('should fail if the listitem has an incorrect parent', function() {
- fixture.innerHTML = '- My list item
';
- var target = fixture.querySelector('#target');
- assert.isFalse(checks.listitem.evaluate.call(checkContext, target));
+ var params = checkSetup('- My list item
');
+ var result = checkEvaluate.apply(checkContext, params)
+ assert.isFalse(result);
});
it('should fail if the listitem has a parent with changed role', function() {
- fixture.innerHTML =
- '- My list item
';
- var target = fixture.querySelector('#target');
- assert.isFalse(checks.listitem.evaluate.call(checkContext, target));
+ var params = checkSetup(
+ '- My list item
'
+ );
+ var result = checkEvaluate.apply(checkContext, params)
+ assert.isFalse(result);
assert.equal(checkContext._data.messageKey, 'roleNotValid');
});
it('should pass if the listitem has a parent with an invalid role', function() {
- fixture.innerHTML =
- '- My list item
';
- var target = fixture.querySelector('#target');
- assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
+ var params = checkSetup(
+ '- My list item
'
+ );
+ var result = checkEvaluate.apply(checkContext, params)
+ assert.isTrue(result);
});
it('should pass if the listitem has a parent with an abstract role', function() {
- fixture.innerHTML =
- '- My list item
';
- var target = fixture.querySelector('#target');
- assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
+ var params = checkSetup(
+ '- My list item
'
+ );
+ var result = checkEvaluate.apply(checkContext, params)
+ assert.isTrue(result);
});
(shadowSupport.v1 ? it : xit)(
@@ -78,9 +85,11 @@ describe('listitem', function() {
node.innerHTML = '- My list item
';
var shadow = node.attachShadow({ mode: 'open' });
shadow.innerHTML = '';
- fixture.appendChild(node);
+ fixtureSetup(node);
var target = node.querySelector('#target');
- assert.isTrue(checks.listitem.evaluate.call(checkContext, target));
+ var virtualTarget = axe.utils.getNodeFromTree(target);
+ var result = checkEvaluate.apply(checkContext, [target, {}, virtualTarget])
+ assert.isTrue(result);
}
);
@@ -91,9 +100,11 @@ describe('listitem', function() {
node.innerHTML = '- My list item
';
var shadow = node.attachShadow({ mode: 'open' });
shadow.innerHTML = '
';
- fixture.appendChild(node);
+ fixtureSetup(node);
var target = node.querySelector('#target');
- assert.isFalse(checks.listitem.evaluate.call(checkContext, target));
+ var virtualTarget = axe.utils.getNodeFromTree(target);
+ var result = checkEvaluate.apply(checkContext, [target, {}, virtualTarget])
+ assert.isFalse(result);
}
);
});
diff --git a/test/integration/rules/listitem/listitem.html b/test/integration/rules/listitem/listitem.html
index 71fbfb6d55..77fea1a212 100644
--- a/test/integration/rules/listitem/listitem.html
+++ b/test/integration/rules/listitem/listitem.html
@@ -19,3 +19,7 @@
- I too do not belong to a list.
+
+
diff --git a/test/integration/rules/listitem/listitem.json b/test/integration/rules/listitem/listitem.json
index 462226fdd1..3d9bd49139 100644
--- a/test/integration/rules/listitem/listitem.json
+++ b/test/integration/rules/listitem/listitem.json
@@ -2,5 +2,5 @@
"description": "listitem test",
"rule": "listitem",
"violations": [["#uncontained"], ["#ulrolechanged"], ["#olrolechanged"]],
- "passes": [["#contained"], ["#alsocontained"], ["#presentation"], ["#none"]]
+ "passes": [["#contained"], ["#alsocontained"], ["#presentation"], ["#none"], ["#menuitem"]]
}