Skip to content

byRole queries return only accessibility elements #1244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/__tests__/host-component-names.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import { View } from 'react-native';
import TestRenderer from 'react-test-renderer';
import { configureInternal, getConfig } from '../config';
import { getHostComponentNames } from '../helpers/host-component-names';
import * as within from '../within';

const mockCreate = jest.spyOn(TestRenderer, 'create') as jest.Mock;
const mockGetQueriesForElements = jest.spyOn(
within,
'getQueriesForElement'
) as jest.Mock;

describe('getHostComponentNames', () => {
test('updates internal config with host component names when they are not defined', () => {
Expand Down Expand Up @@ -45,4 +50,22 @@ describe('getHostComponentNames', () => {
"
`);
});

test('throw an error when autodetection fails due to getByTestId returning non-host component', () => {
mockGetQueriesForElements.mockReturnValue({
getByTestId: () => {
return { type: View };
},
});

expect(() => getHostComponentNames()).toThrowErrorMatchingInlineSnapshot(`
"Trying to detect host component names triggered the following error:

getByTestId returned non-host component

There seems to be an issue with your configuration that prevents React Native Testing Library from working correctly.
Please check if you are using compatible versions of React Native and React Native Testing Library.
"
`);
});
});
Loading