diff --git a/src/queries/role.test.tsx b/src/queries/role.test.tsx new file mode 100644 index 00000000..455645c8 --- /dev/null +++ b/src/queries/role.test.tsx @@ -0,0 +1,22 @@ +import * as React from 'react'; +import { Text, View } from 'react-native'; +import { render } from '..'; + +it('finds elements by role with name option using text fallback when accessible name is not set', async () => { + const Component = () => ( + + + Submit Form + + + ); + + const { getByRole } = await render(); + + // When an element has a role but no accessible name, getByRole falls back + // to searching by text content - this is critical for testing components + // where accessible labels aren't explicitly set but text content identifies the element + const button = getByRole('button', { name: 'Submit Form' }); + expect(button).toBeOnTheScreen(); + expect(button.props.accessibilityRole).toBe('button'); +});