diff --git a/src/__tests__/__snapshots__/role-helpers.js.snap b/src/__tests__/__snapshots__/role-helpers.js.snap index 4a8a1f2f..dd9aab91 100644 --- a/src/__tests__/__snapshots__/role-helpers.js.snap +++ b/src/__tests__/__snapshots__/role-helpers.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`logRoles calls console.log with output from prettyRoles 1`] = ` -region: +section: Name "a region":
+-------------------------------------------------- +img: + +Name "404": +404 + +Name "": + + +-------------------------------------------------- +presentation: + +Name "": + + -------------------------------------------------- link: @@ -52,32 +78,6 @@ Name "": data-testid="a-article" /> --------------------------------------------------- -command: - -Name "": - - -Name "": - - --------------------------------------------------- -menuitem: - -Name "": - - -Name "": - - -------------------------------------------------- list: diff --git a/src/__tests__/role-helpers.js b/src/__tests__/role-helpers.js index aadc1dc2..d3991008 100644 --- a/src/__tests__/role-helpers.js +++ b/src/__tests__/role-helpers.js @@ -18,6 +18,10 @@ function setup() { const {getByTestId} = render(`
Banner header
+ 404 + + + link invalid link @@ -77,6 +81,9 @@ function setup() { return { unnamedSection: getByTestId('a-section'), namedSection: getByTestId('named-section'), + imgAlt: getByTestId('img-alt'), + imgEmptyAlt: getByTestId('img-empty-alt'), + imgNoAlt: getByTestId('img-no-alt'), anchor: getByTestId('a-link'), h1: getByTestId('a-h1'), h2: getByTestId('a-h2'), @@ -142,6 +149,9 @@ test('getRoles returns expected roles for various dom nodes', () => { dd, dt, header, + imgAlt, + imgEmptyAlt, + imgNoAlt, } = setup() expect(getRoles(namedSection)).toEqual({ @@ -163,6 +173,8 @@ test('getRoles returns expected roles for various dom nodes', () => { region: [namedSection], term: [dt], definition: [dd], + img: [imgAlt, imgNoAlt], + presentation: [imgEmptyAlt], }) expect(getRoles(header)).toEqual({ banner: [header], @@ -177,9 +189,21 @@ test('logRoles calls console.log with output from prettyRoles', () => { }) test('getImplicitAriaRoles returns expected roles for various dom nodes', () => { - const {namedSection, h1, unnamedForm, radio, input} = setup() + const { + namedSection, + imgAlt, + imgEmptyAlt, + imgNoAlt, + h1, + unnamedForm, + radio, + input, + } = setup() expect(getImplicitAriaRoles(namedSection)).toEqual(['region']) + expect(getImplicitAriaRoles(imgAlt)).toEqual(['img']) + expect(getImplicitAriaRoles(imgEmptyAlt)).toEqual(['presentation']) + expect(getImplicitAriaRoles(imgNoAlt)).toEqual(['img']) expect(getImplicitAriaRoles(h1)).toEqual(['heading']) expect(getImplicitAriaRoles(unnamedForm)).toEqual([]) expect(getImplicitAriaRoles(radio)).toEqual(['radio']) diff --git a/src/role-helpers.js b/src/role-helpers.js index bc134f27..8368521f 100644 --- a/src/role-helpers.js +++ b/src/role-helpers.js @@ -84,7 +84,7 @@ function buildElementRoleList(elementRolesMap) { const shouldNotExist = constraints.indexOf('undefined') !== -1 if (shouldNotExist) { return `:not([${attributeName}])` - } else if (value) { + } else if (value || value === '') { return `[${attributeName}="${value}"]` } else { return `[${attributeName}]`