You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
*ByRole queries with name option does not find elements based on text content in v14 #1923
test('getByRole query succeeds when accessibility label is queried in the name param for RN Button', async () => {
await render(<Button title="rn-button-title" accessibilityLabel="rn-button-accessibility-label"/>);
simpleScreen.getByRole('button', { name: 'rn-button-title'});
});
or
test('getByRole query fails when text content is queried in the name param', async () => {
await render(<TouchableOpacity accessibilityRole="button" accessibilityLabel="opacity-accessibility-label"><Text>opacity-text</Text></TouchableOpacity>);
simpleScreen.getByRole('button', { name: 'opacity-text'});
});
@kovbe21 in RNTL 14 the way of calculating accessible name has been aligned with Web/React Testing Library. It now uses the name that screen reader would use: if given view has accessibility label it takes preference over text content when both are present. Only if there is no a11y label then text content is taken into consideration.
Activity
mdjastrzebski commentedon Jul 1, 2026
@kovbe21 in RNTL 14 the way of calculating accessible name has been aligned with Web/React Testing Library. It now uses the name that screen reader would use: if given view has accessibility label it takes preference over text content when both are present. Only if there is no a11y label then text content is taken into consideration.
kovbe21 commentedon Jul 2, 2026
Hi @mdjastrzebski!
I see. Its a pity, we will need to adjust our tests since accessibility label is not the same as text content, but understandable.
Could you please update the docs so that it clearly state that when both is used, a11y label is searched for?
mdjastrzebski commentedon Jul 20, 2026
Docs updated in #1927