Skip to content

Commit 3df3c54

Browse files
committed
Address PR comments
1 parent 6ed73ac commit 3df3c54

15 files changed

+88
-85
lines changed

src/__tests__/act.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import act from '../act';
55
import render from '../render';
66
import fireEvent from '../fireEvent';
77

8-
type UseEffectProps = { callback: () => void };
8+
type UseEffectProps = { callback(): void };
99
const UseEffect = ({ callback }: UseEffectProps) => {
1010
React.useEffect(callback);
1111
return null;

src/__tests__/auto-cleanup-skip.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ beforeAll(() => {
1010

1111
let isMounted = false;
1212

13-
class Test extends React.Component<any> {
13+
class Test extends React.Component<{ onUnmount?(): void }> {
1414
componentDidMount() {
1515
isMounted = true;
1616
}

src/__tests__/auto-cleanup.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { render } from '..';
44

55
let isMounted = false;
66

7-
class Test extends React.Component<{ onUnmount?: () => void }> {
7+
class Test extends React.Component<{ onUnmount?(): void }> {
88
componentDidMount() {
99
isMounted = true;
1010
}

src/__tests__/byText.test.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const Banana = () => {
3434
);
3535
};
3636

37+
type ChildrenProps = { children: React.ReactNode };
38+
3739
test('getByText, queryByText', () => {
3840
const { getByText, queryByText } = render(<Banana />);
3941
const button = getByText(/change/i);
@@ -148,8 +150,7 @@ describe('findBy options deprecations', () => {
148150
});
149151

150152
test.skip('getByText works properly with custom text component', () => {
151-
type BoldTextProps = { children: React.ReactNode };
152-
function BoldText({ children }: BoldTextProps) {
153+
function BoldText({ children }: ChildrenProps) {
153154
return <Text>{children}</Text>;
154155
}
155156

@@ -163,12 +164,10 @@ test.skip('getByText works properly with custom text component', () => {
163164
});
164165

165166
test.skip('getByText works properly with custom text container', () => {
166-
type MyTextProps = { children: React.ReactNode };
167-
function MyText({ children }: MyTextProps) {
167+
function MyText({ children }: ChildrenProps) {
168168
return <Text>{children}</Text>;
169169
}
170-
type BoldTextProps = { children: React.ReactNode };
171-
function BoldText({ children }: BoldTextProps) {
170+
function BoldText({ children }: ChildrenProps) {
172171
return <Text>{children}</Text>;
173172
}
174173

@@ -266,8 +265,7 @@ test('queryByText with nested Text components each with text return the lowest o
266265
});
267266

268267
test('queryByText nested deep <CustomText> in <Text>', () => {
269-
type CustomTextProps = { children: React.ReactNode };
270-
const CustomText = ({ children }: CustomTextProps) => {
268+
const CustomText = ({ children }: ChildrenProps) => {
271269
return <Text>{children}</Text>;
272270
};
273271

src/helpers/a11yAPI.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ReactTestInstance } from 'react-test-renderer';
22
import type { AccessibilityRole, AccessibilityState } from 'react-native';
33
import type { WaitForOptions } from '../waitFor';
4+
import type { TextMatch } from '../matches';
45
import makeA11yQuery from './makeA11yQuery';
56

67
type AccessibilityStateKey = keyof AccessibilityState;
@@ -20,42 +21,42 @@ type FindAllReturn = Promise<GetAllReturn>;
2021

2122
export type A11yAPI = {
2223
// Label
23-
getByLabelText: (label: string | RegExp) => GetReturn;
24-
getAllByLabelText: (label: string | RegExp) => GetAllReturn;
25-
queryByLabelText: (label: string | RegExp) => QueryReturn;
26-
queryAllByLabelText: (label: string | RegExp) => QueryAllReturn;
24+
getByLabelText: (label: TextMatch) => GetReturn;
25+
getAllByLabelText: (label: TextMatch) => GetAllReturn;
26+
queryByLabelText: (label: TextMatch) => QueryReturn;
27+
queryAllByLabelText: (label: TextMatch) => QueryAllReturn;
2728
findByLabelText: (
28-
label: string | RegExp,
29+
label: TextMatch,
2930
waitForOptions?: WaitForOptions
3031
) => FindReturn;
3132
findAllByLabelText: (
32-
label: string | RegExp,
33+
label: TextMatch,
3334
waitForOptions?: WaitForOptions
3435
) => FindAllReturn;
3536

3637
// Hint
37-
getByA11yHint: (a11yHint: string | RegExp) => GetReturn;
38-
getByHintText: (a11yHint: string | RegExp) => GetReturn;
39-
getAllByA11yHint: (a11yHint: string | RegExp) => GetAllReturn;
40-
getAllByHintText: (a11yHint: string | RegExp) => GetAllReturn;
41-
queryByA11yHint: (a11yHint: string | RegExp) => QueryReturn;
42-
queryByHintText: (a11yHint: string | RegExp) => QueryReturn;
43-
queryAllByA11yHint: (a11yHint: string | RegExp) => QueryAllReturn;
44-
queryAllByHintText: (a11yHint: string | RegExp) => QueryAllReturn;
38+
getByA11yHint: (a11yHint: TextMatch) => GetReturn;
39+
getByHintText: (a11yHint: TextMatch) => GetReturn;
40+
getAllByA11yHint: (a11yHint: TextMatch) => GetAllReturn;
41+
getAllByHintText: (a11yHint: TextMatch) => GetAllReturn;
42+
queryByA11yHint: (a11yHint: TextMatch) => QueryReturn;
43+
queryByHintText: (a11yHint: TextMatch) => QueryReturn;
44+
queryAllByA11yHint: (a11yHint: TextMatch) => QueryAllReturn;
45+
queryAllByHintText: (a11yHint: TextMatch) => QueryAllReturn;
4546
findByA11yHint: (
46-
a11yHint: string | RegExp,
47+
a11yHint: TextMatch,
4748
waitForOptions?: WaitForOptions
4849
) => FindReturn;
4950
findByHintText: (
50-
a11yHint: string | RegExp,
51+
a11yHint: TextMatch,
5152
waitForOptions?: WaitForOptions
5253
) => FindReturn;
5354
findAllByA11yHint: (
54-
a11yHint: string | RegExp,
55+
a11yHint: TextMatch,
5556
waitForOptions?: WaitForOptions
5657
) => FindAllReturn;
5758
findAllByHintText: (
58-
a11yHint: string | RegExp,
59+
a11yHint: TextMatch,
5960
waitForOptions?: WaitForOptions
6061
) => FindAllReturn;
6162

@@ -128,7 +129,7 @@ export type A11yAPI = {
128129

129130
export function matchStringValue(
130131
prop: string | undefined,
131-
matcher: string | RegExp
132+
matcher: TextMatch
132133
): boolean {
133134
if (!prop) {
134135
return false;

src/helpers/byDisplayValue.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ReactTestInstance } from 'react-test-renderer';
2-
import { matches } from '../matches';
2+
import { matches, TextMatch } from '../matches';
33
import { makeQueries } from './makeQueries';
44
import type { Queries } from './makeQueries';
55
import { filterNodeByType } from './filterNodeByType';
@@ -8,7 +8,7 @@ import type { TextMatchOptions } from './byText';
88

99
const getTextInputNodeByDisplayValue = (
1010
node: ReactTestInstance,
11-
value: string | RegExp,
11+
value: TextMatch,
1212
options: TextMatchOptions = {}
1313
) => {
1414
try {
@@ -30,7 +30,7 @@ const getTextInputNodeByDisplayValue = (
3030
const queryAllByDisplayValue = (
3131
instance: ReactTestInstance
3232
): ((
33-
displayValue: string | RegExp,
33+
displayValue: TextMatch,
3434
queryOptions?: TextMatchOptions
3535
) => Array<ReactTestInstance>) =>
3636
function queryAllByDisplayValueFn(displayValue, queryOptions) {
@@ -39,9 +39,9 @@ const queryAllByDisplayValue = (
3939
);
4040
};
4141

42-
const getMultipleError = (displayValue: string | RegExp) =>
42+
const getMultipleError = (displayValue: TextMatch) =>
4343
`Found multiple elements with display value: ${String(displayValue)} `;
44-
const getMissingError = (displayValue: string | RegExp) =>
44+
const getMissingError = (displayValue: TextMatch) =>
4545
`Unable to find an element with displayValue: ${String(displayValue)}`;
4646

4747
const {
@@ -50,7 +50,7 @@ const {
5050
queryBy: queryByDisplayValue,
5151
findBy: findByDisplayValue,
5252
findAllBy: findAllByDisplayValue,
53-
}: Queries<string | RegExp> = makeQueries(
53+
}: Queries<TextMatch> = makeQueries(
5454
queryAllByDisplayValue,
5555
getMissingError,
5656
getMultipleError

src/helpers/byPlaceholderText.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ReactTestInstance } from 'react-test-renderer';
2-
import { matches } from '../matches';
2+
import { matches, TextMatch } from '../matches';
33
import { makeQueries } from './makeQueries';
44
import type { Queries } from './makeQueries';
55
import { filterNodeByType } from './filterNodeByType';
@@ -8,7 +8,7 @@ import type { TextMatchOptions } from './byText';
88

99
const getTextInputNodeByPlaceholderText = (
1010
node: ReactTestInstance,
11-
placeholder: string | RegExp,
11+
placeholder: TextMatch,
1212
options: TextMatchOptions = {}
1313
) => {
1414
try {
@@ -26,7 +26,7 @@ const getTextInputNodeByPlaceholderText = (
2626
const queryAllByPlaceholderText = (
2727
instance: ReactTestInstance
2828
): ((
29-
placeholder: string | RegExp,
29+
placeholder: TextMatch,
3030
queryOptions?: TextMatchOptions
3131
) => Array<ReactTestInstance>) =>
3232
function queryAllByPlaceholderFn(placeholder, queryOptions) {
@@ -35,9 +35,9 @@ const queryAllByPlaceholderText = (
3535
);
3636
};
3737

38-
const getMultipleError = (placeholder: string | RegExp) =>
38+
const getMultipleError = (placeholder: TextMatch) =>
3939
`Found multiple elements with placeholder: ${String(placeholder)} `;
40-
const getMissingError = (placeholder: string | RegExp) =>
40+
const getMissingError = (placeholder: TextMatch) =>
4141
`Unable to find an element with placeholder: ${String(placeholder)}`;
4242

4343
const {
@@ -46,7 +46,7 @@ const {
4646
queryBy: queryByPlaceholderText,
4747
findBy: findByPlaceholderText,
4848
findAllBy: findAllByPlaceholderText,
49-
}: Queries<string | RegExp> = makeQueries(
49+
}: Queries<TextMatch> = makeQueries(
5050
queryAllByPlaceholderText,
5151
getMissingError,
5252
getMultipleError

src/helpers/byTestId.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { ReactTestInstance } from 'react-test-renderer';
2-
import { matches } from '../matches';
2+
import { matches, TextMatch } from '../matches';
33
import { makeQueries } from './makeQueries';
44
import type { Queries } from './makeQueries';
55
import type { TextMatchOptions } from './byText';
66

77
const getNodeByTestId = (
88
node: ReactTestInstance,
9-
testID: string | RegExp,
9+
testID: TextMatch,
1010
options: TextMatchOptions = {}
1111
) => {
1212
const { exact, normalizer } = options;
@@ -16,7 +16,7 @@ const getNodeByTestId = (
1616
const queryAllByTestId = (
1717
instance: ReactTestInstance
1818
): ((
19-
testId: string | RegExp,
19+
testId: TextMatch,
2020
queryOptions?: TextMatchOptions
2121
) => Array<ReactTestInstance>) =>
2222
function queryAllByTestIdFn(testId, queryOptions) {
@@ -27,9 +27,9 @@ const queryAllByTestId = (
2727
return results;
2828
};
2929

30-
const getMultipleError = (testId: string | RegExp) =>
30+
const getMultipleError = (testId: TextMatch) =>
3131
`Found multiple elements with testID: ${String(testId)}`;
32-
const getMissingError = (testId: string | RegExp) =>
32+
const getMissingError = (testId: TextMatch) =>
3333
`Unable to find an element with testID: ${String(testId)}`;
3434

3535
const {
@@ -38,7 +38,7 @@ const {
3838
queryBy: queryByTestId,
3939
findBy: findByTestId,
4040
findAllBy: findAllByTestId,
41-
}: Queries<string | RegExp> = makeQueries(
41+
}: Queries<TextMatch> = makeQueries(
4242
queryAllByTestId,
4343
getMissingError,
4444
getMultipleError

src/helpers/byText.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ReactTestInstance } from 'react-test-renderer';
22
import * as React from 'react';
3-
import { matches } from '../matches';
3+
import { matches, TextMatch } from '../matches';
44
import type { NormalizerFn } from '../matches';
55
import { makeQueries } from './makeQueries';
66
import type { Queries } from './makeQueries';
@@ -13,7 +13,7 @@ export type TextMatchOptions = {
1313
};
1414

1515
const getChildrenAsText = (
16-
children: (string | number | React.ReactElement)[],
16+
children: React.ReactChild[],
1717
TextComponent: React.ComponentType
1818
) => {
1919
const textContent: string[] = [];
@@ -50,7 +50,7 @@ const getChildrenAsText = (
5050

5151
const getNodeByText = (
5252
node: ReactTestInstance,
53-
text: string | RegExp,
53+
text: TextMatch,
5454
options: TextMatchOptions = {}
5555
) => {
5656
try {
@@ -73,7 +73,7 @@ const getNodeByText = (
7373
const queryAllByText = (
7474
instance: ReactTestInstance
7575
): ((
76-
text: string | RegExp,
76+
text: TextMatch,
7777
queryOptions?: TextMatchOptions
7878
) => Array<ReactTestInstance>) =>
7979
function queryAllByTextFn(text, queryOptions) {
@@ -84,9 +84,9 @@ const queryAllByText = (
8484
return results;
8585
};
8686

87-
const getMultipleError = (text: string | RegExp) =>
87+
const getMultipleError = (text: TextMatch) =>
8888
`Found multiple elements with text: ${String(text)}`;
89-
const getMissingError = (text: string | RegExp) =>
89+
const getMissingError = (text: TextMatch) =>
9090
`Unable to find an element with text: ${String(text)}`;
9191

9292
const {
@@ -95,7 +95,7 @@ const {
9595
queryBy: queryByText,
9696
findBy: findByText,
9797
findAllBy: findAllByText,
98-
}: Queries<string | RegExp> = makeQueries(
98+
}: Queries<TextMatch> = makeQueries(
9999
queryAllByText,
100100
getMissingError,
101101
getMultipleError

0 commit comments

Comments
 (0)