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 = '
    1. My list item
    '; - var target = fixture.querySelector('#target'); - assert.isTrue(checks.listitem.evaluate.call(checkContext, target)); + var params = checkSetup('
    1. My list item
    '); + var result = checkEvaluate.apply(checkContext, params) + assert.isTrue(result); }); it('should pass if the listitem has a parent