Skip to content

Commit dfcd2ed

Browse files
author
EBAM006
committed
refactor: rename includeHiddenFromAccessibility to includeHiddenElements
1 parent cb569a2 commit dfcd2ed

16 files changed

+92
-56
lines changed

src/__tests__/config.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ test('configure() overrides existing config values', () => {
1515
asyncUtilTimeout: 5000,
1616
defaultDebugOptions: { message: 'debug message' },
1717
defaultHidden: true,
18-
defaultIncludeHidden: true,
18+
defaultIncludeHiddenElements: true,
1919
});
2020
});
2121

2222
test('resetToDefaults() resets config to defaults', () => {
2323
configure({
2424
asyncUtilTimeout: 5000,
25-
defaultIncludeHidden: false,
25+
defaultIncludeHiddenElements: false,
2626
defaultHidden: false,
2727
});
2828
expect(getConfig().asyncUtilTimeout).toEqual(5000);
2929
expect(getConfig().defaultHidden).toEqual(false);
30-
expect(getConfig().defaultIncludeHidden).toEqual(false);
30+
expect(getConfig().defaultIncludeHiddenElements).toEqual(false);
3131

3232
resetToDefaults();
3333
expect(getConfig().asyncUtilTimeout).toEqual(1000);
3434
expect(getConfig().defaultHidden).toEqual(true);
35-
expect(getConfig().defaultIncludeHidden).toEqual(true);
35+
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
3636
});

