Skip to content

Commit 5d2723a

Browse files
committed
refactor: tweaks
1 parent 8ccf3c4 commit 5d2723a

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

src/matchers/to-be-checked.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ export function toBeChecked(
3535
};
3636
}
3737

38-
const VALID_ROLES = new Set(['checkbox', 'radio']);
39-
4038
function hasValidAccessibilityRole(element: ReactTestInstance) {
39+
if (!isAccessibilityElement(element)) {
40+
return false;
41+
}
42+
4143
const role = getAccessibilityRole(element);
42-
return isAccessibilityElement(element) && VALID_ROLES.has(role);
44+
return role === 'checkbox' || role === 'radio';
4345
}

src/queries/__tests__/a11yValue.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,31 +308,31 @@ test('error message renders the element tree, preserving only helpful props', as
308308
`);
309309
});
310310

311-
describe('getByAccessibilityValue "aria-value*" props', () => {
312-
test('supports aria-valuemax', () => {
311+
describe('getByAccessibilityValue supports "aria-*" props', () => {
312+
test('supports "aria-valuemax"', () => {
313313
const screen = render(<View aria-valuemax={10} />);
314314
expect(screen.getByAccessibilityValue({ max: 10 })).toBeTruthy();
315315
});
316316

317-
test('supports aria-valuemin', () => {
317+
test('supports "aria-valuemin"', () => {
318318
const screen = render(<View aria-valuemin={20} />);
319319
expect(screen.getByAccessibilityValue({ min: 20 })).toBeTruthy();
320320
});
321321

322-
test('supports aria-valuenow', () => {
322+
test('supports "aria-valuenow"', () => {
323323
const screen = render(<View aria-valuenow={30} />);
324324
expect(screen.getByAccessibilityValue({ now: 30 })).toBeTruthy();
325325
});
326326

327-
test('supports aria-valuetext', () => {
327+
test('supports "aria-valuetext"', () => {
328328
const screen = render(<View aria-valuetext="Hello World" />);
329329
expect(
330330
screen.getByAccessibilityValue({ text: 'Hello World' })
331331
).toBeTruthy();
332332
expect(screen.getByAccessibilityValue({ text: /hello/i })).toBeTruthy();
333333
});
334334

335-
test('supports multiple aria-value* props', () => {
335+
test('supports multiple "aria-value*" props', () => {
336336
const screen = render(
337337
<View aria-valuenow={50} aria-valuemin={0} aria-valuemax={100} />
338338
);

src/queries/__tests__/makeQueries.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ describe('printing element tree', () => {
7171
aria-labelledby="ARIA_LABELLED_BY"
7272
aria-modal={true}
7373
aria-selected={false}
74+
aria-valuemax={30}
75+
aria-valuemin={10}
76+
aria-valuenow={20}
77+
aria-valuetext="Hello Value"
7478
importantForAccessibility="yes"
7579
nativeID="NATIVE_ID"
7680
role="summary"

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,19 @@ describe('accessibility value', () => {
177177
test('supports "aria-valuemax" prop', () => {
178178
const screen = render(<View accessible role="slider" aria-valuemax={10} />);
179179
expect(screen.getByRole('slider', { value: { max: 10 } })).toBeTruthy();
180+
expect(screen.queryByRole('slider', { value: { max: 20 } })).toBeNull();
180181
});
181182

182183
test('supports "aria-valuemin" prop', () => {
183184
const screen = render(<View accessible role="slider" aria-valuemin={20} />);
184185
expect(screen.getByRole('slider', { value: { min: 20 } })).toBeTruthy();
186+
expect(screen.queryByRole('slider', { value: { min: 30 } })).toBeNull();
185187
});
186188

187189
test('supports "aria-valuenow" prop', () => {
188190
const screen = render(<View accessible role="slider" aria-valuenow={30} />);
189191
expect(screen.getByRole('slider', { value: { now: 30 } })).toBeTruthy();
192+
expect(screen.queryByRole('slider', { value: { now: 10 } })).toBeNull();
190193
});
191194

192195
test('supports "aria-valuetext" prop', () => {
@@ -199,9 +202,15 @@ describe('accessibility value', () => {
199202
expect(
200203
screen.getByRole('slider', { value: { text: /hello/i } })
201204
).toBeTruthy();
205+
expect(
206+
screen.queryByRole('slider', { value: { text: 'Hello' } })
207+
).toBeNull();
208+
expect(
209+
screen.queryByRole('slider', { value: { text: /salut/i } })
210+
).toBeNull();
202211
});
203212

204-
test('supports multiple aria-value* props', () => {
213+
test('supports multiple "aria-value*" props', () => {
205214
const screen = render(
206215
<View
207216
accessible

website/docs/Queries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const element3 = screen.getByRole('button', { name: 'Hello', disabled: true });
121121

122122
`expanded`: You can filter elements by their expanded state (coming either from `aria-expanded` prop or `accessbilityState.expanded` prop). The possible values are `true` or `false`. See [React Native's accessibilityState](https://reactnative.dev/docs/accessibility#accessibilitystate) docs to learn more about the `expanded` state.
123123

124-
`value`: Filter elements by their accessibility value, based on either `aria-valuemin`, `aria-valuemax`, `aria-valuenow`, `aria-valuetext` or accessibilityValue props. Accessiblity value conceptually consist of numeric `min`, `max` and `now` values, as well as string `text` value. See React Native [accessibilityValue](https://reactnative.dev/docs/accessibility#accessibilityvalue) docs to learn more about the accessibility value.
124+
`value`: Filter elements by their accessibility value, based on either `aria-valuemin`, `aria-valuemax`, `aria-valuenow`, `aria-valuetext` or `accessibilityValue` props. Accessiblity value conceptually consists of numeric `min`, `max` and `now` entries, as well as string `text` entry. See React Native [accessibilityValue](https://reactnative.dev/docs/accessibility#accessibilityvalue) docs to learn more about the accessibility value concept.
125125

126126
### `ByText`
127127

0 commit comments

Comments
 (0)