forked from callstack/react-native-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindByAPI.js
82 lines (71 loc) · 2.9 KB
/
findByAPI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// @flow
import waitFor from '../waitFor';
import type { WaitForOptions } from '../waitFor';
import {
getByTestId,
getAllByTestId,
getByText,
getAllByText,
getByPlaceholderText,
getAllByPlaceholderText,
getByDisplayValue,
getAllByDisplayValue,
} from './getByAPI';
import { throwRenamedFunctionError } from './errors';
const makeFindQuery = <Text, Result>(
instance: ReactTestInstance,
getQuery: (instance: ReactTestInstance) => (text: Text) => Result,
text: Text,
waitForOptions: WaitForOptions
): Promise<Result> => waitFor(() => getQuery(instance)(text), waitForOptions);
export const findByTestId = (instance: ReactTestInstance) => (
testId: string | RegExp,
waitForOptions: WaitForOptions = {}
) => makeFindQuery(instance, getByTestId, testId, waitForOptions);
export const findAllByTestId = (instance: ReactTestInstance) => (
testId: string | RegExp,
waitForOptions: WaitForOptions = {}
) => makeFindQuery(instance, getAllByTestId, testId, waitForOptions);
export const findByText = (instance: ReactTestInstance) => (
text: string | RegExp,
waitForOptions: WaitForOptions = {}
) => makeFindQuery(instance, getByText, text, waitForOptions);
export const findAllByText = (instance: ReactTestInstance) => (
text: string | RegExp,
waitForOptions: WaitForOptions = {}
) => makeFindQuery(instance, getAllByText, text, waitForOptions);
export const findByPlaceholderText = (instance: ReactTestInstance) => (
placeholder: string | RegExp,
waitForOptions: WaitForOptions = {}
) => makeFindQuery(instance, getByPlaceholderText, placeholder, waitForOptions);
export const findAllByPlaceholderText = (instance: ReactTestInstance) => (
placeholder: string | RegExp,
waitForOptions: WaitForOptions = {}
) =>
makeFindQuery(instance, getAllByPlaceholderText, placeholder, waitForOptions);
export const findByDisplayValue = (instance: ReactTestInstance) => (
value: string | RegExp,
waitForOptions: WaitForOptions = {}
) => makeFindQuery(instance, getByDisplayValue, value, waitForOptions);
export const findAllByDisplayValue = (instance: ReactTestInstance) => (
value: string | RegExp,
waitForOptions: WaitForOptions = {}
) => makeFindQuery(instance, getAllByDisplayValue, value, waitForOptions);
export const findByAPI = (instance: ReactTestInstance) => ({
findByTestId: findByTestId(instance),
findByText: findByText(instance),
findByPlaceholderText: findByPlaceholderText(instance),
findByDisplayValue: findByDisplayValue(instance),
findAllByTestId: findAllByTestId(instance),
findAllByText: findAllByText(instance),
findAllByPlaceholderText: findAllByPlaceholderText(instance),
findAllByDisplayValue: findAllByDisplayValue(instance),
// Renamed
findByPlaceholder: () =>
throwRenamedFunctionError('findByPlaceholder', 'findByPlaceholderText'),
findAllByPlaceholder: () =>
throwRenamedFunctionError(
'findAllByPlaceholder',
'findAllByPlaceholderText'
),
});