Skip to content

Commit a5f168c

Browse files
committed
migrate flow types to ts
1 parent 1f725c7 commit a5f168c

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

src/helpers/a11yAPI.ts

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ReactTestInstance } from 'react-test-renderer';
2-
import type { AccessibilityRole, AccessibilityState } from 'react-native';
2+
import type { AccessibilityState } from 'react-native';
33
import type { WaitForOptions } from '../waitFor';
44
import type { TextMatch } from '../matches';
55
import makeA11yQuery from './makeA11yQuery';
@@ -11,6 +11,34 @@ type A11yValue = {
1111
now?: number;
1212
text?: string;
1313
};
14+
type A11yRole =
15+
| 'none'
16+
| 'button'
17+
| 'link'
18+
| 'search'
19+
| 'image'
20+
| 'keyboardkey'
21+
| 'text'
22+
| 'adjustable'
23+
| 'imagebutton'
24+
| 'header'
25+
| 'summary'
26+
| 'alert'
27+
| 'checkbox'
28+
| 'combobox'
29+
| 'menu'
30+
| 'menubar'
31+
| 'menuitem'
32+
| 'progressbar'
33+
| 'radio'
34+
| 'radiogroup'
35+
| 'scrollbar'
36+
| 'spinbutton'
37+
| 'switch'
38+
| 'tab'
39+
| 'tablist'
40+
| 'timer'
41+
| 'toolbar';
1442

1543
type GetReturn = ReactTestInstance;
1644
type GetAllReturn = Array<ReactTestInstance>;
@@ -19,6 +47,10 @@ type QueryAllReturn = Array<ReactTestInstance>;
1947
type FindReturn = Promise<GetReturn>;
2048
type FindAllReturn = Promise<GetAllReturn>;
2149

50+
export type QueryOptions = {
51+
name?: string | RegExp;
52+
};
53+
2254
export type A11yAPI = {
2355
// Label
2456
getByLabelText: (label: TextMatch) => GetReturn;
@@ -61,16 +93,30 @@ export type A11yAPI = {
6193
) => FindAllReturn;
6294

6395
// Role
64-
getByRole: (role: AccessibilityRole | RegExp) => GetReturn;
65-
getAllByRole: (role: AccessibilityRole | RegExp) => GetAllReturn;
66-
queryByRole: (role: AccessibilityRole | RegExp) => QueryReturn;
67-
queryAllByRole: (role: AccessibilityRole | RegExp) => QueryAllReturn;
96+
getByRole: (
97+
role: A11yRole | RegExp,
98+
queryOptions?: QueryOptions
99+
) => GetReturn;
100+
getAllByRole: (
101+
role: A11yRole | RegExp,
102+
queryOptions?: QueryOptions
103+
) => GetAllReturn;
104+
queryByRole: (
105+
role: A11yRole | RegExp,
106+
queryOptions?: QueryOptions
107+
) => QueryReturn;
108+
queryAllByRole: (
109+
role: A11yRole | RegExp,
110+
queryOptions?: QueryOptions
111+
) => QueryAllReturn;
68112
findByRole: (
69-
role: AccessibilityRole,
113+
role: A11yRole,
114+
queryOptions?: QueryOptions & WaitForOptions,
70115
waitForOptions?: WaitForOptions
71116
) => FindReturn;
72117
findAllByRole: (
73-
role: AccessibilityRole,
118+
role: A11yRole,
119+
queryOptions?: QueryOptions & WaitForOptions,
74120
waitForOptions?: WaitForOptions
75121
) => FindAllReturn;
76122

src/helpers/makeA11yQuery.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Example:
4848
};
4949

5050
type QueryOptions = {
51-
name: string | RegExp,
51+
name: string | RegExp;
5252
};
5353

5454
type QueryNames = {
@@ -64,9 +64,7 @@ const makeA11yQuery = <P extends unknown, M extends unknown>(
6464
name: string,
6565
queryNames: QueryNames,
6666
matcherFn: (prop: P, value: M) => boolean
67-
): ((instance: ReactTestInstance) => { ... }) => (
68-
instance: ReactTestInstance
69-
) => {
67+
) => (instance: ReactTestInstance) => {
7068
const filterWithName = (
7169
node: ReactTestInstance,
7270
options: QueryOptions,

0 commit comments

Comments
 (0)