diff --git a/lib/checks/aria/unsupportedrole-evaluate.js b/lib/checks/aria/unsupportedrole-evaluate.js index 947d8f5c8b..ee7ff3d71e 100644 --- a/lib/checks/aria/unsupportedrole-evaluate.js +++ b/lib/checks/aria/unsupportedrole-evaluate.js @@ -9,7 +9,13 @@ import { isUnsupportedRole, getRole } from '../../commons/aria'; * @return {Boolean} True if the elements semantic role is unsupported. False otherwise. */ function unsupportedroleEvaluate(node, options, virtualNode) { - return isUnsupportedRole(getRole(virtualNode)); + const role = getRole(virtualNode, { dpub: true, fallback: true }); + const isUnsupported = isUnsupportedRole(role); + if (isUnsupported) { + this.data(role); + } + return isUnsupported; + } export default unsupportedroleEvaluate; diff --git a/lib/checks/aria/unsupportedrole.json b/lib/checks/aria/unsupportedrole.json index a75e9da0d9..685ec6e2e4 100644 --- a/lib/checks/aria/unsupportedrole.json +++ b/lib/checks/aria/unsupportedrole.json @@ -5,7 +5,7 @@ "impact": "critical", "messages": { "pass": "ARIA role is supported", - "fail": "The role used is not widely supported in screen readers and assistive technologies: ${data.values}" + "fail": "The role used is not widely supported in screen readers and assistive technologies: ${data}" } } } diff --git a/test/checks/aria/unsupportedrole.js b/test/checks/aria/unsupportedrole.js index 2fcf4613b3..cf7e8e6c81 100644 --- a/test/checks/aria/unsupportedrole.js +++ b/test/checks/aria/unsupportedrole.js @@ -1,7 +1,13 @@ describe('unsupportedrole', function() { 'use strict'; - var queryFixture = axe.testUtils.queryFixture; + var checkContext = axe.testUtils.MockCheckContext(); + var checkSetup = axe.testUtils.checkSetup; + var check = checks.unsupportedrole; + afterEach(function() { + checkContext.reset(); + axe.reset(); + }); it('should return true if applied to an unsupported role', function() { axe.configure({ @@ -15,22 +21,65 @@ describe('unsupportedrole', function() { } }); - var vNode = queryFixture( + var params = checkSetup( '
Contents
' ); - assert.isTrue(checks.unsupportedrole.evaluate(null, null, vNode)); + assert.isTrue(check.evaluate.apply(checkContext, params)); + assert.deepEqual(checkContext._data, "mccheddarton"); }); it('should return false if applied to a supported role', function() { - var vNode = queryFixture(''); - assert.isFalse(checks.unsupportedrole.evaluate(null, null, vNode)); + var params = checkSetup(''); + assert.isFalse(check.evaluate.apply(checkContext, params)); + assert.isNull(checkContext._data); - var vNode = queryFixture(''); - assert.isFalse(checks.unsupportedrole.evaluate(null, null, vNode)); + var params = checkSetup(''); + assert.isFalse(check.evaluate.apply(checkContext, params)); + assert.isNull(checkContext._data); }); it('should return false if applied to an invalid role', function() { - var vNode = queryFixture(''); - assert.isFalse(checks.unsupportedrole.evaluate(null, null, vNode)); + var params = checkSetup(''); + assert.isFalse(check.evaluate.apply(checkContext, params)); + assert.isNull(checkContext._data); + }); + + it('should return true if applied to an unsupported dpub role', function() { + axe.configure({ + standards: { + ariaRoles: { + 'doc-abstract': { + type: 'section', + unsupported: true + } + } + } + }); + + var params = checkSetup( + '
Contents
' + ); + assert.isTrue(check.evaluate.apply(checkContext, params)); + assert.deepEqual(checkContext._data, "doc-abstract"); }); + + it('should return true if applied to an unsupported fallback role', function() { + axe.configure({ + standards: { + ariaRoles: { + alert: { + type: 'widget', + unsupported: true + } + } + } + }); + + var params = checkSetup( + '
Contents
' + ); + assert.isTrue(check.evaluate.apply(checkContext, params)); + assert.deepEqual(checkContext._data, "alert"); + }); + });