Skip to content

Commit dafbcb2

Browse files
committed
chore: add more tests
1 parent 2dae631 commit dafbcb2

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

src/queries/__tests__/a11yValue.test.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { TouchableOpacity, Text } from 'react-native';
2+
import { View, Text, TouchableOpacity } from 'react-native';
33
import { render } from '../..';
44

55
const TEXT_LABEL = 'cool text';
@@ -103,6 +103,30 @@ test('byA11yValue queries support hidden option', () => {
103103
expect(() =>
104104
getByA11yValue({ max: 10 }, { includeHiddenElements: false })
105105
).toThrowErrorMatchingInlineSnapshot(
106-
`"Unable to find an element with accessibilityValue: {"max":10}"`
106+
`"Unable to find an element with max value: 10"`
107+
);
108+
});
109+
110+
test('byA11yValue error messages', () => {
111+
const { getByA11yValue } = render(<View />);
112+
expect(() =>
113+
getByA11yValue({ min: 10, max: 10 })
114+
).toThrowErrorMatchingInlineSnapshot(
115+
`"Unable to find an element with min value: 10, max value: 10"`
116+
);
117+
expect(() =>
118+
getByA11yValue({ max: 20, now: 5 })
119+
).toThrowErrorMatchingInlineSnapshot(
120+
`"Unable to find an element with max value: 20, now value: 5"`
121+
);
122+
expect(() =>
123+
getByA11yValue({ min: 1, max: 2, now: 3 })
124+
).toThrowErrorMatchingInlineSnapshot(
125+
`"Unable to find an element with min value: 1, max value: 2, now value: 3"`
126+
);
127+
expect(() =>
128+
getByA11yValue({ min: 1, max: 2, now: 3, text: /foo/i })
129+
).toThrowErrorMatchingInlineSnapshot(
130+
`"Unable to find an element with min value: 1, max value: 2, now value: 3, text value: /foo/i"`
107131
);
108132
});

src/queries/__tests__/role-value.test.tsx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { View } from 'react-native';
2+
import { View, Text } from 'react-native';
33
import { render } from '../..';
44

55
describe('accessibility value', () => {
@@ -58,4 +58,44 @@ describe('accessibility value', () => {
5858
expect(queryByRole('adjustable', { value: { text: 'No' } })).toBeFalsy();
5959
expect(queryByRole('adjustable', { value: { text: /no/ } })).toBeFalsy();
6060
});
61+
62+
test('matches using single value and other options', () => {
63+
const { getByRole } = render(
64+
<Text
65+
accessibilityRole="adjustable"
66+
accessibilityState={{ disabled: true }}
67+
accessibilityValue={{ min: 10, max: 20, now: 12, text: 'Hello' }}
68+
>
69+
Hello
70+
</Text>
71+
);
72+
73+
expect(
74+
getByRole('adjustable', { name: 'Hello', value: { min: 10 } })
75+
).toBeTruthy();
76+
expect(
77+
getByRole('adjustable', { disabled: true, value: { min: 10 } })
78+
).toBeTruthy();
79+
80+
expect(() =>
81+
getByRole('adjustable', { name: 'Hello', value: { min: 5 } })
82+
).toThrowErrorMatchingInlineSnapshot(
83+
`"Unable to find an element with role: "adjustable", name: "Hello", min value: 5"`
84+
);
85+
expect(() =>
86+
getByRole('adjustable', { name: 'World', value: { min: 10 } })
87+
).toThrowErrorMatchingInlineSnapshot(
88+
`"Unable to find an element with role: "adjustable", name: "World", min value: 10"`
89+
);
90+
expect(() =>
91+
getByRole('adjustable', { name: 'Hello', value: { min: 5 } })
92+
).toThrowErrorMatchingInlineSnapshot(
93+
`"Unable to find an element with role: "adjustable", name: "Hello", min value: 5"`
94+
);
95+
expect(() =>
96+
getByRole('adjustable', { selected: true, value: { min: 10 } })
97+
).toThrowErrorMatchingInlineSnapshot(
98+
`"Unable to find an element with role: "adjustable", selected state: true, min value: 10"`
99+
);
100+
});
61101
});

0 commit comments

Comments
 (0)