@testing-library/react-native 11.4.0 → 11.5.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 +3 -3
- package/build/act.d.ts +3 -1
- package/build/act.js +1 -13
- package/build/act.js.map +1 -1
- package/build/cleanup.d.ts +1 -1
- package/build/config.d.ts +31 -2
- package/build/config.js +28 -3
- package/build/config.js.map +1 -1
- package/build/fireEvent.js +3 -3
- package/build/fireEvent.js.map +1 -1
- package/build/flushMicroTasks.d.ts +1 -1
- package/build/helpers/accessiblity.d.ts +11 -4
- package/build/helpers/accessiblity.js +29 -9
- package/build/helpers/accessiblity.js.map +1 -1
- package/build/helpers/debugDeep.d.ts +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 +2 -2
- 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/host-component-names.d.ts +2 -0
- package/build/helpers/host-component-names.js +50 -0
- package/build/helpers/host-component-names.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/matchLabelText.d.ts +3 -0
- package/build/helpers/matchers/matchLabelText.js +26 -0
- package/build/helpers/matchers/matchLabelText.js.map +1 -0
- package/build/helpers/matchers/matchTextContent.d.ts +10 -0
- package/build/helpers/matchers/matchTextContent.js +24 -0
- package/build/helpers/matchers/matchTextContent.js.map +1 -0
- package/build/helpers/timers.d.ts +0 -2
- package/build/helpers/timers.js.map +1 -1
- package/build/index.flow.js +123 -54
- package/build/matches.d.ts +7 -3
- package/build/matches.js.map +1 -1
- package/build/pure.d.ts +12 -23
- package/build/pure.js +8 -2
- package/build/pure.js.map +1 -1
- package/build/queries/a11yState.d.ts +15 -14
- package/build/queries/a11yState.js +3 -2
- package/build/queries/a11yState.js.map +1 -1
- package/build/queries/a11yValue.d.ts +15 -20
- package/build/queries/a11yValue.js +16 -5
- package/build/queries/a11yValue.js.map +1 -1
- package/build/queries/displayValue.d.ts +11 -9
- package/build/queries/displayValue.js +7 -2
- package/build/queries/displayValue.js.map +1 -1
- package/build/queries/hintText.d.ts +23 -21
- package/build/queries/hintText.js +2 -1
- package/build/queries/hintText.js.map +1 -1
- package/build/queries/labelText.d.ts +11 -9
- package/build/queries/labelText.js +7 -11
- package/build/queries/labelText.js.map +1 -1
- package/build/queries/makeQueries.d.ts +8 -8
- 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 +8 -3
- package/build/queries/placeholderText.js.map +1 -1
- package/build/queries/role.d.ts +7 -4
- package/build/queries/role.js +22 -11
- package/build/queries/role.js.map +1 -1
- package/build/queries/testId.d.ts +11 -9
- package/build/queries/testId.js +2 -2
- package/build/queries/testId.js.map +1 -1
- package/build/queries/text.d.ts +11 -13
- package/build/queries/text.js +24 -51
- package/build/queries/text.js.map +1 -1
- package/build/queries/unsafeProps.d.ts +1 -1
- package/build/queries/unsafeType.d.ts +1 -1
- package/build/render.d.ts +92 -146
- package/build/renderHook.d.ts +2 -2
- package/build/waitFor.d.ts +1 -1
- package/build/within.d.ts +90 -144
- package/package.json +17 -18
- package/typings/index.flow.js +123 -54
package/build/queries/role.js
CHANGED
|
@@ -5,9 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.bindByRoleQueries = void 0;
|
|
7
7
|
var _accessiblity = require("../helpers/accessiblity");
|
|
8
|
+
var _findAll = require("../helpers/findAll");
|
|
8
9
|
var _accessibilityState = require("../helpers/matchers/accessibilityState");
|
|
10
|
+
var _accessibilityValue = require("../helpers/matchers/accessibilityValue");
|
|
9
11
|
var _matchStringProp = require("../helpers/matchers/matchStringProp");
|
|
10
12
|
var _within = require("../within");
|
|
13
|
+
var _config = require("../config");
|
|
11
14
|
var _makeQueries = require("./makeQueries");
|
|
12
15
|
const matchAccessibleNameIfNeeded = (node, name) => {
|
|
13
16
|
if (name == null) return true;
|
|
@@ -20,26 +23,34 @@ const matchAccessibleNameIfNeeded = (node, name) => {
|
|
|
20
23
|
const matchAccessibleStateIfNeeded = (node, options) => {
|
|
21
24
|
return options != null ? (0, _accessibilityState.matchAccessibilityState)(node, options) : true;
|
|
22
25
|
};
|
|
26
|
+
const matchAccessibilityValueIfNeeded = (node, value) => {
|
|
27
|
+
return value != null ? (0, _accessibilityValue.matchAccessibilityValue)(node, value) : true;
|
|
28
|
+
};
|
|
23
29
|
const queryAllByRole = instance => function queryAllByRoleFn(role, options) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
typeof node.type === 'string' && (0, _matchStringProp.matchStringProp)(node.props.accessibilityRole, role) && matchAccessibleStateIfNeeded(node, options) && matchAccessibleNameIfNeeded(node, options?.name));
|
|
30
|
+
const shouldMatchOnlyAccessibilityElements = (0, _config.getConfig)().useBreakingChanges;
|
|
31
|
+
return (0, _findAll.findAll)(instance, node =>
|
|
32
|
+
// run the cheapest checks first, and early exit to avoid unneeded computations
|
|
33
|
+
typeof node.type === 'string' && (!shouldMatchOnlyAccessibilityElements || (0, _accessiblity.isAccessibilityElement)(node)) && (0, _matchStringProp.matchStringProp)(node.props.accessibilityRole, role) && matchAccessibleStateIfNeeded(node, options) && matchAccessibilityValueIfNeeded(node, options?.value) && matchAccessibleNameIfNeeded(node, options?.name), options);
|
|
28
34
|
};
|
|
29
|
-
const
|
|
30
|
-
const
|
|
35
|
+
const formatQueryParams = (role, options = {}) => {
|
|
36
|
+
const params = [`role: "${String(role)}"`];
|
|
31
37
|
if (options.name) {
|
|
32
|
-
|
|
38
|
+
params.push(`name: "${String(options.name)}"`);
|
|
33
39
|
}
|
|
34
40
|
_accessiblity.accessibilityStateKeys.forEach(stateKey => {
|
|
35
41
|
if (options[stateKey] !== undefined) {
|
|
36
|
-
|
|
42
|
+
params.push(`${stateKey} state: ${options[stateKey]}`);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
_accessiblity.accessiblityValueKeys.forEach(valueKey => {
|
|
46
|
+
if (options?.value?.[valueKey] !== undefined) {
|
|
47
|
+
params.push(`${valueKey} value: ${options?.value?.[valueKey]}`);
|
|
37
48
|
}
|
|
38
49
|
});
|
|
39
|
-
return
|
|
50
|
+
return params.join(', ');
|
|
40
51
|
};
|
|
41
|
-
const getMultipleError = (role, options) => `Found multiple elements with ${
|
|
42
|
-
const getMissingError = (role, options) => `Unable to find an element with ${
|
|
52
|
+
const getMultipleError = (role, options) => `Found multiple elements with ${formatQueryParams(role, options)}`;
|
|
53
|
+
const getMissingError = (role, options) => `Unable to find an element with ${formatQueryParams(role, options)}`;
|
|
43
54
|
const {
|
|
44
55
|
getBy,
|
|
45
56
|
getAllBy,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role.js","names":["matchAccessibleNameIfNeeded","node","name","queryAllByText","queryAllByLabelText","getQueriesForElement","length","matchAccessibleStateIfNeeded","options","matchAccessibilityState","queryAllByRole","instance","queryAllByRoleFn","role","findAll","type","matchStringProp","props","accessibilityRole","
|
|
1
|
+
{"version":3,"file":"role.js","names":["matchAccessibleNameIfNeeded","node","name","queryAllByText","queryAllByLabelText","getQueriesForElement","length","matchAccessibleStateIfNeeded","options","matchAccessibilityState","matchAccessibilityValueIfNeeded","value","matchAccessibilityValue","queryAllByRole","instance","queryAllByRoleFn","role","shouldMatchOnlyAccessibilityElements","getConfig","useBreakingChanges","findAll","type","isAccessibilityElement","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 isAccessibilityElement,\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 { getConfig } from '../config';\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 const shouldMatchOnlyAccessibilityElements = getConfig().useBreakingChanges;\n\n return findAll(\n instance,\n (node) =>\n // run the cheapest checks first, and early exit to avoid unneeded computations\n typeof node.type === 'string' &&\n (!shouldMatchOnlyAccessibilityElements ||\n isAccessibilityElement(node)) &&\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":";;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AU,CAAC,GAAG,IAAAC,wBAAW,EAC7EhC,cAAc,EACdyB,eAAe,EACfD,gBAAgB,CACjB;AAWM,MAAMS,iBAAiB,GAC5BhC,QAA2B,KACR;EACnBiC,SAAS,EAAER,KAAK,CAACzB,QAAQ,CAAC;EAC1BkC,YAAY,EAAER,QAAQ,CAAC1B,QAAQ,CAAC;EAChCmC,WAAW,EAAER,OAAO,CAAC3B,QAAQ,CAAC;EAC9BD,cAAc,EAAE6B,UAAU,CAAC5B,QAAQ,CAAC;EACpCoC,UAAU,EAAEP,MAAM,CAAC7B,QAAQ,CAAC;EAC5BqC,aAAa,EAAEP,SAAS,CAAC9B,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,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.bindByTestIdQueries = void 0;
|
|
7
|
+
var _findAll = require("../helpers/findAll");
|
|
7
8
|
var _matches = require("../matches");
|
|
8
9
|
var _makeQueries = require("./makeQueries");
|
|
9
10
|
const getNodeByTestId = (node, testID, options = {}) => {
|
|
@@ -14,8 +15,7 @@ const getNodeByTestId = (node, testID, options = {}) => {
|
|
|
14
15
|
return (0, _matches.matches)(testID, node.props.testID, normalizer, exact);
|
|
15
16
|
};
|
|
16
17
|
const queryAllByTestId = instance => function queryAllByTestIdFn(testId, queryOptions) {
|
|
17
|
-
|
|
18
|
-
return results;
|
|
18
|
+
return (0, _findAll.findAll)(instance, node => typeof node.type === 'string' && getNodeByTestId(node, testId, queryOptions), queryOptions);
|
|
19
19
|
};
|
|
20
20
|
const getMultipleError = testId => `Found multiple elements with testID: ${String(testId)}`;
|
|
21
21
|
const getMissingError = testId => `Unable to find an element with testID: ${String(testId)}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testId.js","names":["getNodeByTestId","node","testID","options","exact","normalizer","matches","props","queryAllByTestId","instance","queryAllByTestIdFn","testId","queryOptions","
|
|
1
|
+
{"version":3,"file":"testId.js","names":["getNodeByTestId","node","testID","options","exact","normalizer","matches","props","queryAllByTestId","instance","queryAllByTestIdFn","testId","queryOptions","findAll","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 return findAll(\n instance,\n (node) =>\n typeof node.type === 'string' &&\n getNodeByTestId(node, testId, queryOptions),\n queryOptions\n );\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,C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@ -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 type { 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 {};
|
package/build/queries/text.js
CHANGED
|
@@ -5,61 +5,34 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.bindByTextQueries = void 0;
|
|
7
7
|
var _reactNative = require("react-native");
|
|
8
|
-
var
|
|
9
|
-
var _filterNodeByType = require("../helpers/filterNodeByType");
|
|
8
|
+
var _config = require("../config");
|
|
10
9
|
var _componentTree = require("../helpers/component-tree");
|
|
11
|
-
var
|
|
10
|
+
var _filterNodeByType = require("../helpers/filterNodeByType");
|
|
11
|
+
var _findAll = require("../helpers/findAll");
|
|
12
|
+
var _hostComponentNames = require("../helpers/host-component-names");
|
|
13
|
+
var _matchTextContent = require("../helpers/matchers/matchTextContent");
|
|
12
14
|
var _makeQueries = require("./makeQueries");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (typeof child === 'number') {
|
|
23
|
-
textContent.push(child.toString());
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (child?.props?.children) {
|
|
27
|
-
// Bail on traversing text children down the tree if current node (child)
|
|
28
|
-
// has no text. In such situations, react-test-renderer will traverse down
|
|
29
|
-
// this tree in a separate call and run this query again. As a result, the
|
|
30
|
-
// query will match the deepest text node that matches requested text.
|
|
31
|
-
if ((0, _filterNodeByType.filterNodeByType)(child, _reactNative.Text)) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if ((0, _filterNodeByType.filterNodeByType)(child, React.Fragment)) {
|
|
35
|
-
textContent.push(...getChildrenAsText(child.props.children));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return textContent;
|
|
40
|
-
};
|
|
41
|
-
const getNodeByText = (node, text, options = {}) => {
|
|
42
|
-
const isTextComponent = (0, _filterNodeByType.filterNodeByType)(node, _reactNative.Text);
|
|
43
|
-
if (isTextComponent) {
|
|
44
|
-
const textChildren = getChildrenAsText(node.props.children);
|
|
45
|
-
if (textChildren) {
|
|
46
|
-
const textToTest = textChildren.join('');
|
|
47
|
-
const {
|
|
48
|
-
exact,
|
|
49
|
-
normalizer
|
|
50
|
-
} = options;
|
|
51
|
-
return (0, _matches.matches)(text, textToTest, normalizer, exact);
|
|
15
|
+
const queryAllByText = instance => function queryAllByTextFn(text, options = {}) {
|
|
16
|
+
const shouldReturnHostText = (0, _config.getConfig)().useBreakingChanges;
|
|
17
|
+
|
|
18
|
+
// Legacy version: return composite Text
|
|
19
|
+
if (!shouldReturnHostText) {
|
|
20
|
+
const baseInstance = (0, _componentTree.isHostElementForType)(instance, _reactNative.Text) ? (0, _componentTree.getCompositeParentOfType)(instance, _reactNative.Text) : instance;
|
|
21
|
+
if (!baseInstance) {
|
|
22
|
+
return [];
|
|
52
23
|
}
|
|
24
|
+
const results = (0, _findAll.findAll)(baseInstance, node => (0, _filterNodeByType.filterNodeByType)(node, _reactNative.Text) && (0, _matchTextContent.matchTextContent)(node, text, options), {
|
|
25
|
+
...options,
|
|
26
|
+
matchDeepestOnly: true
|
|
27
|
+
});
|
|
28
|
+
return results;
|
|
53
29
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
const results = baseInstance.findAll(node => getNodeByText(node, text, options));
|
|
62
|
-
return results;
|
|
30
|
+
|
|
31
|
+
// vNext version: returns host Text
|
|
32
|
+
return (0, _findAll.findAll)(instance, node => (0, _filterNodeByType.filterNodeByType)(node, (0, _hostComponentNames.getHostComponentNames)().text) && (0, _matchTextContent.matchTextContent)(node, text, options), {
|
|
33
|
+
...options,
|
|
34
|
+
matchDeepestOnly: true
|
|
35
|
+
});
|
|
63
36
|
};
|
|
64
37
|
const getMultipleError = text => `Found multiple elements with text: ${String(text)}`;
|
|
65
38
|
const getMissingError = text => `Unable to find an element with text: ${String(text)}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","names":["
|
|
1
|
+
{"version":3,"file":"text.js","names":["queryAllByText","instance","queryAllByTextFn","text","options","shouldReturnHostText","getConfig","useBreakingChanges","baseInstance","isHostElementForType","Text","getCompositeParentOfType","results","findAll","node","filterNodeByType","matchTextContent","matchDeepestOnly","getHostComponentNames","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTextQueries","getByText","getAllByText","queryByText","findByText","findAllByText"],"sources":["../../src/queries/text.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { Text } from 'react-native';\nimport { getConfig } from '../config';\nimport {\n getCompositeParentOfType,\n isHostElementForType,\n} from '../helpers/component-tree';\nimport { filterNodeByType } from '../helpers/filterNodeByType';\nimport { findAll } from '../helpers/findAll';\nimport { getHostComponentNames } from '../helpers/host-component-names';\nimport { matchTextContent } from '../helpers/matchers/matchTextContent';\nimport { 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 ByTextOptions = CommonQueryOptions & TextMatchOptions;\n\nconst queryAllByText = (\n instance: ReactTestInstance\n): ((text: TextMatch, options?: ByTextOptions) => Array<ReactTestInstance>) =>\n function queryAllByTextFn(text, options = {}) {\n const shouldReturnHostText = getConfig().useBreakingChanges;\n\n // Legacy version: return composite Text\n if (!shouldReturnHostText) {\n const baseInstance = isHostElementForType(instance, Text)\n ? getCompositeParentOfType(instance, Text)\n : instance;\n\n if (!baseInstance) {\n return [];\n }\n\n const results = findAll(\n baseInstance,\n (node) =>\n filterNodeByType(node, Text) && matchTextContent(node, text, options),\n { ...options, matchDeepestOnly: true }\n );\n\n return results;\n }\n\n // vNext version: returns host Text\n return findAll(\n instance,\n (node) =>\n filterNodeByType(node, getHostComponentNames().text) &&\n matchTextContent(node, text, options),\n {\n ...options,\n matchDeepestOnly: true,\n }\n );\n };\n\nconst getMultipleError = (text: TextMatch) =>\n `Found multiple elements with text: ${String(text)}`;\n\nconst getMissingError = (text: TextMatch) =>\n `Unable to find an element with text: ${String(text)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByText,\n getMissingError,\n getMultipleError\n);\n\nexport type ByTextQueries = {\n getByText: GetByQuery<TextMatch, ByTextOptions>;\n getAllByText: GetAllByQuery<TextMatch, ByTextOptions>;\n queryByText: QueryByQuery<TextMatch, ByTextOptions>;\n queryAllByText: QueryAllByQuery<TextMatch, ByTextOptions>;\n findByText: FindByQuery<TextMatch, ByTextOptions>;\n findAllByText: FindAllByQuery<TextMatch, ByTextOptions>;\n};\n\nexport const bindByTextQueries = (\n instance: ReactTestInstance\n): ByTextQueries => ({\n getByText: getBy(instance),\n getAllByText: getAllBy(instance),\n queryByText: queryBy(instance),\n queryAllByText: queryAllBy(instance),\n findByText: findBy(instance),\n findAllByText: findAllBy(instance),\n});\n"],"mappings":";;;;;;AACA;AACA;AACA;AAIA;AACA;AACA;AACA;AAEA;AAaA,MAAMA,cAAc,GAClBC,QAA2B,IAE3B,SAASC,gBAAgB,CAACC,IAAI,EAAEC,OAAO,GAAG,CAAC,CAAC,EAAE;EAC5C,MAAMC,oBAAoB,GAAG,IAAAC,iBAAS,GAAE,CAACC,kBAAkB;;EAE3D;EACA,IAAI,CAACF,oBAAoB,EAAE;IACzB,MAAMG,YAAY,GAAG,IAAAC,mCAAoB,EAACR,QAAQ,EAAES,iBAAI,CAAC,GACrD,IAAAC,uCAAwB,EAACV,QAAQ,EAAES,iBAAI,CAAC,GACxCT,QAAQ;IAEZ,IAAI,CAACO,YAAY,EAAE;MACjB,OAAO,EAAE;IACX;IAEA,MAAMI,OAAO,GAAG,IAAAC,gBAAO,EACrBL,YAAY,EACXM,IAAI,IACH,IAAAC,kCAAgB,EAACD,IAAI,EAAEJ,iBAAI,CAAC,IAAI,IAAAM,kCAAgB,EAACF,IAAI,EAAEX,IAAI,EAAEC,OAAO,CAAC,EACvE;MAAE,GAAGA,OAAO;MAAEa,gBAAgB,EAAE;IAAK,CAAC,CACvC;IAED,OAAOL,OAAO;EAChB;;EAEA;EACA,OAAO,IAAAC,gBAAO,EACZZ,QAAQ,EACPa,IAAI,IACH,IAAAC,kCAAgB,EAACD,IAAI,EAAE,IAAAI,yCAAqB,GAAE,CAACf,IAAI,CAAC,IACpD,IAAAa,kCAAgB,EAACF,IAAI,EAAEX,IAAI,EAAEC,OAAO,CAAC,EACvC;IACE,GAAGA,OAAO;IACVa,gBAAgB,EAAE;EACpB,CAAC,CACF;AACH,CAAC;AAEH,MAAME,gBAAgB,GAAIhB,IAAe,IACtC,sCAAqCiB,MAAM,CAACjB,IAAI,CAAE,EAAC;AAEtD,MAAMkB,eAAe,GAAIlB,IAAe,IACrC,wCAAuCiB,MAAM,CAACjB,IAAI,CAAE,EAAC;AAExD,MAAM;EAAEmB,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7E5B,cAAc,EACdqB,eAAe,EACfF,gBAAgB,CACjB;AAWM,MAAMU,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,6 +1,6 @@
|
|
|
1
1
|
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
export
|
|
3
|
+
export type UnsafeByTypeQueries = {
|
|
4
4
|
UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;
|
|
5
5
|
UNSAFE_getAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance>;
|
|
6
6
|
UNSAFE_queryByType: <P>(type: React.ComponentType<P>) => ReactTestInstance | null;
|