@testing-library/react-native 11.3.0 → 11.5.0
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 +5 -2
- package/build/act.js +9 -15
- package/build/act.js.map +1 -1
- package/build/cleanup.d.ts +1 -1
- package/build/cleanup.js +0 -4
- package/build/cleanup.js.map +1 -1
- package/build/config.d.ts +15 -2
- package/build/config.js +16 -8
- package/build/config.js.map +1 -1
- package/build/fireEvent.js +3 -31
- package/build/fireEvent.js.map +1 -1
- package/build/flushMicroTasks.d.ts +1 -1
- package/build/flushMicroTasks.js +0 -3
- package/build/flushMicroTasks.js.map +1 -1
- package/build/helpers/accessiblity.d.ts +10 -1
- package/build/helpers/accessiblity.js +28 -24
- package/build/helpers/accessiblity.js.map +1 -1
- package/build/helpers/component-tree.js +6 -27
- package/build/helpers/component-tree.js.map +1 -1
- package/build/helpers/debugDeep.d.ts +5 -1
- package/build/helpers/debugDeep.js +7 -6
- package/build/helpers/debugDeep.js.map +1 -1
- package/build/helpers/debugShallow.js +0 -5
- package/build/helpers/debugShallow.js.map +1 -1
- package/build/helpers/errors.js +4 -25
- package/build/helpers/errors.js.map +1 -1
- package/build/helpers/filterNodeByType.js +0 -2
- package/build/helpers/filterNodeByType.js.map +1 -1
- package/build/helpers/findAll.d.ts +10 -0
- package/build/helpers/findAll.js +44 -0
- package/build/helpers/findAll.js.map +1 -0
- package/build/helpers/format.d.ts +5 -1
- package/build/helpers/format.js +17 -7
- package/build/helpers/format.js.map +1 -1
- package/build/helpers/getTextContent.d.ts +2 -0
- package/build/helpers/getTextContent.js +20 -0
- package/build/helpers/getTextContent.js.map +1 -0
- package/build/helpers/matchers/accessibilityState.d.ts +3 -0
- package/build/helpers/matchers/accessibilityState.js +28 -0
- package/build/helpers/matchers/accessibilityState.js.map +1 -0
- package/build/helpers/matchers/accessibilityValue.d.ts +9 -0
- package/build/helpers/matchers/accessibilityValue.js +12 -0
- package/build/helpers/matchers/accessibilityValue.js.map +1 -0
- package/build/helpers/matchers/matchArrayProp.js +0 -3
- package/build/helpers/matchers/matchArrayProp.js.map +1 -1
- package/build/helpers/matchers/matchObjectProp.js +0 -2
- package/build/helpers/matchers/matchObjectProp.js.map +1 -1
- package/build/helpers/matchers/matchStringProp.js +0 -3
- package/build/helpers/matchers/matchStringProp.js.map +1 -1
- package/build/helpers/matchers/matchTextContent.d.ts +3 -0
- package/build/helpers/matchers/matchTextContent.js +22 -0
- package/build/helpers/matchers/matchTextContent.js.map +1 -0
- package/build/helpers/stringValidation.js +0 -7
- package/build/helpers/stringValidation.js.map +1 -1
- package/build/helpers/timers.js +10 -21
- package/build/helpers/timers.js.map +1 -1
- package/build/index.flow.js +169 -56
- package/build/index.js +0 -6
- package/build/index.js.map +1 -1
- package/build/matches.d.ts +7 -3
- package/build/matches.js +2 -4
- package/build/matches.js.map +1 -1
- package/build/pure.d.ts +12 -23
- package/build/pure.js +8 -15
- package/build/pure.js.map +1 -1
- package/build/queries/a11yState.d.ts +15 -14
- package/build/queries/a11yState.js +16 -13
- package/build/queries/a11yState.js.map +1 -1
- package/build/queries/a11yValue.d.ts +15 -20
- package/build/queries/a11yValue.js +16 -13
- package/build/queries/a11yValue.js.map +1 -1
- package/build/queries/displayValue.d.ts +11 -9
- package/build/queries/displayValue.js +2 -12
- package/build/queries/displayValue.js.map +1 -1
- package/build/queries/hintText.d.ts +23 -20
- package/build/queries/hintText.js +11 -11
- package/build/queries/hintText.js.map +1 -1
- package/build/queries/labelText.d.ts +11 -8
- package/build/queries/labelText.js +11 -11
- package/build/queries/labelText.js.map +1 -1
- package/build/queries/makeQueries.d.ts +9 -9
- package/build/queries/makeQueries.js +40 -24
- package/build/queries/makeQueries.js.map +1 -1
- package/build/queries/options.d.ts +11 -0
- package/build/queries/options.js +2 -0
- package/build/queries/options.js.map +1 -0
- package/build/queries/placeholderText.d.ts +11 -9
- package/build/queries/placeholderText.js +2 -12
- package/build/queries/placeholderText.js.map +1 -1
- package/build/queries/role.d.ts +7 -3
- package/build/queries/role.js +32 -13
- package/build/queries/role.js.map +1 -1
- package/build/queries/testId.d.ts +11 -9
- package/build/queries/testId.js +3 -11
- package/build/queries/testId.js.map +1 -1
- package/build/queries/text.d.ts +11 -13
- package/build/queries/text.js +6 -71
- package/build/queries/text.js.map +1 -1
- package/build/queries/unsafeProps.d.ts +1 -1
- package/build/queries/unsafeProps.js +2 -11
- package/build/queries/unsafeProps.js.map +1 -1
- package/build/queries/unsafeType.d.ts +1 -1
- package/build/queries/unsafeType.js +2 -9
- package/build/queries/unsafeType.js.map +1 -1
- package/build/react-versions.js +0 -4
- package/build/react-versions.js.map +1 -1
- package/build/render.d.ts +88 -141
- package/build/render.js +21 -31
- package/build/render.js.map +1 -1
- package/build/renderHook.d.ts +2 -2
- package/build/renderHook.js +2 -12
- package/build/renderHook.js.map +1 -1
- package/build/screen.js +0 -6
- package/build/screen.js.map +1 -1
- package/build/shallow.js +0 -6
- package/build/shallow.js.map +1 -1
- package/build/waitFor.d.ts +1 -1
- package/build/waitFor.js +29 -52
- package/build/waitFor.js.map +1 -1
- package/build/waitForElementToBeRemoved.js +2 -11
- package/build/waitForElementToBeRemoved.js.map +1 -1
- package/build/within.d.ts +84 -138
- package/build/within.js +2 -14
- package/build/within.js.map +1 -1
- package/package.json +12 -11
- package/typings/index.flow.js +169 -56
|
@@ -4,70 +4,86 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.makeQueries = makeQueries;
|
|
7
|
-
|
|
8
7
|
var _errors = require("../helpers/errors");
|
|
9
|
-
|
|
10
8
|
var _waitFor = _interopRequireDefault(require("../waitFor"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
const deprecatedKeys = ['timeout', 'interval', 'stackTraceError'];
|
|
13
11
|
|
|
12
|
+
// The WaitForOptions has been moved to the second option param of findBy* methods with the adding of TextMatchOptions
|
|
13
|
+
// To make the migration easier and avoid a breaking change, keep reading this options from the first param but warn
|
|
14
|
+
function extractDeprecatedWaitForOptions(options) {
|
|
15
|
+
if (!options) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const waitForOptions = {
|
|
19
|
+
timeout: options.timeout,
|
|
20
|
+
interval: options.interval,
|
|
21
|
+
stackTraceError: options.stackTraceError
|
|
22
|
+
};
|
|
23
|
+
deprecatedKeys.forEach(key => {
|
|
24
|
+
const option = options[key];
|
|
25
|
+
if (option) {
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
27
|
+
console.warn(`Use of option "${key}" in a findBy* query options (2nd parameter) is deprecated. Please pass this option in the waitForOptions (3rd parameter).
|
|
28
|
+
Example:
|
|
29
|
+
|
|
30
|
+
findByText(text, {}, { ${key}: ${option.toString()} })`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return waitForOptions;
|
|
34
|
+
}
|
|
14
35
|
function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
|
|
15
36
|
function getAllByQuery(instance) {
|
|
16
37
|
return function getAllFn(predicate, options) {
|
|
17
38
|
const results = queryAllByQuery(instance)(predicate, options);
|
|
18
|
-
|
|
19
39
|
if (results.length === 0) {
|
|
20
|
-
throw new _errors.ErrorWithStack(getMissingError(predicate), getAllFn);
|
|
40
|
+
throw new _errors.ErrorWithStack(getMissingError(predicate, options), getAllFn);
|
|
21
41
|
}
|
|
22
|
-
|
|
23
42
|
return results;
|
|
24
43
|
};
|
|
25
44
|
}
|
|
26
|
-
|
|
27
45
|
function queryByQuery(instance) {
|
|
28
46
|
return function singleQueryFn(predicate, options) {
|
|
29
47
|
const results = queryAllByQuery(instance)(predicate, options);
|
|
30
|
-
|
|
31
48
|
if (results.length > 1) {
|
|
32
|
-
throw new _errors.ErrorWithStack(getMultipleError(predicate), singleQueryFn);
|
|
49
|
+
throw new _errors.ErrorWithStack(getMultipleError(predicate, options), singleQueryFn);
|
|
33
50
|
}
|
|
34
|
-
|
|
35
51
|
if (results.length === 0) {
|
|
36
52
|
return null;
|
|
37
53
|
}
|
|
38
|
-
|
|
39
54
|
return results[0];
|
|
40
55
|
};
|
|
41
56
|
}
|
|
42
|
-
|
|
43
57
|
function getByQuery(instance) {
|
|
44
58
|
return function getFn(predicate, options) {
|
|
45
59
|
const results = queryAllByQuery(instance)(predicate, options);
|
|
46
|
-
|
|
47
60
|
if (results.length > 1) {
|
|
48
|
-
throw new _errors.ErrorWithStack(getMultipleError(predicate), getFn);
|
|
61
|
+
throw new _errors.ErrorWithStack(getMultipleError(predicate, options), getFn);
|
|
49
62
|
}
|
|
50
|
-
|
|
51
63
|
if (results.length === 0) {
|
|
52
|
-
throw new _errors.ErrorWithStack(getMissingError(predicate), getFn);
|
|
64
|
+
throw new _errors.ErrorWithStack(getMissingError(predicate, options), getFn);
|
|
53
65
|
}
|
|
54
|
-
|
|
55
66
|
return results[0];
|
|
56
67
|
};
|
|
57
68
|
}
|
|
58
|
-
|
|
59
69
|
function findAllByQuery(instance) {
|
|
60
|
-
return function findAllFn(predicate, queryOptions, waitForOptions) {
|
|
61
|
-
|
|
70
|
+
return function findAllFn(predicate, queryOptions, waitForOptions = {}) {
|
|
71
|
+
const deprecatedWaitForOptions = extractDeprecatedWaitForOptions(queryOptions);
|
|
72
|
+
return (0, _waitFor.default)(() => getAllByQuery(instance)(predicate, queryOptions), {
|
|
73
|
+
...deprecatedWaitForOptions,
|
|
74
|
+
...waitForOptions
|
|
75
|
+
});
|
|
62
76
|
};
|
|
63
77
|
}
|
|
64
|
-
|
|
65
78
|
function findByQuery(instance) {
|
|
66
|
-
return function findFn(predicate, queryOptions, waitForOptions) {
|
|
67
|
-
|
|
79
|
+
return function findFn(predicate, queryOptions, waitForOptions = {}) {
|
|
80
|
+
const deprecatedWaitForOptions = extractDeprecatedWaitForOptions(queryOptions);
|
|
81
|
+
return (0, _waitFor.default)(() => getByQuery(instance)(predicate, queryOptions), {
|
|
82
|
+
...deprecatedWaitForOptions,
|
|
83
|
+
...waitForOptions
|
|
84
|
+
});
|
|
68
85
|
};
|
|
69
86
|
}
|
|
70
|
-
|
|
71
87
|
return {
|
|
72
88
|
getBy: getByQuery,
|
|
73
89
|
getAllBy: getAllByQuery,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeQueries.js","names":["makeQueries","queryAllByQuery","getMissingError","getMultipleError","getAllByQuery","instance","getAllFn","predicate","
|
|
1
|
+
{"version":3,"file":"makeQueries.js","names":["deprecatedKeys","extractDeprecatedWaitForOptions","options","undefined","waitForOptions","timeout","interval","stackTraceError","forEach","key","option","console","warn","toString","makeQueries","queryAllByQuery","getMissingError","getMultipleError","getAllByQuery","instance","getAllFn","predicate","results","length","ErrorWithStack","queryByQuery","singleQueryFn","getByQuery","getFn","findAllByQuery","findAllFn","queryOptions","deprecatedWaitForOptions","waitFor","findByQuery","findFn","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy"],"sources":["../../src/queries/makeQueries.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { ErrorWithStack } from '../helpers/errors';\nimport waitFor from '../waitFor';\nimport type { WaitForOptions } from '../waitFor';\n\nexport type GetByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options\n) => ReactTestInstance;\n\nexport type GetAllByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options\n) => ReactTestInstance[];\n\nexport type QueryByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options\n) => ReactTestInstance | null;\n\nexport type QueryAllByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options\n) => ReactTestInstance[];\n\nexport type FindByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n // Remove `& WaitForOptions` when all queries have been migrated to support 2nd arg query options.\n options?: Options & WaitForOptions,\n waitForOptions?: WaitForOptions\n) => Promise<ReactTestInstance>;\n\nexport type FindAllByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n // Remove `& WaitForOptions` when all queries have been migrated to support 2nd arg query options.\n options?: Options & WaitForOptions,\n waitForOptions?: WaitForOptions\n) => Promise<ReactTestInstance[]>;\n\ntype UnboundQuery<Query> = (instance: ReactTestInstance) => Query;\n\nexport type UnboundQueries<Predicate, Options> = {\n getBy: UnboundQuery<GetByQuery<Predicate, Options>>;\n getAllBy: UnboundQuery<GetAllByQuery<Predicate, Options>>;\n queryBy: UnboundQuery<QueryByQuery<Predicate, Options>>;\n queryAllBy: UnboundQuery<QueryAllByQuery<Predicate, Options>>;\n findBy: UnboundQuery<FindByQuery<Predicate, Options>>;\n findAllBy: UnboundQuery<FindAllByQuery<Predicate, Options>>;\n};\n\nconst deprecatedKeys: (keyof WaitForOptions)[] = [\n 'timeout',\n 'interval',\n 'stackTraceError',\n];\n\n// The WaitForOptions has been moved to the second option param of findBy* methods with the adding of TextMatchOptions\n// To make the migration easier and avoid a breaking change, keep reading this options from the first param but warn\nfunction extractDeprecatedWaitForOptions(options?: WaitForOptions) {\n if (!options) {\n return undefined;\n }\n\n const waitForOptions: WaitForOptions = {\n timeout: options.timeout,\n interval: options.interval,\n stackTraceError: options.stackTraceError,\n };\n\n deprecatedKeys.forEach((key) => {\n const option = options[key];\n if (option) {\n // eslint-disable-next-line no-console\n console.warn(\n `Use of option \"${key}\" in a findBy* query options (2nd parameter) is deprecated. Please pass this option in the waitForOptions (3rd parameter). \nExample: \n\n findByText(text, {}, { ${key}: ${option.toString()} })`\n );\n }\n });\n\n return waitForOptions;\n}\n\nexport function makeQueries<Predicate, Options>(\n queryAllByQuery: UnboundQuery<QueryAllByQuery<Predicate, Options>>,\n getMissingError: (predicate: Predicate, options?: Options) => string,\n getMultipleError: (predicate: Predicate, options?: Options) => string\n): UnboundQueries<Predicate, Options> {\n function getAllByQuery(instance: ReactTestInstance) {\n return function getAllFn(predicate: Predicate, options?: Options) {\n const results = queryAllByQuery(instance)(predicate, options);\n\n if (results.length === 0) {\n throw new ErrorWithStack(getMissingError(predicate, options), getAllFn);\n }\n\n return results;\n };\n }\n\n function queryByQuery(instance: ReactTestInstance) {\n return function singleQueryFn(predicate: Predicate, options?: Options) {\n const results = queryAllByQuery(instance)(predicate, options);\n\n if (results.length > 1) {\n throw new ErrorWithStack(\n getMultipleError(predicate, options),\n singleQueryFn\n );\n }\n\n if (results.length === 0) {\n return null;\n }\n\n return results[0];\n };\n }\n\n function getByQuery(instance: ReactTestInstance) {\n return function getFn(predicate: Predicate, options?: Options) {\n const results = queryAllByQuery(instance)(predicate, options);\n\n if (results.length > 1) {\n throw new ErrorWithStack(getMultipleError(predicate, options), getFn);\n }\n\n if (results.length === 0) {\n throw new ErrorWithStack(getMissingError(predicate, options), getFn);\n }\n\n return results[0];\n };\n }\n\n function findAllByQuery(instance: ReactTestInstance) {\n return function findAllFn(\n predicate: Predicate,\n queryOptions?: Options & WaitForOptions,\n waitForOptions: WaitForOptions = {}\n ) {\n const deprecatedWaitForOptions =\n extractDeprecatedWaitForOptions(queryOptions);\n return waitFor(() => getAllByQuery(instance)(predicate, queryOptions), {\n ...deprecatedWaitForOptions,\n ...waitForOptions,\n });\n };\n }\n\n function findByQuery(instance: ReactTestInstance) {\n return function findFn(\n predicate: Predicate,\n queryOptions?: Options & WaitForOptions,\n waitForOptions: WaitForOptions = {}\n ) {\n const deprecatedWaitForOptions =\n extractDeprecatedWaitForOptions(queryOptions);\n return waitFor(() => getByQuery(instance)(predicate, queryOptions), {\n ...deprecatedWaitForOptions,\n ...waitForOptions,\n });\n };\n }\n\n return {\n getBy: getByQuery,\n getAllBy: getAllByQuery,\n queryBy: queryByQuery,\n queryAllBy: queryAllByQuery,\n findBy: findByQuery,\n findAllBy: findAllByQuery,\n };\n}\n"],"mappings":";;;;;;AACA;AACA;AAAiC;AAgDjC,MAAMA,cAAwC,GAAG,CAC/C,SAAS,EACT,UAAU,EACV,iBAAiB,CAClB;;AAED;AACA;AACA,SAASC,+BAA+B,CAACC,OAAwB,EAAE;EACjE,IAAI,CAACA,OAAO,EAAE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AAC;MAC/C,OAAO,IAAAE,gBAAO,EAAC,MAAMN,UAAU,CAACR,QAAQ,CAAC,CAACE,SAAS,EAAEU,YAAY,CAAC,EAAE;QAClE,GAAGC,wBAAwB;QAC3B,GAAG5B;MACL,CAAC,CAAC;IACJ,CAAC;EACH;EAEA,OAAO;IACLgC,KAAK,EAAET,UAAU;IACjBU,QAAQ,EAAEnB,aAAa;IACvBoB,OAAO,EAAEb,YAAY;IACrBc,UAAU,EAAExB,eAAe;IAC3ByB,MAAM,EAAEN,WAAW;IACnBO,SAAS,EAAEZ;EACb,CAAC;AACH"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NormalizerFn } from '../matches';
|
|
2
|
+
export type CommonQueryOptions = {
|
|
3
|
+
/** Should query include elements hidden from accessibility. */
|
|
4
|
+
includeHiddenElements?: boolean;
|
|
5
|
+
/** RTL-compatibile alias to `includeHiddenElements`. */
|
|
6
|
+
hidden?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type TextMatchOptions = {
|
|
9
|
+
exact?: boolean;
|
|
10
|
+
normalizer?: NormalizerFn;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","names":[],"sources":["../../src/queries/options.ts"],"sourcesContent":["import { NormalizerFn } from '../matches';\n\nexport type CommonQueryOptions = {\n /** Should query include elements hidden from accessibility. */\n includeHiddenElements?: boolean;\n\n /** RTL-compatibile alias to `includeHiddenElements`. */\n hidden?: boolean;\n};\n\nexport type TextMatchOptions = {\n exact?: boolean;\n normalizer?: NormalizerFn;\n};\n"],"mappings":""}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
-
import { TextMatch } from '../matches';
|
|
2
|
+
import { TextMatch, TextMatchOptions } from '../matches';
|
|
3
3
|
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './makeQueries';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
import type { CommonQueryOptions } from './options';
|
|
5
|
+
type ByPlaceholderTextOptions = CommonQueryOptions & TextMatchOptions;
|
|
6
|
+
export type ByPlaceholderTextQueries = {
|
|
7
|
+
getByPlaceholderText: GetByQuery<TextMatch, ByPlaceholderTextOptions>;
|
|
8
|
+
getAllByPlaceholderText: GetAllByQuery<TextMatch, ByPlaceholderTextOptions>;
|
|
9
|
+
queryByPlaceholderText: QueryByQuery<TextMatch, ByPlaceholderTextOptions>;
|
|
10
|
+
queryAllByPlaceholderText: QueryAllByQuery<TextMatch, ByPlaceholderTextOptions>;
|
|
11
|
+
findByPlaceholderText: FindByQuery<TextMatch, ByPlaceholderTextOptions>;
|
|
12
|
+
findAllByPlaceholderText: FindAllByQuery<TextMatch, ByPlaceholderTextOptions>;
|
|
12
13
|
};
|
|
13
14
|
export declare const bindByPlaceholderTextQueries: (instance: ReactTestInstance) => ByPlaceholderTextQueries;
|
|
15
|
+
export {};
|
|
@@ -4,15 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.bindByPlaceholderTextQueries = void 0;
|
|
7
|
-
|
|
8
7
|
var _reactNative = require("react-native");
|
|
9
|
-
|
|
8
|
+
var _findAll = require("../helpers/findAll");
|
|
10
9
|
var _filterNodeByType = require("../helpers/filterNodeByType");
|
|
11
|
-
|
|
12
10
|
var _matches = require("../matches");
|
|
13
|
-
|
|
14
11
|
var _makeQueries = require("./makeQueries");
|
|
15
|
-
|
|
16
12
|
const getTextInputNodeByPlaceholderText = (node, placeholder, options = {}) => {
|
|
17
13
|
const {
|
|
18
14
|
exact,
|
|
@@ -20,15 +16,11 @@ const getTextInputNodeByPlaceholderText = (node, placeholder, options = {}) => {
|
|
|
20
16
|
} = options;
|
|
21
17
|
return (0, _filterNodeByType.filterNodeByType)(node, _reactNative.TextInput) && (0, _matches.matches)(placeholder, node.props.placeholder, normalizer, exact);
|
|
22
18
|
};
|
|
23
|
-
|
|
24
19
|
const queryAllByPlaceholderText = instance => function queryAllByPlaceholderFn(placeholder, queryOptions) {
|
|
25
|
-
return
|
|
20
|
+
return (0, _findAll.findAll)(instance, node => getTextInputNodeByPlaceholderText(node, placeholder, queryOptions), queryOptions);
|
|
26
21
|
};
|
|
27
|
-
|
|
28
22
|
const getMultipleError = placeholder => `Found multiple elements with placeholder: ${String(placeholder)} `;
|
|
29
|
-
|
|
30
23
|
const getMissingError = placeholder => `Unable to find an element with placeholder: ${String(placeholder)}`;
|
|
31
|
-
|
|
32
24
|
const {
|
|
33
25
|
getBy,
|
|
34
26
|
getAllBy,
|
|
@@ -37,7 +29,6 @@ const {
|
|
|
37
29
|
findBy,
|
|
38
30
|
findAllBy
|
|
39
31
|
} = (0, _makeQueries.makeQueries)(queryAllByPlaceholderText, getMissingError, getMultipleError);
|
|
40
|
-
|
|
41
32
|
const bindByPlaceholderTextQueries = instance => ({
|
|
42
33
|
getByPlaceholderText: getBy(instance),
|
|
43
34
|
getAllByPlaceholderText: getAllBy(instance),
|
|
@@ -46,6 +37,5 @@ const bindByPlaceholderTextQueries = instance => ({
|
|
|
46
37
|
findByPlaceholderText: findBy(instance),
|
|
47
38
|
findAllByPlaceholderText: findAllBy(instance)
|
|
48
39
|
});
|
|
49
|
-
|
|
50
40
|
exports.bindByPlaceholderTextQueries = bindByPlaceholderTextQueries;
|
|
51
41
|
//# sourceMappingURL=placeholderText.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"placeholderText.js","names":["getTextInputNodeByPlaceholderText","node","placeholder","options","exact","normalizer","filterNodeByType","TextInput","matches","props","queryAllByPlaceholderText","instance","queryAllByPlaceholderFn","queryOptions","findAll","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByPlaceholderTextQueries","getByPlaceholderText","getAllByPlaceholderText","queryByPlaceholderText","findByPlaceholderText","findAllByPlaceholderText"],"sources":["../../src/queries/placeholderText.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { TextInput } from 'react-native';\nimport { filterNodeByType } from '../helpers/filterNodeByType';\nimport { matches, TextMatch } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport type {
|
|
1
|
+
{"version":3,"file":"placeholderText.js","names":["getTextInputNodeByPlaceholderText","node","placeholder","options","exact","normalizer","filterNodeByType","TextInput","matches","props","queryAllByPlaceholderText","instance","queryAllByPlaceholderFn","queryOptions","findAll","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByPlaceholderTextQueries","getByPlaceholderText","getAllByPlaceholderText","queryByPlaceholderText","findByPlaceholderText","findAllByPlaceholderText"],"sources":["../../src/queries/placeholderText.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { TextInput } from 'react-native';\nimport { findAll } from '../helpers/findAll';\nimport { filterNodeByType } from '../helpers/filterNodeByType';\nimport { matches, TextMatch, TextMatchOptions } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport type { CommonQueryOptions } from './options';\n\ntype ByPlaceholderTextOptions = CommonQueryOptions & TextMatchOptions;\n\nconst getTextInputNodeByPlaceholderText = (\n node: ReactTestInstance,\n placeholder: TextMatch,\n options: TextMatchOptions = {}\n) => {\n const { exact, normalizer } = options;\n return (\n filterNodeByType(node, TextInput) &&\n matches(placeholder, node.props.placeholder, normalizer, exact)\n );\n};\n\nconst queryAllByPlaceholderText = (\n instance: ReactTestInstance\n): ((\n placeholder: TextMatch,\n queryOptions?: ByPlaceholderTextOptions\n) => Array<ReactTestInstance>) =>\n function queryAllByPlaceholderFn(placeholder, queryOptions) {\n return findAll(\n instance,\n (node) =>\n getTextInputNodeByPlaceholderText(node, placeholder, queryOptions),\n queryOptions\n );\n };\n\nconst getMultipleError = (placeholder: TextMatch) =>\n `Found multiple elements with placeholder: ${String(placeholder)} `;\nconst getMissingError = (placeholder: TextMatch) =>\n `Unable to find an element with placeholder: ${String(placeholder)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByPlaceholderText,\n getMissingError,\n getMultipleError\n);\n\nexport type ByPlaceholderTextQueries = {\n getByPlaceholderText: GetByQuery<TextMatch, ByPlaceholderTextOptions>;\n getAllByPlaceholderText: GetAllByQuery<TextMatch, ByPlaceholderTextOptions>;\n queryByPlaceholderText: QueryByQuery<TextMatch, ByPlaceholderTextOptions>;\n queryAllByPlaceholderText: QueryAllByQuery<\n TextMatch,\n ByPlaceholderTextOptions\n >;\n findByPlaceholderText: FindByQuery<TextMatch, ByPlaceholderTextOptions>;\n findAllByPlaceholderText: FindAllByQuery<TextMatch, ByPlaceholderTextOptions>;\n};\n\nexport const bindByPlaceholderTextQueries = (\n instance: ReactTestInstance\n): ByPlaceholderTextQueries => ({\n getByPlaceholderText: getBy(instance),\n getAllByPlaceholderText: getAllBy(instance),\n queryByPlaceholderText: queryBy(instance),\n queryAllByPlaceholderText: queryAllBy(instance),\n findByPlaceholderText: findBy(instance),\n findAllByPlaceholderText: findAllBy(instance),\n});\n"],"mappings":";;;;;;AACA;AACA;AACA;AACA;AACA;AAaA,MAAMA,iCAAiC,GAAG,CACxCC,IAAuB,EACvBC,WAAsB,EACtBC,OAAyB,GAAG,CAAC,CAAC,KAC3B;EACH,MAAM;IAAEC,KAAK;IAAEC;EAAW,CAAC,GAAGF,OAAO;EACrC,OACE,IAAAG,kCAAgB,EAACL,IAAI,EAAEM,sBAAS,CAAC,IACjC,IAAAC,gBAAO,EAACN,WAAW,EAAED,IAAI,CAACQ,KAAK,CAACP,WAAW,EAAEG,UAAU,EAAED,KAAK,CAAC;AAEnE,CAAC;AAED,MAAMM,yBAAyB,GAC7BC,QAA2B,IAK3B,SAASC,uBAAuB,CAACV,WAAW,EAAEW,YAAY,EAAE;EAC1D,OAAO,IAAAC,gBAAO,EACZH,QAAQ,EACPV,IAAI,IACHD,iCAAiC,CAACC,IAAI,EAAEC,WAAW,EAAEW,YAAY,CAAC,EACpEA,YAAY,CACb;AACH,CAAC;AAEH,MAAME,gBAAgB,GAAIb,WAAsB,IAC7C,6CAA4Cc,MAAM,CAACd,WAAW,CAAE,GAAE;AACrE,MAAMe,eAAe,GAAIf,WAAsB,IAC5C,+CAA8Cc,MAAM,CAACd,WAAW,CAAE,EAAC;AAEtE,MAAM;EAAEgB,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7Ed,yBAAyB,EACzBO,eAAe,EACfF,gBAAgB,CACjB;AAcM,MAAMU,4BAA4B,GACvCd,QAA2B,KACG;EAC9Be,oBAAoB,EAAER,KAAK,CAACP,QAAQ,CAAC;EACrCgB,uBAAuB,EAAER,QAAQ,CAACR,QAAQ,CAAC;EAC3CiB,sBAAsB,EAAER,OAAO,CAACT,QAAQ,CAAC;EACzCD,yBAAyB,EAAEW,UAAU,CAACV,QAAQ,CAAC;EAC/CkB,qBAAqB,EAAEP,MAAM,CAACX,QAAQ,CAAC;EACvCmB,wBAAwB,EAAEP,SAAS,CAACZ,QAAQ;AAC9C,CAAC,CAAC;AAAC"}
|
package/build/queries/role.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import type { AccessibilityState } from 'react-native';
|
|
1
2
|
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
-
import {
|
|
3
|
+
import { AccessibilityValueMatcher } from '../helpers/matchers/accessibilityValue';
|
|
4
|
+
import type { TextMatch } from '../matches';
|
|
3
5
|
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './makeQueries';
|
|
4
|
-
|
|
6
|
+
import { CommonQueryOptions } from './options';
|
|
7
|
+
type ByRoleOptions = CommonQueryOptions & AccessibilityState & {
|
|
5
8
|
name?: TextMatch;
|
|
9
|
+
value?: AccessibilityValueMatcher;
|
|
6
10
|
};
|
|
7
|
-
export
|
|
11
|
+
export type ByRoleQueries = {
|
|
8
12
|
getByRole: GetByQuery<TextMatch, ByRoleOptions>;
|
|
9
13
|
getAllByRole: GetAllByQuery<TextMatch, ByRoleOptions>;
|
|
10
14
|
queryByRole: QueryByQuery<TextMatch, ByRoleOptions>;
|
package/build/queries/role.js
CHANGED
|
@@ -4,13 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.bindByRoleQueries = void 0;
|
|
7
|
-
|
|
7
|
+
var _accessiblity = require("../helpers/accessiblity");
|
|
8
|
+
var _findAll = require("../helpers/findAll");
|
|
9
|
+
var _accessibilityState = require("../helpers/matchers/accessibilityState");
|
|
10
|
+
var _accessibilityValue = require("../helpers/matchers/accessibilityValue");
|
|
8
11
|
var _matchStringProp = require("../helpers/matchers/matchStringProp");
|
|
9
|
-
|
|
10
12
|
var _within = require("../within");
|
|
11
|
-
|
|
12
13
|
var _makeQueries = require("./makeQueries");
|
|
13
|
-
|
|
14
14
|
const matchAccessibleNameIfNeeded = (node, name) => {
|
|
15
15
|
if (name == null) return true;
|
|
16
16
|
const {
|
|
@@ -19,15 +19,36 @@ const matchAccessibleNameIfNeeded = (node, name) => {
|
|
|
19
19
|
} = (0, _within.getQueriesForElement)(node);
|
|
20
20
|
return queryAllByText(name).length > 0 || queryAllByLabelText(name).length > 0;
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
const matchAccessibleStateIfNeeded = (node, options) => {
|
|
23
|
+
return options != null ? (0, _accessibilityState.matchAccessibilityState)(node, options) : true;
|
|
24
|
+
};
|
|
25
|
+
const matchAccessibilityValueIfNeeded = (node, value) => {
|
|
26
|
+
return value != null ? (0, _accessibilityValue.matchAccessibilityValue)(node, value) : true;
|
|
27
|
+
};
|
|
23
28
|
const queryAllByRole = instance => function queryAllByRoleFn(role, options) {
|
|
24
|
-
return
|
|
29
|
+
return (0, _findAll.findAll)(instance, node =>
|
|
30
|
+
// run the cheapest checks first, and early exit too avoid unneeded computations
|
|
31
|
+
typeof node.type === 'string' && (0, _matchStringProp.matchStringProp)(node.props.accessibilityRole, role) && matchAccessibleStateIfNeeded(node, options) && matchAccessibilityValueIfNeeded(node, options?.value) && matchAccessibleNameIfNeeded(node, options?.name), options);
|
|
25
32
|
};
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
const formatQueryParams = (role, options = {}) => {
|
|
34
|
+
const params = [`role: "${String(role)}"`];
|
|
35
|
+
if (options.name) {
|
|
36
|
+
params.push(`name: "${String(options.name)}"`);
|
|
37
|
+
}
|
|
38
|
+
_accessiblity.accessibilityStateKeys.forEach(stateKey => {
|
|
39
|
+
if (options[stateKey] !== undefined) {
|
|
40
|
+
params.push(`${stateKey} state: ${options[stateKey]}`);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
_accessiblity.accessiblityValueKeys.forEach(valueKey => {
|
|
44
|
+
if (options?.value?.[valueKey] !== undefined) {
|
|
45
|
+
params.push(`${valueKey} value: ${options?.value?.[valueKey]}`);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return params.join(', ');
|
|
49
|
+
};
|
|
50
|
+
const getMultipleError = (role, options) => `Found multiple elements with ${formatQueryParams(role, options)}`;
|
|
51
|
+
const getMissingError = (role, options) => `Unable to find an element with ${formatQueryParams(role, options)}`;
|
|
31
52
|
const {
|
|
32
53
|
getBy,
|
|
33
54
|
getAllBy,
|
|
@@ -36,7 +57,6 @@ const {
|
|
|
36
57
|
findBy,
|
|
37
58
|
findAllBy
|
|
38
59
|
} = (0, _makeQueries.makeQueries)(queryAllByRole, getMissingError, getMultipleError);
|
|
39
|
-
|
|
40
60
|
const bindByRoleQueries = instance => ({
|
|
41
61
|
getByRole: getBy(instance),
|
|
42
62
|
getAllByRole: getAllBy(instance),
|
|
@@ -45,6 +65,5 @@ const bindByRoleQueries = instance => ({
|
|
|
45
65
|
findByRole: findBy(instance),
|
|
46
66
|
findAllByRole: findAllBy(instance)
|
|
47
67
|
});
|
|
48
|
-
|
|
49
68
|
exports.bindByRoleQueries = bindByRoleQueries;
|
|
50
69
|
//# sourceMappingURL=role.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role.js","names":["matchAccessibleNameIfNeeded","node","name","queryAllByText","queryAllByLabelText","getQueriesForElement","length","queryAllByRole","instance","queryAllByRoleFn","role","
|
|
1
|
+
{"version":3,"file":"role.js","names":["matchAccessibleNameIfNeeded","node","name","queryAllByText","queryAllByLabelText","getQueriesForElement","length","matchAccessibleStateIfNeeded","options","matchAccessibilityState","matchAccessibilityValueIfNeeded","value","matchAccessibilityValue","queryAllByRole","instance","queryAllByRoleFn","role","findAll","type","matchStringProp","props","accessibilityRole","formatQueryParams","params","String","push","accessibilityStateKeys","forEach","stateKey","undefined","accessiblityValueKeys","valueKey","join","getMultipleError","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByRoleQueries","getByRole","getAllByRole","queryByRole","findByRole","findAllByRole"],"sources":["../../src/queries/role.ts"],"sourcesContent":["import type { AccessibilityState } from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\nimport {\n accessibilityStateKeys,\n accessiblityValueKeys,\n} from '../helpers/accessiblity';\nimport { findAll } from '../helpers/findAll';\nimport { matchAccessibilityState } from '../helpers/matchers/accessibilityState';\nimport {\n AccessibilityValueMatcher,\n matchAccessibilityValue,\n} from '../helpers/matchers/accessibilityValue';\nimport { matchStringProp } from '../helpers/matchers/matchStringProp';\nimport type { TextMatch } from '../matches';\nimport { getQueriesForElement } from '../within';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport { CommonQueryOptions } from './options';\n\ntype ByRoleOptions = CommonQueryOptions &\n AccessibilityState & {\n name?: TextMatch;\n value?: AccessibilityValueMatcher;\n };\n\nconst matchAccessibleNameIfNeeded = (\n node: ReactTestInstance,\n name?: TextMatch\n) => {\n if (name == null) return true;\n\n const { queryAllByText, queryAllByLabelText } = getQueriesForElement(node);\n return (\n queryAllByText(name).length > 0 || queryAllByLabelText(name).length > 0\n );\n};\n\nconst matchAccessibleStateIfNeeded = (\n node: ReactTestInstance,\n options?: ByRoleOptions\n) => {\n return options != null ? matchAccessibilityState(node, options) : true;\n};\n\nconst matchAccessibilityValueIfNeeded = (\n node: ReactTestInstance,\n value?: AccessibilityValueMatcher\n) => {\n return value != null ? matchAccessibilityValue(node, value) : true;\n};\n\nconst queryAllByRole = (\n instance: ReactTestInstance\n): ((role: TextMatch, options?: ByRoleOptions) => Array<ReactTestInstance>) =>\n function queryAllByRoleFn(role, options) {\n return findAll(\n instance,\n (node) =>\n // run the cheapest checks first, and early exit too avoid unneeded computations\n typeof node.type === 'string' &&\n matchStringProp(node.props.accessibilityRole, role) &&\n matchAccessibleStateIfNeeded(node, options) &&\n matchAccessibilityValueIfNeeded(node, options?.value) &&\n matchAccessibleNameIfNeeded(node, options?.name),\n options\n );\n };\n\nconst formatQueryParams = (role: TextMatch, options: ByRoleOptions = {}) => {\n const params = [`role: \"${String(role)}\"`];\n\n if (options.name) {\n params.push(`name: \"${String(options.name)}\"`);\n }\n\n accessibilityStateKeys.forEach((stateKey) => {\n if (options[stateKey] !== undefined) {\n params.push(`${stateKey} state: ${options[stateKey]}`);\n }\n });\n\n accessiblityValueKeys.forEach((valueKey) => {\n if (options?.value?.[valueKey] !== undefined) {\n params.push(`${valueKey} value: ${options?.value?.[valueKey]}`);\n }\n });\n\n return params.join(', ');\n};\n\nconst getMultipleError = (role: TextMatch, options?: ByRoleOptions) =>\n `Found multiple elements with ${formatQueryParams(role, options)}`;\n\nconst getMissingError = (role: TextMatch, options?: ByRoleOptions) =>\n `Unable to find an element with ${formatQueryParams(role, options)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByRole,\n getMissingError,\n getMultipleError\n);\n\nexport type ByRoleQueries = {\n getByRole: GetByQuery<TextMatch, ByRoleOptions>;\n getAllByRole: GetAllByQuery<TextMatch, ByRoleOptions>;\n queryByRole: QueryByQuery<TextMatch, ByRoleOptions>;\n queryAllByRole: QueryAllByQuery<TextMatch, ByRoleOptions>;\n findByRole: FindByQuery<TextMatch, ByRoleOptions>;\n findAllByRole: FindAllByQuery<TextMatch, ByRoleOptions>;\n};\n\nexport const bindByRoleQueries = (\n instance: ReactTestInstance\n): ByRoleQueries => ({\n getByRole: getBy(instance),\n getAllByRole: getAllBy(instance),\n queryByRole: queryBy(instance),\n queryAllByRole: queryAllBy(instance),\n findByRole: findBy(instance),\n findAllByRole: findAllBy(instance),\n});\n"],"mappings":";;;;;;AAEA;AAIA;AACA;AACA;AAIA;AAEA;AACA;AAiBA,MAAMA,2BAA2B,GAAG,CAClCC,IAAuB,EACvBC,IAAgB,KACb;EACH,IAAIA,IAAI,IAAI,IAAI,EAAE,OAAO,IAAI;EAE7B,MAAM;IAAEC,cAAc;IAAEC;EAAoB,CAAC,GAAG,IAAAC,4BAAoB,EAACJ,IAAI,CAAC;EAC1E,OACEE,cAAc,CAACD,IAAI,CAAC,CAACI,MAAM,GAAG,CAAC,IAAIF,mBAAmB,CAACF,IAAI,CAAC,CAACI,MAAM,GAAG,CAAC;AAE3E,CAAC;AAED,MAAMC,4BAA4B,GAAG,CACnCN,IAAuB,EACvBO,OAAuB,KACpB;EACH,OAAOA,OAAO,IAAI,IAAI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B,CAACH,OAAO,CAAEI,QAAQ,IAAK;IAC1C,IAAIvB,OAAO,EAAEG,KAAK,GAAGoB,QAAQ,CAAC,KAAKF,SAAS,EAAE;MAC5CN,MAAM,CAACE,IAAI,CAAE,GAAEM,QAAS,WAAUvB,OAAO,EAAEG,KAAK,GAAGoB,QAAQ,CAAE,EAAC,CAAC;IACjE;EACF,CAAC,CAAC;EAEF,OAAOR,MAAM,CAACS,IAAI,CAAC,IAAI,CAAC;AAC1B,CAAC;AAED,MAAMC,gBAAgB,GAAG,CAACjB,IAAe,EAAER,OAAuB,KAC/D,gCAA+Bc,iBAAiB,CAACN,IAAI,EAAER,OAAO,CAAE,EAAC;AAEpE,MAAM0B,eAAe,GAAG,CAAClB,IAAe,EAAER,OAAuB,KAC9D,kCAAiCc,iBAAiB,CAACN,IAAI,EAAER,OAAO,CAAE,EAAC;AAEtE,MAAM;EAAE2B,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7E5B,cAAc,EACdqB,eAAe,EACfD,gBAAgB,CACjB;AAWM,MAAMS,iBAAiB,GAC5B5B,QAA2B,KACR;EACnB6B,SAAS,EAAER,KAAK,CAACrB,QAAQ,CAAC;EAC1B8B,YAAY,EAAER,QAAQ,CAACtB,QAAQ,CAAC;EAChC+B,WAAW,EAAER,OAAO,CAACvB,QAAQ,CAAC;EAC9BD,cAAc,EAAEyB,UAAU,CAACxB,QAAQ,CAAC;EACpCgC,UAAU,EAAEP,MAAM,CAACzB,QAAQ,CAAC;EAC5BiC,aAAa,EAAEP,SAAS,CAAC1B,QAAQ;AACnC,CAAC,CAAC;AAAC"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
-
import { TextMatch } from '../matches';
|
|
2
|
+
import { TextMatch, TextMatchOptions } from '../matches';
|
|
3
3
|
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './makeQueries';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
import type { CommonQueryOptions } from './options';
|
|
5
|
+
type ByTestIdOptions = CommonQueryOptions & TextMatchOptions;
|
|
6
|
+
export type ByTestIdQueries = {
|
|
7
|
+
getByTestId: GetByQuery<TextMatch, ByTestIdOptions>;
|
|
8
|
+
getAllByTestId: GetAllByQuery<TextMatch, ByTestIdOptions>;
|
|
9
|
+
queryByTestId: QueryByQuery<TextMatch, ByTestIdOptions>;
|
|
10
|
+
queryAllByTestId: QueryAllByQuery<TextMatch, ByTestIdOptions>;
|
|
11
|
+
findByTestId: FindByQuery<TextMatch, ByTestIdOptions>;
|
|
12
|
+
findAllByTestId: FindAllByQuery<TextMatch, ByTestIdOptions>;
|
|
12
13
|
};
|
|
13
14
|
export declare const bindByTestIdQueries: (instance: ReactTestInstance) => ByTestIdQueries;
|
|
15
|
+
export {};
|
package/build/queries/testId.js
CHANGED
|
@@ -4,11 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.bindByTestIdQueries = void 0;
|
|
7
|
-
|
|
7
|
+
var _findAll = require("../helpers/findAll");
|
|
8
8
|
var _matches = require("../matches");
|
|
9
|
-
|
|
10
9
|
var _makeQueries = require("./makeQueries");
|
|
11
|
-
|
|
12
10
|
const getNodeByTestId = (node, testID, options = {}) => {
|
|
13
11
|
const {
|
|
14
12
|
exact,
|
|
@@ -16,16 +14,12 @@ const getNodeByTestId = (node, testID, options = {}) => {
|
|
|
16
14
|
} = options;
|
|
17
15
|
return (0, _matches.matches)(testID, node.props.testID, normalizer, exact);
|
|
18
16
|
};
|
|
19
|
-
|
|
20
17
|
const queryAllByTestId = instance => function queryAllByTestIdFn(testId, queryOptions) {
|
|
21
|
-
const results =
|
|
22
|
-
return results;
|
|
18
|
+
const results = (0, _findAll.findAll)(instance, node => getNodeByTestId(node, testId, queryOptions), queryOptions);
|
|
19
|
+
return results.filter(element => typeof element.type === 'string');
|
|
23
20
|
};
|
|
24
|
-
|
|
25
21
|
const getMultipleError = testId => `Found multiple elements with testID: ${String(testId)}`;
|
|
26
|
-
|
|
27
22
|
const getMissingError = testId => `Unable to find an element with testID: ${String(testId)}`;
|
|
28
|
-
|
|
29
23
|
const {
|
|
30
24
|
getBy,
|
|
31
25
|
getAllBy,
|
|
@@ -34,7 +28,6 @@ const {
|
|
|
34
28
|
findBy,
|
|
35
29
|
findAllBy
|
|
36
30
|
} = (0, _makeQueries.makeQueries)(queryAllByTestId, getMissingError, getMultipleError);
|
|
37
|
-
|
|
38
31
|
const bindByTestIdQueries = instance => ({
|
|
39
32
|
getByTestId: getBy(instance),
|
|
40
33
|
getAllByTestId: getAllBy(instance),
|
|
@@ -43,6 +36,5 @@ const bindByTestIdQueries = instance => ({
|
|
|
43
36
|
findByTestId: findBy(instance),
|
|
44
37
|
findAllByTestId: findAllBy(instance)
|
|
45
38
|
});
|
|
46
|
-
|
|
47
39
|
exports.bindByTestIdQueries = bindByTestIdQueries;
|
|
48
40
|
//# sourceMappingURL=testId.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testId.js","names":["getNodeByTestId","node","testID","options","exact","normalizer","matches","props","queryAllByTestId","instance","queryAllByTestIdFn","testId","queryOptions","results","findAll","filter","element","type","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTestIdQueries","getByTestId","getAllByTestId","queryByTestId","findByTestId","findAllByTestId"],"sources":["../../src/queries/testId.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matches, TextMatch } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport type {
|
|
1
|
+
{"version":3,"file":"testId.js","names":["getNodeByTestId","node","testID","options","exact","normalizer","matches","props","queryAllByTestId","instance","queryAllByTestIdFn","testId","queryOptions","results","findAll","filter","element","type","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTestIdQueries","getByTestId","getAllByTestId","queryByTestId","findByTestId","findAllByTestId"],"sources":["../../src/queries/testId.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { findAll } from '../helpers/findAll';\nimport { matches, TextMatch, TextMatchOptions } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport type { CommonQueryOptions } from './options';\n\ntype ByTestIdOptions = CommonQueryOptions & TextMatchOptions;\n\nconst getNodeByTestId = (\n node: ReactTestInstance,\n testID: TextMatch,\n options: TextMatchOptions = {}\n) => {\n const { exact, normalizer } = options;\n return matches(testID, node.props.testID, normalizer, exact);\n};\n\nconst queryAllByTestId = (\n instance: ReactTestInstance\n): ((\n testId: TextMatch,\n queryOptions?: ByTestIdOptions\n) => Array<ReactTestInstance>) =>\n function queryAllByTestIdFn(testId, queryOptions) {\n const results = findAll(\n instance,\n (node) => getNodeByTestId(node, testId, queryOptions),\n queryOptions\n );\n\n return results.filter((element) => typeof element.type === 'string');\n };\n\nconst getMultipleError = (testId: TextMatch) =>\n `Found multiple elements with testID: ${String(testId)}`;\nconst getMissingError = (testId: TextMatch) =>\n `Unable to find an element with testID: ${String(testId)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByTestId,\n getMissingError,\n getMultipleError\n);\n\nexport type ByTestIdQueries = {\n getByTestId: GetByQuery<TextMatch, ByTestIdOptions>;\n getAllByTestId: GetAllByQuery<TextMatch, ByTestIdOptions>;\n queryByTestId: QueryByQuery<TextMatch, ByTestIdOptions>;\n queryAllByTestId: QueryAllByQuery<TextMatch, ByTestIdOptions>;\n findByTestId: FindByQuery<TextMatch, ByTestIdOptions>;\n findAllByTestId: FindAllByQuery<TextMatch, ByTestIdOptions>;\n};\n\nexport const bindByTestIdQueries = (\n instance: ReactTestInstance\n): ByTestIdQueries => ({\n getByTestId: getBy(instance),\n getAllByTestId: getAllBy(instance),\n queryByTestId: queryBy(instance),\n queryAllByTestId: queryAllBy(instance),\n findByTestId: findBy(instance),\n findAllByTestId: findAllBy(instance),\n});\n"],"mappings":";;;;;;AACA;AACA;AACA;AAaA,MAAMA,eAAe,GAAG,CACtBC,IAAuB,EACvBC,MAAiB,EACjBC,OAAyB,GAAG,CAAC,CAAC,KAC3B;EACH,MAAM;IAAEC,KAAK;IAAEC;EAAW,CAAC,GAAGF,OAAO;EACrC,OAAO,IAAAG,gBAAO,EAACJ,MAAM,EAAED,IAAI,CAACM,KAAK,CAACL,MAAM,EAAEG,UAAU,EAAED,KAAK,CAAC;AAC9D,CAAC;AAED,MAAMI,gBAAgB,GACpBC,QAA2B,IAK3B,SAASC,kBAAkB,CAACC,MAAM,EAAEC,YAAY,EAAE;EAChD,MAAMC,OAAO,GAAG,IAAAC,gBAAO,EACrBL,QAAQ,EACPR,IAAI,IAAKD,eAAe,CAACC,IAAI,EAAEU,MAAM,EAAEC,YAAY,CAAC,EACrDA,YAAY,CACb;EAED,OAAOC,OAAO,CAACE,MAAM,CAAEC,OAAO,IAAK,OAAOA,OAAO,CAACC,IAAI,KAAK,QAAQ,CAAC;AACtE,CAAC;AAEH,MAAMC,gBAAgB,GAAIP,MAAiB,IACxC,wCAAuCQ,MAAM,CAACR,MAAM,CAAE,EAAC;AAC1D,MAAMS,eAAe,GAAIT,MAAiB,IACvC,0CAAyCQ,MAAM,CAACR,MAAM,CAAE,EAAC;AAE5D,MAAM;EAAEU,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7EnB,gBAAgB,EAChBY,eAAe,EACfF,gBAAgB,CACjB;AAWM,MAAMU,mBAAmB,GAC9BnB,QAA2B,KACN;EACrBoB,WAAW,EAAER,KAAK,CAACZ,QAAQ,CAAC;EAC5BqB,cAAc,EAAER,QAAQ,CAACb,QAAQ,CAAC;EAClCsB,aAAa,EAAER,OAAO,CAACd,QAAQ,CAAC;EAChCD,gBAAgB,EAAEgB,UAAU,CAACf,QAAQ,CAAC;EACtCuB,YAAY,EAAEP,MAAM,CAAChB,QAAQ,CAAC;EAC9BwB,eAAe,EAAEP,SAAS,CAACjB,QAAQ;AACrC,CAAC,CAAC;AAAC"}
|
package/build/queries/text.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
-
import { TextMatch } from '../matches';
|
|
3
|
-
import type { NormalizerFn } from '../matches';
|
|
2
|
+
import { TextMatch, TextMatchOptions } from '../matches';
|
|
4
3
|
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './makeQueries';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
findByText: FindByQuery<TextMatch, TextMatchOptions>;
|
|
15
|
-
findAllByText: FindAllByQuery<TextMatch, TextMatchOptions>;
|
|
4
|
+
import { CommonQueryOptions } from './options';
|
|
5
|
+
type ByTextOptions = CommonQueryOptions & TextMatchOptions;
|
|
6
|
+
export type ByTextQueries = {
|
|
7
|
+
getByText: GetByQuery<TextMatch, ByTextOptions>;
|
|
8
|
+
getAllByText: GetAllByQuery<TextMatch, ByTextOptions>;
|
|
9
|
+
queryByText: QueryByQuery<TextMatch, ByTextOptions>;
|
|
10
|
+
queryAllByText: QueryAllByQuery<TextMatch, ByTextOptions>;
|
|
11
|
+
findByText: FindByQuery<TextMatch, ByTextOptions>;
|
|
12
|
+
findAllByText: FindAllByQuery<TextMatch, ByTextOptions>;
|
|
16
13
|
};
|
|
17
14
|
export declare const bindByTextQueries: (instance: ReactTestInstance) => ByTextQueries;
|
|
15
|
+
export {};
|