@testing-library/react-native 9.1.0 → 10.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/build/act.d.ts +3 -0
- package/build/act.js +2 -1
- package/build/act.js.map +1 -0
- package/build/cleanup.d.ts +5 -0
- package/build/cleanup.js +3 -2
- package/build/cleanup.js.map +1 -0
- package/build/fireEvent.d.ts +8 -0
- package/build/fireEvent.js +2 -1
- package/build/fireEvent.js.map +1 -0
- package/build/flushMicroTasks.d.ts +5 -0
- package/build/flushMicroTasks.js +2 -12
- package/build/flushMicroTasks.js.map +1 -0
- package/build/helpers/debugDeep.d.ts +5 -0
- package/build/helpers/debugDeep.js +4 -1
- package/build/helpers/debugDeep.js.map +1 -0
- package/build/helpers/debugShallow.d.ts +6 -0
- package/build/helpers/debugShallow.js +4 -7
- package/build/helpers/debugShallow.js.map +1 -0
- package/build/helpers/errors.d.ts +10 -0
- package/build/helpers/errors.js +29 -9
- package/build/helpers/errors.js.map +1 -0
- package/build/helpers/filterNodeByType.d.ts +3 -0
- package/build/helpers/filterNodeByType.js +2 -1
- package/build/helpers/filterNodeByType.js.map +1 -0
- package/build/helpers/format.d.ts +3 -0
- package/build/helpers/format.js +4 -3
- package/build/helpers/format.js.map +1 -0
- package/build/helpers/timers.d.ts +6 -0
- package/build/helpers/timers.js +9 -6
- package/build/helpers/timers.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.flow.js +394 -0
- package/build/index.js +2 -1
- package/build/index.js.map +1 -0
- package/build/matches.d.ts +9 -0
- package/build/matches.js +3 -2
- package/build/matches.js.map +1 -0
- package/build/{pure.js.flow → pure.d.ts} +5 -8
- package/build/pure.js +14 -31
- package/build/pure.js.map +1 -0
- package/build/queries/a11yAPI.d.ts +66 -0
- package/build/{helpers → queries}/a11yAPI.js +16 -15
- package/build/queries/a11yAPI.js.map +1 -0
- package/build/queries/displayValue.d.ts +13 -0
- package/build/{helpers/byDisplayValue.js → queries/displayValue.js} +23 -17
- package/build/queries/displayValue.js.map +1 -0
- package/build/queries/makeA11yQuery.d.ts +13 -0
- package/build/{helpers → queries}/makeA11yQuery.js +3 -2
- package/build/queries/makeA11yQuery.js.map +1 -0
- package/build/queries/makeQueries.d.ts +19 -0
- package/build/{helpers → queries}/makeQueries.js +23 -19
- package/build/queries/makeQueries.js.map +1 -0
- package/build/queries/placeholderText.d.ts +13 -0
- package/build/{helpers/byPlaceholderText.js → queries/placeholderText.js} +23 -17
- package/build/queries/placeholderText.js.map +1 -0
- package/build/queries/testId.d.ts +13 -0
- package/build/{helpers/byTestId.js → queries/testId.js} +19 -13
- package/build/queries/testId.js.map +1 -0
- package/build/queries/text.d.ts +17 -0
- package/build/{helpers/byText.js → queries/text.js} +27 -21
- package/build/queries/text.js.map +1 -0
- package/build/queries/unsafeProps.d.ts +16 -0
- package/build/queries/unsafeProps.js +58 -0
- package/build/queries/unsafeProps.js.map +1 -0
- package/build/queries/unsafeType.d.ts +9 -0
- package/build/queries/unsafeType.js +54 -0
- package/build/queries/unsafeType.js.map +1 -0
- package/build/render.d.ts +135 -0
- package/build/render.js +16 -21
- package/build/render.js.map +1 -0
- package/build/renderHook.d.ts +17 -0
- package/build/renderHook.js +57 -0
- package/build/renderHook.js.map +1 -0
- package/build/shallow.d.ts +8 -0
- package/build/shallow.js +3 -9
- package/build/shallow.js.map +1 -0
- package/build/waitFor.d.ts +8 -0
- package/build/waitFor.js +26 -22
- package/build/waitFor.js.map +1 -0
- package/build/waitForElementToBeRemoved.d.ts +2 -0
- package/build/waitForElementToBeRemoved.js +2 -1
- package/build/waitForElementToBeRemoved.js.map +1 -0
- package/build/within.d.ts +117 -0
- package/build/within.js +19 -9
- package/build/within.js.map +1 -0
- package/package.json +24 -14
- package/typings/index.flow.js +394 -0
- package/build/act.js.flow +0 -9
- package/build/cleanup.js.flow +0 -13
- package/build/fireEvent.js.flow +0 -127
- package/build/flushMicroTasks.js.flow +0 -23
- package/build/helpers/a11yAPI.js.flow +0 -241
- package/build/helpers/byDisplayValue.js.flow +0 -66
- package/build/helpers/byPlaceholderText.js.flow +0 -62
- package/build/helpers/byTestId.js.flow +0 -50
- package/build/helpers/byText.js.flow +0 -108
- package/build/helpers/debugDeep.js.flow +0 -16
- package/build/helpers/debugShallow.js.flow +0 -20
- package/build/helpers/errors.js.flow +0 -82
- package/build/helpers/filterNodeByType.js.flow +0 -1
- package/build/helpers/findByAPI.js +0 -32
- package/build/helpers/findByAPI.js.flow +0 -76
- package/build/helpers/format.js.flow +0 -10
- package/build/helpers/getByAPI.js +0 -98
- package/build/helpers/getByAPI.js.flow +0 -157
- package/build/helpers/makeA11yQuery.js.flow +0 -98
- package/build/helpers/makeQueries.js.flow +0 -165
- package/build/helpers/queryByAPI.js +0 -92
- package/build/helpers/queryByAPI.js.flow +0 -166
- package/build/helpers/timers.js.flow +0 -88
- package/build/index.js.flow +0 -18
- package/build/matches.js.flow +0 -41
- package/build/render.js.flow +0 -109
- package/build/shallow.js.flow +0 -26
- package/build/types.flow.js +0 -1
- package/build/types.flow.js.flow +0 -59
- package/build/waitFor.js.flow +0 -226
- package/build/waitForElementToBeRemoved.js.flow +0 -42
- package/build/within.js.flow +0 -18
- package/typings/index.d.ts +0 -433
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import type { WaitForOptions } from '../waitFor';
|
|
3
|
-
import type { TextMatchOptions } from './byText';
|
|
4
|
-
import { findAllByTestId, findByTestId } from './byTestId';
|
|
5
|
-
import { findAllByText, findByText } from './byText';
|
|
6
|
-
import {
|
|
7
|
-
findAllByPlaceholderText,
|
|
8
|
-
findByPlaceholderText,
|
|
9
|
-
} from './byPlaceholderText';
|
|
10
|
-
import { findAllByDisplayValue, findByDisplayValue } from './byDisplayValue';
|
|
11
|
-
import { throwRenamedFunctionError } from './errors';
|
|
12
|
-
|
|
13
|
-
export type FindByAPI = {|
|
|
14
|
-
findAllByDisplayValue: (
|
|
15
|
-
value: string | RegExp,
|
|
16
|
-
queryOptions?: TextMatchOptions & WaitForOptions,
|
|
17
|
-
waitForOptions?: WaitForOptions
|
|
18
|
-
) => Promise<Array<ReactTestInstance>>,
|
|
19
|
-
findAllByPlaceholder: () => void,
|
|
20
|
-
findAllByPlaceholderText: (
|
|
21
|
-
placeholder: string | RegExp,
|
|
22
|
-
queryOptions?: TextMatchOptions & WaitForOptions,
|
|
23
|
-
waitForOptions?: WaitForOptions
|
|
24
|
-
) => Promise<Array<ReactTestInstance>>,
|
|
25
|
-
findAllByTestId: (
|
|
26
|
-
testId: string | RegExp,
|
|
27
|
-
queryOptions?: TextMatchOptions & WaitForOptions,
|
|
28
|
-
waitForOptions?: WaitForOptions
|
|
29
|
-
) => Promise<Array<ReactTestInstance>>,
|
|
30
|
-
findAllByText: (
|
|
31
|
-
text: string | RegExp,
|
|
32
|
-
queryOptions?: TextMatchOptions & WaitForOptions,
|
|
33
|
-
waitForOptions?: WaitForOptions
|
|
34
|
-
) => Promise<Array<ReactTestInstance>>,
|
|
35
|
-
findByDisplayValue: (
|
|
36
|
-
value: string | RegExp,
|
|
37
|
-
queryOptions?: TextMatchOptions & WaitForOptions,
|
|
38
|
-
waitForOptions?: WaitForOptions
|
|
39
|
-
) => Promise<ReactTestInstance>,
|
|
40
|
-
findByPlaceholder: () => void,
|
|
41
|
-
findByPlaceholderText: (
|
|
42
|
-
placeholder: string | RegExp,
|
|
43
|
-
queryOptions?: TextMatchOptions & WaitForOptions,
|
|
44
|
-
waitForOptions?: WaitForOptions
|
|
45
|
-
) => Promise<ReactTestInstance>,
|
|
46
|
-
findByTestId: (
|
|
47
|
-
testId: string | RegExp,
|
|
48
|
-
queryOptions?: TextMatchOptions & WaitForOptions,
|
|
49
|
-
waitForOptions?: WaitForOptions
|
|
50
|
-
) => Promise<ReactTestInstance>,
|
|
51
|
-
findByText: (
|
|
52
|
-
text: string | RegExp,
|
|
53
|
-
queryOptions?: TextMatchOptions & WaitForOptions,
|
|
54
|
-
waitForOptions?: WaitForOptions
|
|
55
|
-
) => Promise<ReactTestInstance>,
|
|
56
|
-
|};
|
|
57
|
-
|
|
58
|
-
export const findByAPI = (instance: ReactTestInstance): FindByAPI => ({
|
|
59
|
-
findByTestId: findByTestId(instance),
|
|
60
|
-
findByText: findByText(instance),
|
|
61
|
-
findByPlaceholderText: findByPlaceholderText(instance),
|
|
62
|
-
findByDisplayValue: findByDisplayValue(instance),
|
|
63
|
-
findAllByTestId: findAllByTestId(instance),
|
|
64
|
-
findAllByText: findAllByText(instance),
|
|
65
|
-
findAllByPlaceholderText: findAllByPlaceholderText(instance),
|
|
66
|
-
findAllByDisplayValue: findAllByDisplayValue(instance),
|
|
67
|
-
|
|
68
|
-
// Renamed
|
|
69
|
-
findByPlaceholder: () =>
|
|
70
|
-
throwRenamedFunctionError('findByPlaceholder', 'findByPlaceholderText'),
|
|
71
|
-
findAllByPlaceholder: () =>
|
|
72
|
-
throwRenamedFunctionError(
|
|
73
|
-
'findAllByPlaceholder',
|
|
74
|
-
'findAllByPlaceholderText'
|
|
75
|
-
),
|
|
76
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import prettyFormat, { plugins } from 'pretty-format';
|
|
3
|
-
|
|
4
|
-
const format = (input: ?ReactTestRendererJSON): typeof prettyFormat =>
|
|
5
|
-
prettyFormat(input, {
|
|
6
|
-
plugins: [plugins.ReactTestComponent, plugins.ReactElement],
|
|
7
|
-
highlight: true,
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
export default format;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getByAPI = exports.UNSAFE_getAllByProps = exports.UNSAFE_getAllByType = exports.UNSAFE_getByProps = exports.UNSAFE_getByType = void 0;
|
|
7
|
-
|
|
8
|
-
var React = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
|
-
var _prettyFormat = _interopRequireDefault(require("pretty-format"));
|
|
11
|
-
|
|
12
|
-
var _errors = require("./errors");
|
|
13
|
-
|
|
14
|
-
var _byTestId = require("./byTestId");
|
|
15
|
-
|
|
16
|
-
var _byText = require("./byText");
|
|
17
|
-
|
|
18
|
-
var _byPlaceholderText = require("./byPlaceholderText");
|
|
19
|
-
|
|
20
|
-
var _byDisplayValue = require("./byDisplayValue");
|
|
21
|
-
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
25
|
-
|
|
26
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
27
|
-
|
|
28
|
-
const UNSAFE_getByType = instance => function getByTypeFn(type) {
|
|
29
|
-
try {
|
|
30
|
-
return instance.findByType(type);
|
|
31
|
-
} catch (error) {
|
|
32
|
-
throw new _errors.ErrorWithStack((0, _errors.prepareErrorMessage)(error), getByTypeFn);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
exports.UNSAFE_getByType = UNSAFE_getByType;
|
|
37
|
-
|
|
38
|
-
const UNSAFE_getByProps = instance => function getByPropsFn(props) {
|
|
39
|
-
try {
|
|
40
|
-
return instance.findByProps(props);
|
|
41
|
-
} catch (error) {
|
|
42
|
-
throw new _errors.ErrorWithStack((0, _errors.prepareErrorMessage)(error), getByPropsFn);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
exports.UNSAFE_getByProps = UNSAFE_getByProps;
|
|
47
|
-
|
|
48
|
-
const UNSAFE_getAllByType = instance => function getAllByTypeFn(type) {
|
|
49
|
-
const results = instance.findAllByType(type);
|
|
50
|
-
|
|
51
|
-
if (results.length === 0) {
|
|
52
|
-
throw new _errors.ErrorWithStack('No instances found', getAllByTypeFn);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return results;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
exports.UNSAFE_getAllByType = UNSAFE_getAllByType;
|
|
59
|
-
|
|
60
|
-
const UNSAFE_getAllByProps = instance => function getAllByPropsFn(props) {
|
|
61
|
-
const results = instance.findAllByProps(props);
|
|
62
|
-
|
|
63
|
-
if (results.length === 0) {
|
|
64
|
-
throw new _errors.ErrorWithStack(`No instances found with props:\n${(0, _prettyFormat.default)(props)}`, getAllByPropsFn);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return results;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
exports.UNSAFE_getAllByProps = UNSAFE_getAllByProps;
|
|
71
|
-
|
|
72
|
-
const getByAPI = instance => ({
|
|
73
|
-
getByText: (0, _byText.getByText)(instance),
|
|
74
|
-
getByPlaceholderText: (0, _byPlaceholderText.getByPlaceholderText)(instance),
|
|
75
|
-
getByDisplayValue: (0, _byDisplayValue.getByDisplayValue)(instance),
|
|
76
|
-
getByTestId: (0, _byTestId.getByTestId)(instance),
|
|
77
|
-
getAllByText: (0, _byText.getAllByText)(instance),
|
|
78
|
-
getAllByPlaceholderText: (0, _byPlaceholderText.getAllByPlaceholderText)(instance),
|
|
79
|
-
getAllByDisplayValue: (0, _byDisplayValue.getAllByDisplayValue)(instance),
|
|
80
|
-
getAllByTestId: (0, _byTestId.getAllByTestId)(instance),
|
|
81
|
-
// Unsafe
|
|
82
|
-
UNSAFE_getByType: UNSAFE_getByType(instance),
|
|
83
|
-
UNSAFE_getAllByType: UNSAFE_getAllByType(instance),
|
|
84
|
-
UNSAFE_getByProps: UNSAFE_getByProps(instance),
|
|
85
|
-
UNSAFE_getAllByProps: UNSAFE_getAllByProps(instance),
|
|
86
|
-
// Removed
|
|
87
|
-
getByName: () => (0, _errors.throwRemovedFunctionError)('getByName', 'migration-v2#removed-functions'),
|
|
88
|
-
getAllByName: () => (0, _errors.throwRemovedFunctionError)('getAllByName', 'migration-v2#removed-functions'),
|
|
89
|
-
getByType: () => (0, _errors.throwRemovedFunctionError)('getByType', 'migration-v2#removed-functions'),
|
|
90
|
-
getAllByType: () => (0, _errors.throwRemovedFunctionError)('getAllByType', 'migration-v2#removed-functions'),
|
|
91
|
-
getByProps: () => (0, _errors.throwRemovedFunctionError)('getByProps', 'migration-v2#removed-functions'),
|
|
92
|
-
getAllByProps: () => (0, _errors.throwRemovedFunctionError)('getAllByProps', 'migration-v2#removed-functions'),
|
|
93
|
-
// Renamed
|
|
94
|
-
getByPlaceholder: () => (0, _errors.throwRenamedFunctionError)('getByPlaceholder', 'getByPlaceholderText'),
|
|
95
|
-
getAllByPlaceholder: () => (0, _errors.throwRenamedFunctionError)('getAllByPlaceholder', 'getByPlaceholderText')
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
exports.getByAPI = getByAPI;
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import prettyFormat from 'pretty-format';
|
|
4
|
-
import {
|
|
5
|
-
ErrorWithStack,
|
|
6
|
-
prepareErrorMessage,
|
|
7
|
-
throwRemovedFunctionError,
|
|
8
|
-
throwRenamedFunctionError,
|
|
9
|
-
} from './errors';
|
|
10
|
-
import { getAllByTestId, getByTestId } from './byTestId';
|
|
11
|
-
import { getAllByText, getByText } from './byText';
|
|
12
|
-
import {
|
|
13
|
-
getAllByPlaceholderText,
|
|
14
|
-
getByPlaceholderText,
|
|
15
|
-
} from './byPlaceholderText';
|
|
16
|
-
import { getAllByDisplayValue, getByDisplayValue } from './byDisplayValue';
|
|
17
|
-
import type { TextMatchOptions } from './byText';
|
|
18
|
-
|
|
19
|
-
export type GetByAPI = {|
|
|
20
|
-
getByText: (
|
|
21
|
-
text: string | RegExp,
|
|
22
|
-
queryOptions?: TextMatchOptions
|
|
23
|
-
) => ReactTestInstance,
|
|
24
|
-
getByPlaceholderText: (
|
|
25
|
-
placeholder: string | RegExp,
|
|
26
|
-
queryOptions?: TextMatchOptions
|
|
27
|
-
) => ReactTestInstance,
|
|
28
|
-
getByDisplayValue: (
|
|
29
|
-
value: string | RegExp,
|
|
30
|
-
queryOptions?: TextMatchOptions
|
|
31
|
-
) => ReactTestInstance,
|
|
32
|
-
getByTestId: (
|
|
33
|
-
testID: string | RegExp,
|
|
34
|
-
queryOptions?: TextMatchOptions
|
|
35
|
-
) => ReactTestInstance,
|
|
36
|
-
getAllByTestId: (
|
|
37
|
-
testID: string | RegExp,
|
|
38
|
-
queryOptions?: TextMatchOptions
|
|
39
|
-
) => Array<ReactTestInstance>,
|
|
40
|
-
getAllByText: (
|
|
41
|
-
text: string | RegExp,
|
|
42
|
-
queryOptions?: TextMatchOptions
|
|
43
|
-
) => Array<ReactTestInstance>,
|
|
44
|
-
getAllByPlaceholderText: (
|
|
45
|
-
placeholder: string | RegExp,
|
|
46
|
-
queryOptions?: TextMatchOptions
|
|
47
|
-
) => Array<ReactTestInstance>,
|
|
48
|
-
getAllByDisplayValue: (
|
|
49
|
-
value: string | RegExp,
|
|
50
|
-
queryOptions?: TextMatchOptions
|
|
51
|
-
) => Array<ReactTestInstance>,
|
|
52
|
-
|
|
53
|
-
// Unsafe aliases
|
|
54
|
-
UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance,
|
|
55
|
-
UNSAFE_getAllByType: <P>(
|
|
56
|
-
type: React.ComponentType<P>
|
|
57
|
-
) => Array<ReactTestInstance>,
|
|
58
|
-
UNSAFE_getByProps: (props: { [string]: any }) => ReactTestInstance,
|
|
59
|
-
UNSAFE_getAllByProps: (props: { [string]: any }) => Array<ReactTestInstance>,
|
|
60
|
-
|
|
61
|
-
getByName: () => void,
|
|
62
|
-
getByType: () => void,
|
|
63
|
-
getByProps: () => void,
|
|
64
|
-
getAllByName: () => void,
|
|
65
|
-
getAllByType: () => void,
|
|
66
|
-
getAllByProps: () => void,
|
|
67
|
-
|
|
68
|
-
getByPlaceholder: () => void,
|
|
69
|
-
getAllByPlaceholder: () => void,
|
|
70
|
-
|};
|
|
71
|
-
|
|
72
|
-
export const UNSAFE_getByType = (
|
|
73
|
-
instance: ReactTestInstance
|
|
74
|
-
): ((type: React.ComponentType<any>) => ReactTestInstance) =>
|
|
75
|
-
function getByTypeFn(type: React.ComponentType<any>) {
|
|
76
|
-
try {
|
|
77
|
-
return instance.findByType(type);
|
|
78
|
-
} catch (error) {
|
|
79
|
-
throw new ErrorWithStack(prepareErrorMessage(error), getByTypeFn);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export const UNSAFE_getByProps = (
|
|
84
|
-
instance: ReactTestInstance
|
|
85
|
-
): ((props: { [propName: string]: any }) => ReactTestInstance) =>
|
|
86
|
-
function getByPropsFn(props: { [propName: string]: any }) {
|
|
87
|
-
try {
|
|
88
|
-
return instance.findByProps(props);
|
|
89
|
-
} catch (error) {
|
|
90
|
-
throw new ErrorWithStack(prepareErrorMessage(error), getByPropsFn);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export const UNSAFE_getAllByType = (
|
|
95
|
-
instance: ReactTestInstance
|
|
96
|
-
): ((type: React.ComponentType<any>) => Array<ReactTestInstance>) =>
|
|
97
|
-
function getAllByTypeFn(type: React.ComponentType<any>) {
|
|
98
|
-
const results = instance.findAllByType(type);
|
|
99
|
-
if (results.length === 0) {
|
|
100
|
-
throw new ErrorWithStack('No instances found', getAllByTypeFn);
|
|
101
|
-
}
|
|
102
|
-
return results;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export const UNSAFE_getAllByProps = (
|
|
106
|
-
instance: ReactTestInstance
|
|
107
|
-
): ((props: { [propName: string]: any }) => Array<ReactTestInstance>) =>
|
|
108
|
-
function getAllByPropsFn(props: { [propName: string]: any }) {
|
|
109
|
-
const results = instance.findAllByProps(props);
|
|
110
|
-
if (results.length === 0) {
|
|
111
|
-
throw new ErrorWithStack(
|
|
112
|
-
`No instances found with props:\n${prettyFormat(props)}`,
|
|
113
|
-
getAllByPropsFn
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
return results;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export const getByAPI = (instance: ReactTestInstance): GetByAPI => ({
|
|
120
|
-
getByText: getByText(instance),
|
|
121
|
-
getByPlaceholderText: getByPlaceholderText(instance),
|
|
122
|
-
getByDisplayValue: getByDisplayValue(instance),
|
|
123
|
-
getByTestId: getByTestId(instance),
|
|
124
|
-
getAllByText: getAllByText(instance),
|
|
125
|
-
getAllByPlaceholderText: getAllByPlaceholderText(instance),
|
|
126
|
-
getAllByDisplayValue: getAllByDisplayValue(instance),
|
|
127
|
-
getAllByTestId: getAllByTestId(instance),
|
|
128
|
-
|
|
129
|
-
// Unsafe
|
|
130
|
-
UNSAFE_getByType: UNSAFE_getByType(instance),
|
|
131
|
-
UNSAFE_getAllByType: UNSAFE_getAllByType(instance),
|
|
132
|
-
UNSAFE_getByProps: UNSAFE_getByProps(instance),
|
|
133
|
-
UNSAFE_getAllByProps: UNSAFE_getAllByProps(instance),
|
|
134
|
-
|
|
135
|
-
// Removed
|
|
136
|
-
getByName: () =>
|
|
137
|
-
throwRemovedFunctionError('getByName', 'migration-v2#removed-functions'),
|
|
138
|
-
getAllByName: () =>
|
|
139
|
-
throwRemovedFunctionError('getAllByName', 'migration-v2#removed-functions'),
|
|
140
|
-
getByType: () =>
|
|
141
|
-
throwRemovedFunctionError('getByType', 'migration-v2#removed-functions'),
|
|
142
|
-
getAllByType: () =>
|
|
143
|
-
throwRemovedFunctionError('getAllByType', 'migration-v2#removed-functions'),
|
|
144
|
-
getByProps: () =>
|
|
145
|
-
throwRemovedFunctionError('getByProps', 'migration-v2#removed-functions'),
|
|
146
|
-
getAllByProps: () =>
|
|
147
|
-
throwRemovedFunctionError(
|
|
148
|
-
'getAllByProps',
|
|
149
|
-
'migration-v2#removed-functions'
|
|
150
|
-
),
|
|
151
|
-
|
|
152
|
-
// Renamed
|
|
153
|
-
getByPlaceholder: () =>
|
|
154
|
-
throwRenamedFunctionError('getByPlaceholder', 'getByPlaceholderText'),
|
|
155
|
-
getAllByPlaceholder: () =>
|
|
156
|
-
throwRenamedFunctionError('getAllByPlaceholder', 'getByPlaceholderText'),
|
|
157
|
-
});
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import waitFor from '../waitFor';
|
|
3
|
-
import type { WaitForOptions } from '../waitFor';
|
|
4
|
-
import {
|
|
5
|
-
ErrorWithStack,
|
|
6
|
-
prepareErrorMessage,
|
|
7
|
-
createQueryByError,
|
|
8
|
-
} from './errors';
|
|
9
|
-
|
|
10
|
-
function isNodeValid(node: ReactTestInstance) {
|
|
11
|
-
return typeof node.type === 'string';
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function makeAliases(aliases: Array<string>, query: Function) {
|
|
15
|
-
return aliases
|
|
16
|
-
.map((alias) => ({ [alias]: query }))
|
|
17
|
-
.reduce((acc, query) => ({ ...acc, ...query }), {});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type QueryNames = {
|
|
21
|
-
getBy: Array<string>,
|
|
22
|
-
getAllBy: Array<string>,
|
|
23
|
-
queryBy: Array<string>,
|
|
24
|
-
queryAllBy: Array<string>,
|
|
25
|
-
findBy: Array<string>,
|
|
26
|
-
findAllBy: Array<string>,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const makeA11yQuery = <P: mixed, M: mixed>(
|
|
30
|
-
name: string,
|
|
31
|
-
queryNames: QueryNames,
|
|
32
|
-
matcherFn: (prop: P, value: M) => boolean
|
|
33
|
-
): ((instance: ReactTestInstance) => { ... }) => (
|
|
34
|
-
instance: ReactTestInstance
|
|
35
|
-
) => {
|
|
36
|
-
const getBy = (matcher: M) => {
|
|
37
|
-
try {
|
|
38
|
-
return instance.find(
|
|
39
|
-
(node) => isNodeValid(node) && matcherFn(node.props[name], matcher)
|
|
40
|
-
);
|
|
41
|
-
} catch (error) {
|
|
42
|
-
throw new ErrorWithStack(
|
|
43
|
-
prepareErrorMessage(error, name, matcher),
|
|
44
|
-
getBy
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const getAllBy = (matcher: M) => {
|
|
50
|
-
const results = instance.findAll(
|
|
51
|
-
(node) => isNodeValid(node) && matcherFn(node.props[name], matcher)
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
if (results.length === 0) {
|
|
55
|
-
throw new ErrorWithStack(
|
|
56
|
-
prepareErrorMessage(new Error('No instances found'), name, matcher),
|
|
57
|
-
getAllBy
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return results;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const queryBy = (matcher: M) => {
|
|
65
|
-
try {
|
|
66
|
-
return getBy(matcher);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
return createQueryByError(error, queryBy);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const queryAllBy = (matcher: M) => {
|
|
73
|
-
try {
|
|
74
|
-
return getAllBy(matcher);
|
|
75
|
-
} catch (error) {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const findBy = (matcher: M, waitForOptions?: WaitForOptions) => {
|
|
81
|
-
return waitFor(() => getBy(matcher), waitForOptions);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const findAllBy = (matcher: M, waitForOptions?: WaitForOptions) => {
|
|
85
|
-
return waitFor(() => getAllBy(matcher), waitForOptions);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
...makeAliases(queryNames.getBy, getBy),
|
|
90
|
-
...makeAliases(queryNames.getAllBy, getAllBy),
|
|
91
|
-
...makeAliases(queryNames.queryBy, queryBy),
|
|
92
|
-
...makeAliases(queryNames.queryAllBy, queryAllBy),
|
|
93
|
-
...makeAliases(queryNames.findBy, findBy),
|
|
94
|
-
...makeAliases(queryNames.findAllBy, findAllBy),
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export default makeA11yQuery;
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import waitFor from '../waitFor';
|
|
3
|
-
import type { WaitForOptions } from '../waitFor';
|
|
4
|
-
import { ErrorWithStack } from './errors';
|
|
5
|
-
import type { TextMatchOptions } from './byText';
|
|
6
|
-
|
|
7
|
-
type QueryFunction<ArgType, ReturnType> = (
|
|
8
|
-
instance: ReactTestInstance
|
|
9
|
-
) => (args: ArgType, queryOptions?: TextMatchOptions) => ReturnType;
|
|
10
|
-
|
|
11
|
-
type FindQueryFunction<ArgType, ReturnType> = (
|
|
12
|
-
instance: ReactTestInstance
|
|
13
|
-
) => (
|
|
14
|
-
args: ArgType,
|
|
15
|
-
queryOptions?: TextMatchOptions & WaitForOptions,
|
|
16
|
-
waitForOptions?: WaitForOptions
|
|
17
|
-
) => Promise<ReturnType>;
|
|
18
|
-
|
|
19
|
-
type QueryAllByQuery<QueryArg> = QueryFunction<
|
|
20
|
-
QueryArg,
|
|
21
|
-
Array<ReactTestInstance>
|
|
22
|
-
>;
|
|
23
|
-
type QueryByQuery<QueryArg> = QueryFunction<QueryArg, null | ReactTestInstance>;
|
|
24
|
-
|
|
25
|
-
type GetAllByQuery<QueryArg> = QueryFunction<
|
|
26
|
-
QueryArg,
|
|
27
|
-
Array<ReactTestInstance>
|
|
28
|
-
>;
|
|
29
|
-
type GetByQuery<QueryArg> = QueryFunction<QueryArg, ReactTestInstance>;
|
|
30
|
-
|
|
31
|
-
type FindAllByQuery<QueryArg> = FindQueryFunction<
|
|
32
|
-
QueryArg,
|
|
33
|
-
Array<ReactTestInstance>
|
|
34
|
-
>;
|
|
35
|
-
type FindByQuery<QueryArg> = FindQueryFunction<QueryArg, ReactTestInstance>;
|
|
36
|
-
|
|
37
|
-
export type Queries<QueryArg> = {
|
|
38
|
-
getBy: GetByQuery<QueryArg>,
|
|
39
|
-
getAllBy: GetAllByQuery<QueryArg>,
|
|
40
|
-
queryBy: QueryByQuery<QueryArg>,
|
|
41
|
-
findBy: FindByQuery<QueryArg>,
|
|
42
|
-
findAllBy: FindAllByQuery<QueryArg>,
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// The WaitForOptions has been moved to the second option param of findBy* methods with the adding of TextMatchOptions
|
|
46
|
-
// To make the migration easier and avoid a breaking change, keep reading this options from the first param but warn
|
|
47
|
-
const deprecatedKeys: $Keys<WaitForOptions>[] = [
|
|
48
|
-
'timeout',
|
|
49
|
-
'interval',
|
|
50
|
-
'stackTraceError',
|
|
51
|
-
];
|
|
52
|
-
const extractDeprecatedWaitForOptionUsage = (queryOptions?: WaitForOptions) => {
|
|
53
|
-
if (queryOptions) {
|
|
54
|
-
const waitForOptions: WaitForOptions = {
|
|
55
|
-
timeout: queryOptions.timeout,
|
|
56
|
-
interval: queryOptions.interval,
|
|
57
|
-
stackTraceError: queryOptions.stackTraceError,
|
|
58
|
-
};
|
|
59
|
-
deprecatedKeys.forEach((key) => {
|
|
60
|
-
if (queryOptions[key]) {
|
|
61
|
-
// eslint-disable-next-line no-console
|
|
62
|
-
console.warn(
|
|
63
|
-
`Use of option "${key}" in a findBy* query's second parameter, TextMatchOptions, is deprecated. Please pass this option in the third, WaitForOptions, parameter.
|
|
64
|
-
Example:
|
|
65
|
-
|
|
66
|
-
findByText(text, {}, { ${key}: ${queryOptions[key].toString()} })`
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
return waitForOptions;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export function makeQueries<QueryArg>(
|
|
75
|
-
queryAllByQuery: QueryAllByQuery<QueryArg>,
|
|
76
|
-
getMissingError: (args: QueryArg) => string,
|
|
77
|
-
getMultipleError: (args: QueryArg) => string
|
|
78
|
-
): Queries<QueryArg> {
|
|
79
|
-
function getAllByQuery(instance: ReactTestInstance) {
|
|
80
|
-
return function getAllFn(args: QueryArg, queryOptions?: TextMatchOptions) {
|
|
81
|
-
const results = queryAllByQuery(instance)(args, queryOptions);
|
|
82
|
-
|
|
83
|
-
if (results.length === 0) {
|
|
84
|
-
throw new ErrorWithStack(getMissingError(args), getAllFn);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return results;
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function queryByQuery(instance: ReactTestInstance) {
|
|
92
|
-
return function singleQueryFn(
|
|
93
|
-
args: QueryArg,
|
|
94
|
-
queryOptions?: TextMatchOptions
|
|
95
|
-
) {
|
|
96
|
-
const results = queryAllByQuery(instance)(args, queryOptions);
|
|
97
|
-
|
|
98
|
-
if (results.length > 1) {
|
|
99
|
-
throw new ErrorWithStack(getMultipleError(args), singleQueryFn);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (results.length === 0) {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return results[0];
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function getByQuery(instance: ReactTestInstance) {
|
|
111
|
-
return function getFn(args: QueryArg, queryOptions?: TextMatchOptions) {
|
|
112
|
-
const results = queryAllByQuery(instance)(args, queryOptions);
|
|
113
|
-
|
|
114
|
-
if (results.length > 1) {
|
|
115
|
-
throw new ErrorWithStack(getMultipleError(args), getFn);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (results.length === 0) {
|
|
119
|
-
throw new ErrorWithStack(getMissingError(args), getFn);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return results[0];
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function findAllByQuery(instance: ReactTestInstance) {
|
|
127
|
-
return function findAllFn(
|
|
128
|
-
args: QueryArg,
|
|
129
|
-
queryOptions?: TextMatchOptions & WaitForOptions,
|
|
130
|
-
waitForOptions?: WaitForOptions = {}
|
|
131
|
-
) {
|
|
132
|
-
const deprecatedWaitForOptions = extractDeprecatedWaitForOptionUsage(
|
|
133
|
-
queryOptions
|
|
134
|
-
);
|
|
135
|
-
return waitFor(() => getAllByQuery(instance)(args, queryOptions), {
|
|
136
|
-
...deprecatedWaitForOptions,
|
|
137
|
-
...waitForOptions,
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function findByQuery(instance: ReactTestInstance) {
|
|
143
|
-
return function findFn(
|
|
144
|
-
args: QueryArg,
|
|
145
|
-
queryOptions?: TextMatchOptions & WaitForOptions,
|
|
146
|
-
waitForOptions?: WaitForOptions = {}
|
|
147
|
-
) {
|
|
148
|
-
const deprecatedWaitForOptions = extractDeprecatedWaitForOptionUsage(
|
|
149
|
-
queryOptions
|
|
150
|
-
);
|
|
151
|
-
return waitFor(() => getByQuery(instance)(args, queryOptions), {
|
|
152
|
-
...deprecatedWaitForOptions,
|
|
153
|
-
...waitForOptions,
|
|
154
|
-
});
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return {
|
|
159
|
-
getBy: getByQuery,
|
|
160
|
-
getAllBy: getAllByQuery,
|
|
161
|
-
queryBy: queryByQuery,
|
|
162
|
-
findBy: findByQuery,
|
|
163
|
-
findAllBy: findAllByQuery,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.queryByAPI = exports.UNSAFE_queryAllByProps = exports.UNSAFE_queryAllByType = exports.UNSAFE_queryByProps = exports.UNSAFE_queryByType = void 0;
|
|
7
|
-
|
|
8
|
-
var React = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
|
-
var _getByAPI = require("./getByAPI");
|
|
11
|
-
|
|
12
|
-
var _byTestId = require("./byTestId");
|
|
13
|
-
|
|
14
|
-
var _byText = require("./byText");
|
|
15
|
-
|
|
16
|
-
var _byPlaceholderText = require("./byPlaceholderText");
|
|
17
|
-
|
|
18
|
-
var _byDisplayValue = require("./byDisplayValue");
|
|
19
|
-
|
|
20
|
-
var _errors = require("./errors");
|
|
21
|
-
|
|
22
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
23
|
-
|
|
24
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
-
|
|
26
|
-
const UNSAFE_queryByType = instance => function queryByTypeFn(type) {
|
|
27
|
-
try {
|
|
28
|
-
return (0, _getByAPI.UNSAFE_getByType)(instance)(type);
|
|
29
|
-
} catch (error) {
|
|
30
|
-
return (0, _errors.createQueryByError)(error, queryByTypeFn);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
exports.UNSAFE_queryByType = UNSAFE_queryByType;
|
|
35
|
-
|
|
36
|
-
const UNSAFE_queryByProps = instance => function queryByPropsFn(props) {
|
|
37
|
-
try {
|
|
38
|
-
return (0, _getByAPI.UNSAFE_getByProps)(instance)(props);
|
|
39
|
-
} catch (error) {
|
|
40
|
-
return (0, _errors.createQueryByError)(error, queryByPropsFn);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
exports.UNSAFE_queryByProps = UNSAFE_queryByProps;
|
|
45
|
-
|
|
46
|
-
const UNSAFE_queryAllByType = instance => type => {
|
|
47
|
-
try {
|
|
48
|
-
return (0, _getByAPI.UNSAFE_getAllByType)(instance)(type);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
return [];
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
exports.UNSAFE_queryAllByType = UNSAFE_queryAllByType;
|
|
55
|
-
|
|
56
|
-
const UNSAFE_queryAllByProps = instance => props => {
|
|
57
|
-
try {
|
|
58
|
-
return (0, _getByAPI.UNSAFE_getAllByProps)(instance)(props);
|
|
59
|
-
} catch (error) {
|
|
60
|
-
return [];
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
exports.UNSAFE_queryAllByProps = UNSAFE_queryAllByProps;
|
|
65
|
-
|
|
66
|
-
const queryByAPI = instance => ({
|
|
67
|
-
queryByTestId: (0, _byTestId.queryByTestId)(instance),
|
|
68
|
-
queryByText: (0, _byText.queryByText)(instance),
|
|
69
|
-
queryByPlaceholderText: (0, _byPlaceholderText.queryByPlaceholderText)(instance),
|
|
70
|
-
queryByDisplayValue: (0, _byDisplayValue.queryByDisplayValue)(instance),
|
|
71
|
-
queryAllByTestId: (0, _byTestId.queryAllByTestId)(instance),
|
|
72
|
-
queryAllByText: (0, _byText.queryAllByText)(instance),
|
|
73
|
-
queryAllByPlaceholderText: (0, _byPlaceholderText.queryAllByPlaceholderText)(instance),
|
|
74
|
-
queryAllByDisplayValue: (0, _byDisplayValue.queryAllByDisplayValue)(instance),
|
|
75
|
-
// Unsafe
|
|
76
|
-
UNSAFE_queryByType: UNSAFE_queryByType(instance),
|
|
77
|
-
UNSAFE_queryAllByType: UNSAFE_queryAllByType(instance),
|
|
78
|
-
UNSAFE_queryByProps: UNSAFE_queryByProps(instance),
|
|
79
|
-
UNSAFE_queryAllByProps: UNSAFE_queryAllByProps(instance),
|
|
80
|
-
// Removed
|
|
81
|
-
queryByName: () => (0, _errors.throwRemovedFunctionError)('queryByName', 'migration-v2#removed-functions'),
|
|
82
|
-
queryAllByName: () => (0, _errors.throwRemovedFunctionError)('queryAllByName', 'migration-v2#removed-functions'),
|
|
83
|
-
queryByType: () => (0, _errors.throwRemovedFunctionError)('queryByType', 'migration-v2#removed-functions'),
|
|
84
|
-
queryAllByType: () => (0, _errors.throwRemovedFunctionError)('queryAllByType', 'migration-v2#removed-functions'),
|
|
85
|
-
queryByProps: () => (0, _errors.throwRemovedFunctionError)('queryByProps', 'migration-v2#removed-functions'),
|
|
86
|
-
queryAllByProps: () => (0, _errors.throwRemovedFunctionError)('queryAllByProps', 'migration-v2#removed-functions'),
|
|
87
|
-
// Renamed
|
|
88
|
-
queryByPlaceholder: () => (0, _errors.throwRenamedFunctionError)('queryByPlaceholder', 'queryByPlaceholderText'),
|
|
89
|
-
queryAllByPlaceholder: () => (0, _errors.throwRenamedFunctionError)('queryAllByPlaceholder', 'queryAllByPlaceholderText')
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
exports.queryByAPI = queryByAPI;
|