Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Commit 1e1b0f2

Browse files
committed
feat: add more accessibility queries
1 parent ee3d2cf commit 1e1b0f2

File tree

4 files changed

+244
-123
lines changed

4 files changed

+244
-123
lines changed

src/__tests__/queries.find.js

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,51 @@ import { render } from '../.';
55

66
test('find asynchronously finds elements', async () => {
77
const {
8-
findByA11yLabel,
8+
findAllByA11yHint,
99
findAllByA11yLabel,
10-
11-
findByPlaceholder,
10+
findAllByA11yRole,
11+
findAllByA11yStates,
12+
findAllByA11yTraits,
1213
findAllByPlaceholder,
13-
14-
findByText,
14+
findAllByTestId,
1515
findAllByText,
16-
17-
findByValue,
1816
findAllByValue,
19-
17+
findByA11yHint,
18+
findByA11yLabel,
2019
findByA11yRole,
21-
findAllByA11yRole,
22-
20+
findByA11yStates,
21+
findByA11yTraits,
22+
findByPlaceholder,
2323
findByTestId,
24-
findAllByTestId,
24+
findByText,
25+
findByValue,
2526
} = render(
2627
<View>
2728
<Text testID="test-id" accessibilityRole="text">
2829
test text content
2930
</Text>
3031
<TextInput placeholder="placeholder" />
3132
<TextInput value="value" />
33+
<TextInput accessibilityStates={['disabled']} />
3234
<Image accessibilityLabel="test-label" src="/lucy-ricardo.png" />
33-
<View role="dialog" />
35+
<Image accessibilityHint="test-hint" src="/lucy-ricardo.png" />
36+
<View accessibilityRole="dialog" />
37+
<View accessibilityTraits={['button']} />
3438
</View>,
3539
);
3640

41+
await expect(findByA11yHint('test-hint')).resolves.toBeTruthy();
42+
await expect(findAllByA11yHint('test-hint')).resolves.toHaveLength(1);
43+
3744
await expect(findByA11yLabel('test-label')).resolves.toBeTruthy();
3845
await expect(findAllByA11yLabel('test-label')).resolves.toHaveLength(1);
3946

47+
await expect(findByA11yStates(['disabled'])).resolves.toBeTruthy();
48+
await expect(findAllByA11yStates(['disabled'])).resolves.toHaveLength(1);
49+
50+
await expect(findByA11yTraits(['button'])).resolves.toBeTruthy();
51+
await expect(findAllByA11yTraits(['button'])).resolves.toHaveLength(1);
52+
4053
await expect(findByPlaceholder('placeholder')).resolves.toBeTruthy();
4154
await expect(findAllByPlaceholder('placeholder')).resolves.toHaveLength(1);
4255

@@ -55,31 +68,44 @@ test('find asynchronously finds elements', async () => {
5568

5669
test('find rejects when something cannot be found', async () => {
5770
const {
58-
findByA11yLabel,
71+
findAllByA11yHint,
5972
findAllByA11yLabel,
60-
61-
findByPlaceholder,
73+
findAllByA11yRole,
74+
findAllByA11yStates,
75+
findAllByA11yTraits,
6276
findAllByPlaceholder,
63-
64-
findByText,
77+
findAllByTestId,
6578
findAllByText,
66-
67-
findByValue,
6879
findAllByValue,
69-
80+
findByA11yHint,
81+
findByA11yLabel,
7082
findByA11yRole,
71-
findAllByA11yRole,
72-
83+
findByA11yStates,
84+
findByA11yTraits,
85+
findByPlaceholder,
7386
findByTestId,
74-
findAllByTestId,
87+
findByText,
88+
findByValue,
7589
} = render(<View />);
7690

7791
const qo = {};
7892
const wo = { timeout: 10 };
7993

94+
await expect(findByA11yHint('x', qo, wo)).rejects.toThrow('x');
95+
await expect(findAllByA11yHint('x', qo, wo)).rejects.toThrow('x');
96+
8097
await expect(findByA11yLabel('x', qo, wo)).rejects.toThrow('x');
8198
await expect(findAllByA11yLabel('x', qo, wo)).rejects.toThrow('x');
8299

100+
await expect(findByA11yRole('x', qo, wo)).rejects.toThrow('x');
101+
await expect(findAllByA11yRole('x', qo, wo)).rejects.toThrow('x');
102+
103+
await expect(findByA11yStates('x', qo, wo)).rejects.toThrow('x');
104+
await expect(findAllByA11yStates('x', qo, wo)).rejects.toThrow('x');
105+
106+
await expect(findByA11yTraits('x', qo, wo)).rejects.toThrow('x');
107+
await expect(findAllByA11yTraits('x', qo, wo)).rejects.toThrow('x');
108+
83109
await expect(findByPlaceholder('x', qo, wo)).rejects.toThrow('x');
84110
await expect(findAllByPlaceholder('x', qo, wo)).rejects.toThrow('x');
85111

@@ -89,9 +115,6 @@ test('find rejects when something cannot be found', async () => {
89115
await expect(findByValue('x', qo, wo)).rejects.toThrow('x');
90116
await expect(findAllByValue('x', qo, wo)).rejects.toThrow('x');
91117

92-
await expect(findByA11yRole('x', qo, wo)).rejects.toThrow('x');
93-
await expect(findAllByA11yRole('x', qo, wo)).rejects.toThrow('x');
94-
95118
await expect(findByTestId('x', qo, wo)).rejects.toThrow('x');
96119
await expect(findAllByTestId('x', qo, wo)).rejects.toThrow('x');
97120
});

src/__tests__/wait-for-element-to-be-removed.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test('resolves only when the element is removed', async () => {
3333
// 2. The element should be removed immediately
3434
// so if it doesn't in the first 100ms then we know something's wrong
3535
// so we'll fail early and not wait the full timeout
36-
await waitForElementToBeRemoved(() => queryAllByTestId('view'), { timeout: 500 });
36+
await waitForElementToBeRemoved(() => queryAllByTestId('view'), { timeout: 250 });
3737
});
3838

3939
test('resolves on mutation if callback throws an error', async () => {
@@ -55,5 +55,5 @@ test('resolves on mutation if callback throws an error', async () => {
5555

5656
const { getByTestId } = render(<MutatedElement />);
5757

58-
await waitForElementToBeRemoved(() => getByTestId('view'), { timeout: 100 });
58+
await waitForElementToBeRemoved(() => getByTestId('view'), { timeout: 250 });
5959
});

0 commit comments

Comments
 (0)