Skip to content

Commit fa35bc9

Browse files
committed
refactor: pre-merge tweaks
1 parent c86b75c commit fa35bc9

File tree

17 files changed

+54
-46
lines changed

17 files changed

+54
-46
lines changed

src/__tests__/config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ test('resetToDefaults() resets config to defaults', () => {
2323
configure({
2424
asyncUtilTimeout: 5000,
2525
defaultIncludeHiddenElements: false,
26-
defaultHidden: false,
2726
});
2827
expect(getConfig().asyncUtilTimeout).toEqual(5000);
2928
expect(getConfig().defaultIncludeHiddenElements).toEqual(false);
@@ -35,6 +34,7 @@ test('resetToDefaults() resets config to defaults', () => {
3534

3635
test('configure handles alias option defaultHidden', () => {
3736
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
37+
3838
configure({ defaultHidden: false });
3939
expect(getConfig().defaultIncludeHiddenElements).toEqual(false);
4040
});

src/config.ts

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

7-
/** Default includeHiddenElements value for all queries */
7+
/** Default value for `includeHiddenElements` query option. */
88
defaultIncludeHiddenElements: boolean;
99

1010
/** Default options for `debug` helper. */
1111
defaultDebugOptions?: Partial<DebugOptions>;
1212
};
1313

1414
export type ConfigAliasOptions = {
15-
/** Default hidden value for all queries, alias to defaultIncludeHiddenElements to respect react-testing-library API
16-
* WARNING: if both defaultHidden and defaultIncludeHiddenElements values are defined,
17-
* then defaultIncludeHiddenElements will take precedence
18-
*/
15+
/** RTL-compatibility alias to `defaultIncludeHiddenElements` */
1916
defaultHidden: boolean;
2017
};
2118

@@ -34,14 +31,10 @@ export function configure(options: Partial<Config & ConfigAliasOptions>) {
3431
defaultHidden ??
3532
config.defaultIncludeHiddenElements;
3633

37-
const optionsToSet = {
38-
...restOptions,
39-
defaultIncludeHiddenElements,
40-
};
41-
4234
config = {
4335
...config,
44-
...optionsToSet,
36+
...restOptions,
37+
defaultIncludeHiddenElements,
4538
};
4639
}
4740

src/helpers/__tests__/includeHiddenElements.test.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import { View } from 'react-native';
21
import React from 'react';
3-
4-
import render from '../../render';
5-
import { screen } from '../../screen';
6-
import { configure } from '../../config';
2+
import { View } from 'react-native';
3+
import { configure, render, screen } from '../..';
74

85
test('includeHiddenElements query option takes priority over hidden option and global config', () => {
96
configure({ defaultHidden: true, defaultIncludeHiddenElements: true });

src/helpers/findAll.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ export function findAll(
1515
) {
1616
const results = root.findAll(predicate);
1717

18-
const hidden =
18+
const includeHiddenElements =
1919
options?.includeHiddenElements ??
2020
options?.hidden ??
2121
getConfig()?.defaultIncludeHiddenElements;
2222

23-
if (hidden) {
23+
if (includeHiddenElements) {
2424
return results;
2525
}
2626

src/queries/__tests__/a11yState.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,7 @@ test('byA11yState queries support hidden option', () => {
247247
).toBeFalsy();
248248
expect(() =>
249249
getByA11yState({ expanded: false }, { includeHiddenElements: false })
250-
).toThrow();
250+
).toThrowErrorMatchingInlineSnapshot(
251+
`"Unable to find an element with expanded state: false"`
252+
);
251253
});

src/queries/__tests__/a11yValue.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,7 @@ test('byA11yValue queries support hidden option', () => {
110110
).toBeFalsy();
111111
expect(() =>
112112
getByA11yValue({ max: 10 }, { includeHiddenElements: false })
113-
).toThrow();
113+
).toThrowErrorMatchingInlineSnapshot(
114+
`"Unable to find an element with accessibilityValue: {"max":10}"`
115+
);
114116
});

src/queries/__tests__/displayValue.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,7 @@ test('byDisplayValue queries support hidden option', () => {
115115
).toBeFalsy();
116116
expect(() =>
117117
getByDisplayValue('hidden', { includeHiddenElements: false })
118-
).toThrow();
118+
).toThrowErrorMatchingInlineSnapshot(
119+
`"Unable to find an element with displayValue: hidden"`
120+
);
119121
});

src/queries/__tests__/hintText.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,7 @@ test('byHintText queries support hidden option', () => {
122122
).toBeFalsy();
123123
expect(() =>
124124
getByHintText('hidden', { includeHiddenElements: false })
125-
).toThrow();
125+
).toThrowErrorMatchingInlineSnapshot(
126+
`"Unable to find an element with accessibilityHint: hidden"`
127+
);
126128
});

src/queries/__tests__/labelText.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,7 @@ test('byLabelText queries support hidden option', () => {
161161
).toBeFalsy();
162162
expect(() =>
163163
getByLabelText('hidden', { includeHiddenElements: false })
164-
).toThrow();
164+
).toThrowErrorMatchingInlineSnapshot(
165+
`"Unable to find an element with accessibilityLabel: hidden"`
166+
);
165167
});

src/queries/__tests__/placeholderText.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,7 @@ test('byPlaceholderText queries support hidden option', () => {
7474
).toBeFalsy();
7575
expect(() =>
7676
getByPlaceholderText('hidden', { includeHiddenElements: false })
77-
).toThrow();
77+
).toThrowErrorMatchingInlineSnapshot(
78+
`"Unable to find an element with placeholder: hidden"`
79+
);
7880
});

0 commit comments

Comments
 (0)