diff --git a/lib/checks/aria/unsupportedrole.js b/lib/checks/aria/unsupportedrole.js
index 04a5e364b1..278a719ba7 100644
--- a/lib/checks/aria/unsupportedrole.js
+++ b/lib/checks/aria/unsupportedrole.js
@@ -1,3 +1 @@
-return !axe.commons.aria.isValidRole(node.getAttribute('role'), {
- flagUnsupported: true
-});
+return axe.commons.aria.isUnsupportedRole(axe.commons.aria.getRole(node));
diff --git a/lib/commons/aria/is-unsupported-role.js b/lib/commons/aria/is-unsupported-role.js
new file mode 100644
index 0000000000..50bf8fa69f
--- /dev/null
+++ b/lib/commons/aria/is-unsupported-role.js
@@ -0,0 +1,14 @@
+/* global aria, axe */
+
+/**
+ * Check if a given role is unsupported
+ * @method isUnsupportedRole
+ * @memberof axe.commons.aria
+ * @instance
+ * @param {String} role The role to check
+ * @return {Boolean}
+ */
+aria.isUnsupportedRole = function(role) {
+ const roleDefinition = aria.lookupTable.role[role];
+ return roleDefinition ? roleDefinition.unsupported : false;
+};
diff --git a/test/checks/aria/unsupportedrole.js b/test/checks/aria/unsupportedrole.js
index 2a645d5120..272ecd5efc 100644
--- a/test/checks/aria/unsupportedrole.js
+++ b/test/checks/aria/unsupportedrole.js
@@ -8,7 +8,7 @@ describe('unsupportedrole', function() {
});
it('should return true if applied to an unsupported role', function() {
- axe.commons.aria.lookupTable.role.mcheddarton = {
+ axe.commons.aria.lookupTable.role.mccheddarton = {
type: 'widget',
unsupported: true
};
@@ -21,5 +21,15 @@ describe('unsupportedrole', function() {
fixture.innerHTML = '
Contents
';
var node = fixture.querySelector('#target');
assert.isFalse(checks.unsupportedrole.evaluate(node));
+
+ fixture.innerHTML = '';
+ var node = fixture.querySelector('#target');
+ assert.isFalse(checks.unsupportedrole.evaluate(node));
+ });
+
+ it('should return false if applied to an invalid role', function() {
+ fixture.innerHTML = '';
+ var node = fixture.querySelector('#target');
+ assert.isFalse(checks.unsupportedrole.evaluate(node));
});
});
diff --git a/test/commons/aria/is-unsupported-role.js b/test/commons/aria/is-unsupported-role.js
new file mode 100644
index 0000000000..a44ab18307
--- /dev/null
+++ b/test/commons/aria/is-unsupported-role.js
@@ -0,0 +1,32 @@
+describe('aria.isUnsupportedRole', function() {
+ 'use strict';
+
+ it('should return true if the role is unsupported', function() {
+ var orig = axe.commons.aria.lookupTable.role;
+ axe.commons.aria.lookupTable.role = {
+ cats: {
+ unsupported: true
+ }
+ };
+ assert.isTrue(axe.commons.aria.isUnsupportedRole('cats'));
+ axe.commons.aria.lookupTable.role = orig;
+ });
+
+ it('should return false if the role is supported', function() {
+ var orig = axe.commons.aria.lookupTable.role;
+ axe.commons.aria.lookupTable.role = {
+ cats: {
+ unsupported: false
+ }
+ };
+ assert.isFalse(axe.commons.aria.isUnsupportedRole('cats'));
+ axe.commons.aria.lookupTable.role = orig;
+ });
+
+ it('should return false if the role is invalid', function() {
+ var orig = axe.commons.aria.lookupTable.role;
+ axe.commons.aria.lookupTable.role = {};
+ assert.isFalse(axe.commons.aria.isUnsupportedRole('cats'));
+ axe.commons.aria.lookupTable.role = orig;
+ });
+});