diff --git a/lib/checks/aria/aria-errormessage-evaluate.js b/lib/checks/aria/aria-errormessage-evaluate.js index 2ef53f35e2..9494988234 100644 --- a/lib/checks/aria/aria-errormessage-evaluate.js +++ b/lib/checks/aria/aria-errormessage-evaluate.js @@ -62,11 +62,13 @@ export default function ariaErrormessageEvaluate(node, options, virtualNode) { }); return false; } + const describedbyTokens = tokenList(virtualNode.attr('aria-describedby')); + const errormessageTokens = tokenList(attr); return ( getExplicitRole(idref) === 'alert' || idref.getAttribute('aria-live') === 'assertive' || idref.getAttribute('aria-live') === 'polite' || - tokenList(virtualNode.attr('aria-describedby')).indexOf(attr) > -1 + errormessageTokens.some(token => describedbyTokens.includes(token)) ); } diff --git a/test/checks/aria/errormessage.js b/test/checks/aria/errormessage.js index fd95256b21..f5465b2c2d 100644 --- a/test/checks/aria/errormessage.js +++ b/test/checks/aria/errormessage.js @@ -70,6 +70,46 @@ describe('aria-errormessage', function () { ); }); + it('should return true if aria-errormessage has multiple ids that are all in aria-describedby', function () { + var vNode = queryFixture( + '' + + '
Error 1
' + + '
Error 2
' + ); + assert.isTrue( + axe.testUtils + .getCheckEvaluate('aria-errormessage') + .call(checkContext, null, null, vNode) + ); + }); + + it('should return true if aria-errormessage has multiple ids but at least one is in aria-describedby', function () { + var vNode = queryFixture( + '' + + '
Error 1
' + + '
Error 2
' + ); + assert.isTrue( + axe.testUtils + .getCheckEvaluate('aria-errormessage') + .call(checkContext, null, null, vNode) + ); + }); + + it('should return false if aria-errormessage has multiple ids but none are in aria-describedby', function () { + var vNode = queryFixture( + '' + + '
Other
' + + '
Error 1
' + + '
Error 2
' + ); + assert.isFalse( + axe.testUtils + .getCheckEvaluate('aria-errormessage') + .call(checkContext, null, null, vNode) + ); + }); + it('sets an array of IDs in data', function () { var vNode = queryFixture( '
' +