diff --git a/src/__tests__/element-queries.js b/src/__tests__/element-queries.js
index 05aade0c..8a38fa11 100644
--- a/src/__tests__/element-queries.js
+++ b/src/__tests__/element-queries.js
@@ -533,14 +533,14 @@ test('queryAllByRole returns semantic html elements', () => {
expect(queryAllByRole(/listitem/i)).toHaveLength(3)
// TODO: with https://github.com/A11yance/aria-query/pull/42
// the actual value will match `toHaveLength(2)`
- expect(queryAllByRole(/textbox/i)).toHaveLength(1)
+ expect(queryAllByRole(/textbox/i)).toHaveLength(2)
expect(queryAllByRole(/checkbox/i)).toHaveLength(1)
expect(queryAllByRole(/radio/i)).toHaveLength(1)
expect(queryAllByRole('row')).toHaveLength(3)
expect(queryAllByRole(/rowgroup/i)).toHaveLength(2)
// TODO: with https://github.com/A11yance/aria-query/pull/42
// the actual value will match `toHaveLength(3)`
- expect(queryAllByRole(/(table)|(textbox)/i)).toHaveLength(2)
+ expect(queryAllByRole(/(table)|(textbox)/i)).toHaveLength(3)
expect(queryAllByRole(/img/i)).toHaveLength(1)
expect(queryAllByRole('meter')).toHaveLength(1)
expect(queryAllByRole('progressbar')).toHaveLength(0)
diff --git a/src/__tests__/suggestions.js b/src/__tests__/suggestions.js
index c65962b1..75c9ae56 100644
--- a/src/__tests__/suggestions.js
+++ b/src/__tests__/suggestions.js
@@ -74,7 +74,9 @@ test(`should not suggest if the suggestion would give different results`, () =>
})
test('should suggest by label over title', () => {
- renderIntoDocument(``)
+ renderIntoDocument(
+ ``,
+ )
expect(() => screen.getByTitle('foo')).toThrowError(
/getByLabelText\(\/bar\/i\)/,
@@ -181,7 +183,7 @@ test('escapes regular expressions in suggestion', () => {
test('should suggest getByLabelText when no role available', () => {
renderIntoDocument(
- ``,
+ ``,
)
expect(() => screen.getByTestId('foo')).toThrowError(
/getByLabelText\(\/username\/i\)/,
@@ -232,19 +234,21 @@ test.each([
test(`should suggest label over placeholder text`, () => {
renderIntoDocument(
- ``,
+ ``,
)
- expect(() => screen.getByPlaceholderText('Username')).toThrowError(
- /getByLabelText\(\/username\/i\)/,
+ expect(() => screen.getByPlaceholderText('Password')).toThrowError(
+ /getByLabelText\(\/password\/i\)/,
)
})
test(`should suggest getByPlaceholderText`, () => {
- renderIntoDocument(``)
+ renderIntoDocument(
+ ``,
+ )
expect(() => screen.getByTestId('foo')).toThrowError(
- /getByPlaceholderText\(\/username\/i\)/,
+ /getByPlaceholderText\(\/password\/i\)/,
)
})
@@ -257,25 +261,27 @@ test(`should suggest getByText for simple elements`, () => {
})
test(`should suggest getByDisplayValue`, () => {
- renderIntoDocument(``)
+ renderIntoDocument(
+ ``,
+ )
- document.getElementById('lastName').value = 'Prine' // RIP John Prine
+ document.getElementById('password').value = 'Prine' // RIP John Prine
- expect(() => screen.getByTestId('lastName')).toThrowError(
+ expect(() => screen.getByTestId('password')).toThrowError(
/getByDisplayValue\(\/prine\/i\)/,
)
})
test(`should suggest getByAltText`, () => {
renderIntoDocument(`
-
+
`)
expect(() => screen.getByTestId('input')).toThrowError(
- /getByAltText\(\/last name\/i\)/,
+ /getByAltText\(\/password\/i\)/,
)
expect(() => screen.getByTestId('area')).toThrowError(
/getByAltText\(\/computer\/i\)/,
diff --git a/src/role-helpers.js b/src/role-helpers.js
index f42e3e14..e991cadb 100644
--- a/src/role-helpers.js
+++ b/src/role-helpers.js
@@ -154,8 +154,9 @@ function getRoles(container, {hidden = false} = {}) {
function prettyRoles(dom, {hidden}) {
const roles = getRoles(dom, {hidden})
-
+ //We prefer to skip generic role, we don't reccomand it
return Object.entries(roles)
+ .filter(([role]) => role !== 'generic')
.map(([role, elements]) => {
const delimiterBar = '-'.repeat(50)
const elementsString = elements
diff --git a/src/suggestions.js b/src/suggestions.js
index 1a26a761..3e93fa5a 100644
--- a/src/suggestions.js
+++ b/src/suggestions.js
@@ -82,9 +82,10 @@ export function getSuggestedQuery(element, variant = 'get', method) {
return undefined
}
+ //We prefer to suggest something else if the role is generic
const role =
element.getAttribute('role') ?? getImplicitAriaRoles(element)?.[0]
- if (canSuggest('Role', method, role)) {
+ if (role !== 'generic' && canSuggest('Role', method, role)) {
return makeSuggestion('Role', role, {
variant,
name: computeAccessibleName(element),