Repository navigation
Description
Describe the bug
On Android, React Native's own Text passes accessible={false} to its host when it has no press handler, and true on iOS (https://github.com/react/react-native/blob/v0.79.7/packages/react-native/Libraries/Text/Text.js#L236-L243). isAccessibilityElement returns an explicit accessible as it is (
react-native-testing-library/src/helpers/accessibility.ts
Lines 97 to 99 in 564a842
| if (instance.props.accessible !== undefined) { | |
| return instance.props.accessible; | |
| } |
*ByRole asks it of every candidate, so on Android no Text without a press handler is found by its role: getByRole('header') misses every heading, and getByRole('text') every text.
React Native documents accessible as native focusable on Android and as isAccessibilityElement on iOS (https://reactnative.dev/docs/accessibility#accessible).
React Native's Jest preset mocks Text with a component that sets no accessible, so the difference shows wherever React Native's own Text renders: after jest.unmock, or under a runner that renders React Native's components, such as vitest-native.
Expected behavior
queryByRole('header', { name: 'Title' }) finds <Text accessibilityRole="header">Title</Text> on Android, as it does on iOS.
Steps to Reproduce
- In an empty folder, install the package with React Native 0.79.7 and Jest:
npm install @testing-library/react-native@14.1.0 react@19.1.0 react-native@0.79.7 test-renderer@1.3.1 jest@29 @babel/core@7 @react-native/babel-preset@0.79.7
- Add
babel.config.js:module.exports = { presets: ['module:@react-native/babel-preset'] };
- Add a Jest project per platform to
package.json:"jest": { "projects": [ { "displayName": "ios", "preset": "react-native", "haste": { "defaultPlatform": "ios", "platforms": ["android", "ios", "native"] } }, { "displayName": "android", "preset": "react-native", "haste": { "defaultPlatform": "android", "platforms": ["android", "ios", "native"] } } ] }
- Add
header.test.js:jest.unmock('react-native/Libraries/Text/Text'); const { render } = require('@testing-library/react-native'); const { Platform, Text } = require('react-native'); test('finds a Text header by its role', async () => { const view = await render(<Text accessibilityRole="header">Title</Text>); const header = view.queryByRole('header', { name: 'Title' }); const text = view.getByText('Title'); console.log( `${Platform.OS}: the host Text carries accessible=${String(text.props.accessible)}, queryByRole('header') ${header === null ? 'finds nothing' : 'finds it'}`, ); expect(header).not.toBeNull(); });
- Run
npx jest
Expected: both projects pass. Actual: the ios project passes and the android project fails.
Reproducer: https://gist.github.com/YevheniiKotyrlo/2c22a4c66cd61982fff113aeb2a2781c. node repro.mjs builds main (564a842), packs it, runs the steps above, and exits 1 while Android finds nothing:
@testing-library/react-native main at 564a842 (2026-11-05)
ios: the host Text carries accessible=true, queryByRole('header') finds it
android: the host Text carries accessible=false, queryByRole('header') finds nothing
RESULT: on Android, queryByRole('header') finds no Text header, which it finds on iOS
Without the jest.unmock line the preset's mock renders, the host carries accessible=undefined, and both projects pass.
Screenshots
None.
Versions
npmPackages:
@testing-library/react-native: file:../testing-library-react-native-14.1.0.tgz => 14.1.0
jest: ^29.7.0 => 29.7.0
react: ^19.1.0 => 19.1.0
react-native: ^0.79.7 => 0.79.7
test-renderer: ^1.3.1 => 1.3.1
Activity