Skip to content

Commit 5f94d52

Browse files
byRole queries return only accessibility elements (#1244)
* refactor: group tests in accessibility * feat: add isAccessibilityElement helper * chore: fix typo * feat: handle accessible in byrole * feat: only check accessibility when useBreakingChanges true * test: group a11y tests together * test: add implicit accessible test * test: review byrole test titles * test: add test case for byRole * refactor: code review changes * fix: code cov warnings Co-authored-by: Maciej Jastrzębski <[email protected]>
1 parent d261f61 commit 5f94d52

8 files changed

+1073
-141
lines changed

src/__tests__/host-component-names.test.tsx

+23
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import { View } from 'react-native';
22
import TestRenderer from 'react-test-renderer';
33
import { configureInternal, getConfig } from '../config';
44
import { getHostComponentNames } from '../helpers/host-component-names';
5+
import * as within from '../within';
56

67
const mockCreate = jest.spyOn(TestRenderer, 'create') as jest.Mock;
8+
const mockGetQueriesForElements = jest.spyOn(
9+
within,
10+
'getQueriesForElement'
11+
) as jest.Mock;
712

813
describe('getHostComponentNames', () => {
914
test('updates internal config with host component names when they are not defined', () => {
@@ -45,4 +50,22 @@ describe('getHostComponentNames', () => {
4550
"
4651
`);
4752
});
53+
54+
test('throw an error when autodetection fails due to getByTestId returning non-host component', () => {
55+
mockGetQueriesForElements.mockReturnValue({
56+
getByTestId: () => {
57+
return { type: View };
58+
},
59+
});
60+
61+
expect(() => getHostComponentNames()).toThrowErrorMatchingInlineSnapshot(`
62+
"Trying to detect host component names triggered the following error:
63+
64+
getByTestId returned non-host component
65+
66+
There seems to be an issue with your configuration that prevents React Native Testing Library from working correctly.
67+
Please check if you are using compatible versions of React Native and React Native Testing Library.
68+
"
69+
`);
70+
});
4871
});

0 commit comments

Comments
 (0)