src/config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ export type Config = {
44
/** Default timeout, in ms, for `waitFor` and `findBy*` queries. */
55
asyncUtilTimeout: number;
66

7-
/** Default includeHidden value for all queries */
8-
defaultIncludeHidden: boolean;
7+
/** Default includeHiddenElements value for all queries */
8+
defaultIncludeHiddenElements: boolean;
99

10-
/** Default hidden value for all queries, alias to defaultIncludeHidden to respect react-testing-library API
11-
* WARNING: if both defaultHidden and defaultIncludeHidden values are defined,
12-
* then defaultIncludeHidden will take precedence
10+
/** Default hidden value for all queries, alias to defaultIncludeHiddenElements to respect react-testing-library API
11+
* WARNING: if both defaultHidden and defaultIncludeHiddenElements values are defined,
12+
* then defaultIncludeHiddenElements will take precedence
1313
*/
1414
defaultHidden: boolean;
1515

@@ -20,7 +20,7 @@ export type Config = {
2020
const defaultConfig: Config = {
2121
asyncUtilTimeout: 1000,
2222
defaultHidden: true,
23-
defaultIncludeHidden: true,
23+
defaultIncludeHiddenElements: true,
2424
};
2525

2626
let config = { ...defaultConfig };

src/helpers/findAll.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { isHiddenFromAccessibility } from './accessiblity';
44

55
interface FindAllOptions {
66
hidden?: boolean;
7-
includeHidden?: boolean;
7+
includeHiddenElements?: boolean;
88
}
99

1010
export function findAll(
@@ -13,11 +13,13 @@ export function findAll(
1313
options?: FindAllOptions
1414
) {
1515
const results = root.findAll(predicate);
16-
const includeHiddenQueryOption = options?.includeHidden ?? options?.hidden;
17-
const defaultIncludeHidden =
18-
getConfig()?.defaultIncludeHidden ?? getConfig()?.defaultHidden;
16+
const includeHiddenElementsQueryOption =
17+
options?.includeHiddenElements ?? options?.hidden;
18+
const defaultIncludeHiddenElements =
19+
getConfig()?.defaultIncludeHiddenElements ?? getConfig()?.defaultHidden;
1920

20-
const hidden = includeHiddenQueryOption ?? defaultIncludeHidden;
21+
const hidden =
22+
includeHiddenElementsQueryOption ?? defaultIncludeHiddenElements;
2123
if (hidden) {
2224
return results;
2325
}

src/queries/__tests__/a11yState.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,17 @@ test('byA11yState queries support hidden option', () => {
240240
expect(getByA11yState({ expanded: false })).toBeTruthy();
241241
expect(getByA11yState({ expanded: false }, { hidden: true })).toBeTruthy();
242242
expect(
243-
getByA11yState({ expanded: false }, { includeHidden: true })
243+
getByA11yState({ expanded: false }, { includeHiddenElements: true })
244244
).toBeTruthy();
245245

246246
expect(queryByA11yState({ expanded: false }, { hidden: false })).toBeFalsy();
247247
expect(() =>
248248
getByA11yState({ expanded: false }, { hidden: false })
249249
).toThrow();
250250
expect(
251-
queryByA11yState({ expanded: false }, { includeHidden: false })
251+
queryByA11yState({ expanded: false }, { includeHiddenElements: false })
252252
).toBeFalsy();
253253
expect(() =>
254-
getByA11yState({ expanded: false }, { includeHidden: false })
254+
getByA11yState({ expanded: false }, { includeHiddenElements: false })
255255
).toThrow();
256256
});

src/queries/__tests__/a11yValue.test.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,16 @@ test('byA11yValue queries support hidden option', () => {
102102

103103
expect(getByA11yValue({ max: 10 })).toBeTruthy();
104104
expect(getByA11yValue({ max: 10 }, { hidden: true })).toBeTruthy();
105-
expect(getByA11yValue({ max: 10 }, { includeHidden: true })).toBeTruthy();
105+
expect(
106+
getByA11yValue({ max: 10 }, { includeHiddenElements: true })
107+
).toBeTruthy();
106108

107109
expect(queryByA11yValue({ max: 10 }, { hidden: false })).toBeFalsy();
108110
expect(() => getByA11yValue({ max: 10 }, { hidden: false })).toThrow();
109-
expect(queryByA11yValue({ max: 10 }, { includeHidden: false })).toBeFalsy();
110-
expect(() => getByA11yValue({ max: 10 }, { includeHidden: false })).toThrow();
111+
expect(
112+
queryByA11yValue({ max: 10 }, { includeHiddenElements: false })
113+
).toBeFalsy();
114+
expect(() =>
115+
getByA11yValue({ max: 10 }, { includeHiddenElements: false })
116+
).toThrow();
111117
});

src/queries/__tests__/displayValue.test.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,16 @@ test('byDisplayValue queries support hidden option', () => {
107107

108108
expect(getByDisplayValue('hidden')).toBeTruthy();
109109
expect(getByDisplayValue('hidden', { hidden: true })).toBeTruthy();
110-
expect(getByDisplayValue('hidden', { includeHidden: true })).toBeTruthy();
110+
expect(
111+
getByDisplayValue('hidden', { includeHiddenElements: true })
112+
).toBeTruthy();
111113

112114
expect(queryByDisplayValue('hidden', { hidden: false })).toBeFalsy();
113115
expect(() => getByDisplayValue('hidden', { hidden: false })).toThrow();
114-
expect(queryByDisplayValue('hidden', { includeHidden: false })).toBeFalsy();
115-
expect(() => getByDisplayValue('hidden', { includeHidden: false })).toThrow();
116+
expect(
117+
queryByDisplayValue('hidden', { includeHiddenElements: false })
118+
).toBeFalsy();
119+
expect(() =>
120+
getByDisplayValue('hidden', { includeHiddenElements: false })
121+
).toThrow();
116122
});

src/queries/__tests__/hintText.test.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,14 @@ test('byHintText queries support hidden option', () => {
116116

117117
expect(getByHintText('hidden')).toBeTruthy();
118118
expect(getByHintText('hidden', { hidden: true })).toBeTruthy();
119-
expect(getByHintText('hidden', { includeHidden: true })).toBeTruthy();
119+
expect(getByHintText('hidden', { includeHiddenElements: true })).toBeTruthy();
120120

121121
expect(queryByHintText('hidden', { hidden: false })).toBeFalsy();
122122
expect(() => getByHintText('hidden', { hidden: false })).toThrow();
123-
expect(queryByHintText('hidden', { includeHidden: false })).toBeFalsy();
124-
expect(() => getByHintText('hidden', { includeHidden: false })).toThrow();
123+
expect(
124+
queryByHintText('hidden', { includeHiddenElements: false })
125+
).toBeFalsy();
126+
expect(() =>
127+
getByHintText('hidden', { includeHiddenElements: false })
128+
).toThrow();
125129
});

src/queries/__tests__/labelText.test.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,16 @@ test('byLabelText queries support hidden option', () => {
153153

154154
expect(getByLabelText('hidden')).toBeTruthy();
155155
expect(getByLabelText('hidden', { hidden: true })).toBeTruthy();
156-
expect(getByLabelText('hidden', { includeHidden: true })).toBeTruthy();
156+
expect(
157+
getByLabelText('hidden', { includeHiddenElements: true })
158+
).toBeTruthy();
157159

158160
expect(queryByLabelText('hidden', { hidden: false })).toBeFalsy();
159161
expect(() => getByLabelText('hidden', { hidden: false })).toThrow();
160-
expect(queryByLabelText('hidden', { includeHidden: false })).toBeFalsy();
161-
expect(() => getByLabelText('hidden', { includeHidden: false })).toThrow();
162+
expect(
163+
queryByLabelText('hidden', { includeHiddenElements: false })
164+
).toBeFalsy();
165+
expect(() =>
166+
getByLabelText('hidden', { includeHiddenElements: false })
167+
).toThrow();
162168
});

src/queries/__tests__/placeholderText.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,16 @@ test('byPlaceholderText queries support hidden option', () => {
6666

6767
expect(getByPlaceholderText('hidden')).toBeTruthy();
6868
expect(getByPlaceholderText('hidden', { hidden: true })).toBeTruthy();
69-
expect(getByPlaceholderText('hidden', { includeHidden: true })).toBeTruthy();
69+
expect(
70+
getByPlaceholderText('hidden', { includeHiddenElements: true })
71+
).toBeTruthy();
7072

7173
expect(queryByPlaceholderText('hidden', { hidden: false })).toBeFalsy();
7274
expect(() => getByPlaceholderText('hidden', { hidden: false })).toThrow();
7375
expect(
74-
queryByPlaceholderText('hidden', { includeHidden: false })
76+
queryByPlaceholderText('hidden', { includeHiddenElements: false })
7577
).toBeFalsy();
7678
expect(() =>
77-
getByPlaceholderText('hidden', { includeHidden: false })
79+
getByPlaceholderText('hidden', { includeHiddenElements: false })
7880
).toThrow();
7981
});

src/queries/__tests__/role.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,9 @@ test('byRole queries support hidden option', () => {
707707

708708
expect(getByRole('button')).toBeTruthy();
709709
expect(getByRole('button', { hidden: true })).toBeTruthy();
710-
expect(getByRole('button', { includeHidden: true })).toBeTruthy();
710+
expect(getByRole('button', { includeHiddenElements: true })).toBeTruthy();
711711

712712
expect(queryByRole('button', { hidden: false })).toBeFalsy();
713713
expect(() => getByRole('button', { hidden: false })).toThrow();
714-
expect(() => getByRole('button', { includeHidden: false })).toThrow();
714+
expect(() => getByRole('button', { includeHiddenElements: false })).toThrow();
715715
});

src/queries/__tests__/testId.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,11 @@ test('byTestId queries support hidden option', () => {
142142

143143
expect(getByTestId('hidden')).toBeTruthy();
144144
expect(getByTestId('hidden', { hidden: true })).toBeTruthy();
145-
expect(getByTestId('hidden', { includeHidden: true })).toBeTruthy();
145+
expect(getByTestId('hidden', { includeHiddenElements: true })).toBeTruthy();
146146

147147
expect(queryByTestId('hidden', { hidden: false })).toBeFalsy();
148148
expect(() => getByTestId('hidden', { hidden: false })).toThrow();
149-
expect(() => getByTestId('hidden', { includeHidden: false })).toThrow();
149+
expect(() =>
150+
getByTestId('hidden', { includeHiddenElements: false })
151+
).toThrow();
150152
});

src/queries/__tests__/text.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,12 @@ test('byText support hidden option', () => {
474474

475475
expect(getByText(/hidden/i)).toBeTruthy();
476476
expect(getByText(/hidden/i, { hidden: true })).toBeTruthy();
477-
expect(getByText(/hidden/i, { includeHidden: true })).toBeTruthy();
477+
expect(getByText(/hidden/i, { includeHiddenElements: true })).toBeTruthy();
478478

479479
expect(queryByText(/hidden/i, { hidden: false })).toBeFalsy();
480-
expect(queryByText(/hidden/i, { includeHidden: false })).toBeFalsy();
480+
expect(queryByText(/hidden/i, { includeHiddenElements: false })).toBeFalsy();
481481
expect(() => getByText(/hidden/i, { hidden: false })).toThrow();
482-
expect(() => getByText(/hidden/i, { includeHidden: false })).toThrow();
482+
expect(() =>
483+
getByText(/hidden/i, { includeHiddenElements: false })
484+
).toThrow();
483485
});

src/queries/options.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { NormalizerFn } from '../matches';
22

33
/**
4-
* hidden is an alias for includeHidden that exists only to match react-testing-library API
5-
* if both hidden and includeHidden values are defined, then includeHidden will take precedence
4+
* hidden is an alias for includeHiddenElements that exists only to match react-testing-library API
5+
* if both hidden and includeHiddenElements values are defined, then includeHiddenElements will take precedence
66
*/
7-
export type CommonQueryOptions = { hidden?: boolean; includeHidden?: boolean };
7+
export type CommonQueryOptions = {
8+
hidden?: boolean;
9+
includeHiddenElements?: boolean;
10+
};
811

912
export type TextMatchOptions = {
1013
exact?: boolean;

typings/index.flow.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ type QueryAllReturn = Array<ReactTestInstance> | [];
88
type FindReturn = Promise<ReactTestInstance>;
99
type FindAllReturn = Promise<ReactTestInstance[]>;
1010

11-
type CommonQueryOptions = { hidden?: boolean, includeHidden?: boolean };
11+
type CommonQueryOptions = {
12+
hidden?: boolean,
13+
includeHiddenElements?: boolean,
14+
};
1215
type TextMatch = string | RegExp;
1316

1417
declare type NormalizerFn = (textToNormalize: string) => string;
@@ -464,7 +467,7 @@ declare module '@testing-library/react-native' {
464467
declare interface Config {
465468
asyncUtilTimeout: number;
466469
defaultHidden: boolean;
467-
defaultIncludeHidden: boolean;
470+
defaultIncludeHiddenElements: boolean;
468471
defaultDebugOptions?: $Shape<DebugOptions>;
469472
}
470473

website/docs/API.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ title: API
5050
- [Configuration](#configuration)
5151
- [`configure`](#configure)
5252
- [`asyncUtilTimeout` option](#asyncutiltimeout-option)
53-
- [`defaultIncludeHidden` option](#defaultincludehidden-option)
53+
- [`defaultIncludeHiddenElements` option](#defaultincludehidden-option)
5454
- [`defaultHidden` option](#defaulthidden-option)
5555
- [`defaultDebugOptions` option](#defaultdebugoptions-option)
5656
- [`resetToDefaults()`](#resettodefaults)
@@ -792,13 +792,13 @@ function configure(options: Partial<Config>) {}
792792

793793
Default timeout, in ms, for async helper functions (`waitFor`, `waitForElementToBeRemoved`) and `findBy*` queries. Defaults to 1000 ms.
794794

795-
#### `defaultIncludeHidden` option
795+
#### `defaultIncludeHiddenElements` option
796796

797-
Default [includeHidden](Queries.md#includehidden-option) query option for all queries. This default option will be overridden by the one you specify directly when using your query.
797+
Default [includeHiddenElements](Queries.md#includehidden-option) query option for all queries. This default option will be overridden by the one you specify directly when using your query.
798798

799799
#### `defaultHidden` option
800800

801-
This is just an alias to the `defaultIncludeHidden` option. It only exists to match react-testing-library naming used in the [configuration options](https://testing-library.com/docs/dom-testing-library/api-configuration/#defaulthidden). Prefer the use of `defaultIncludeHidden` if possible as `defaultIncludeHidden: true` is clearer than `defaultHidden: true`.
801+
This is just an alias to the `defaultIncludeHiddenElements` option. It only exists to match react-testing-library naming used in the [configuration options](https://testing-library.com/docs/dom-testing-library/api-configuration/#defaulthidden). Prefer the use of `defaultIncludeHiddenElements` if possible as `defaultIncludeHiddenElements: true` is clearer than `defaultHidden: true`.
802802

803803
#### `defaultDebugOptions` option
804804

website/docs/Queries.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ title: Queries
2727
- [Default state for: `checked` and `expanded` keys](#default-state-for-checked-and-expanded-keys)
2828
- [`ByA11Value`, `ByAccessibilityValue`](#bya11value-byaccessibilityvalue)
2929
- [Common options](#common-options)
30-
- [`includeHidden` option](#includehidden-option)
30+
- [`includeHiddenElements` option](#includehidden-option)
3131
- [`hidden` option](#hidden-option)
3232
- [TextMatch](#textmatch)
3333
- [Examples](#examples)
@@ -377,9 +377,9 @@ const element = screen.getByA11yValue({ min: 40 });
377377

378378
## Common options
379379

380-
### `includeHidden` option
380+
### `includeHiddenElements` option
381381

382-
All queries have the `includeHidden` option which enables them to respect accessibility props on components when it is set to `false`. If you set `includeHidden` to `true`, elements that are normally excluded from the accessibility tree are considered for the query as well. Currently `includeHidden` option is set `true` by default, which means that elements includeHidden from accessibility will be included by default. However, we plan to change the default value to `includeHidden: false` in the next major release.
382+
All queries have the `includeHiddenElements` option which enables them to respect accessibility props on components when it is set to `false`. If you set `includeHiddenElements` to `true`, elements that are normally excluded from the accessibility tree are considered for the query as well. Currently `includeHiddenElements` option is set `true` by default, which means that elements includeHiddenElements from accessibility will be included by default. However, we plan to change the default value to `includeHiddenElements: false` in the next major release.
383383

384384
You can configure the default value with the [`configure` function](API.md#configure).
385385

@@ -392,19 +392,19 @@ render(<Text style={{ display: 'none' }}>I am hidden from accessibility</Text>);
392392

393393
// Include hidden elements
394394
expect(
395-
screen.queryByText('I am hidden from accessibility', { includeHidden: false })
395+
screen.queryByText('I am hidden from accessibility', { includeHiddenElements: false })
396396
).toBeFalsy();
397397

398398
// Match hidden elements
399-
expect(screen.getByText('I am hidden from accessibility')).toBeTruthy(); // Defaults to includeHidden: true for now
399+
expect(screen.getByText('I am hidden from accessibility')).toBeTruthy(); // Defaults to includeHiddenElements: true for now
400400
expect(
401-
screen.getByText('I am hidden from accessibility', { includeHidden: true })
401+
screen.getByText('I am hidden from accessibility', { includeHiddenElements: true })
402402
).toBeTruthy();
403403
```
404404

405405
### `hidden` option
406406

407-
This is just an alias to the `includeHidden` option. It only exists to match react-testing-library naming used in [byRole](https://testing-library.com/docs/queries/byrole/#hidden). Prefer the use of `includeHidden` if possible as `includeHidden: true` is clearer than `hidden: true`.
407+
This is just an alias to the `includeHiddenElements` option. It only exists to match react-testing-library naming used in [byRole](https://testing-library.com/docs/queries/byrole/#hidden). Prefer the use of `includeHiddenElements` if possible as `includeHiddenElements: true` is clearer than `hidden: true`.
408408

409409
## TextMatch
410410

0 commit comments

Comments
 (0)