@testing-library/react-native 14.0.0-beta.0 → 14.0.0-beta.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 +22 -33
- package/build/event-builder/base.js.map +1 -0
- package/build/event-builder/common.d.ts +152 -0
- package/build/event-builder/common.js +80 -0
- package/build/event-builder/common.js.map +1 -0
- package/build/event-builder/index.d.ts +3 -0
- package/build/event-builder/index.js +39 -0
- package/build/event-builder/index.js.map +1 -0
- package/build/event-builder/scroll.d.ts +56 -0
- package/build/event-builder/scroll.js +51 -0
- package/build/event-builder/scroll.js.map +1 -0
- package/build/event-builder/text.d.ts +162 -0
- package/build/event-builder/text.js +113 -0
- package/build/event-builder/text.js.map +1 -0
- package/build/fire-event.d.ts +6 -5
- package/build/fire-event.js +47 -23
- package/build/fire-event.js.map +1 -1
- package/build/helpers/accessibility.d.ts +18 -15
- package/build/helpers/accessibility.js +64 -47
- package/build/helpers/accessibility.js.map +1 -1
- package/build/helpers/component-tree.d.ts +9 -9
- package/build/helpers/component-tree.js +17 -17
- package/build/helpers/component-tree.js.map +1 -1
- package/build/helpers/find-all.d.ts +2 -2
- package/build/helpers/find-all.js +1 -1
- package/build/helpers/find-all.js.map +1 -1
- package/build/helpers/format-element.d.ts +5 -5
- package/build/helpers/format-element.js +9 -9
- package/build/helpers/format-element.js.map +1 -1
- package/build/helpers/host-component-names.d.ts +13 -13
- package/build/helpers/host-component-names.js +18 -18
- package/build/helpers/host-component-names.js.map +1 -1
- package/build/helpers/matchers/match-accessibility-state.d.ts +2 -2
- package/build/helpers/matchers/match-accessibility-state.js +6 -6
- package/build/helpers/matchers/match-accessibility-state.js.map +1 -1
- package/build/helpers/matchers/match-accessibility-value.d.ts +2 -2
- package/build/helpers/matchers/match-accessibility-value.js +2 -2
- package/build/helpers/matchers/match-accessibility-value.js.map +1 -1
- package/build/helpers/matchers/match-label-text.d.ts +2 -2
- package/build/helpers/matchers/match-label-text.js +2 -2
- package/build/helpers/matchers/match-label-text.js.map +1 -1
- package/build/helpers/matchers/match-text-content.d.ts +5 -5
- package/build/helpers/matchers/match-text-content.js +5 -5
- package/build/helpers/matchers/match-text-content.js.map +1 -1
- package/build/helpers/pointer-events.d.ts +2 -2
- package/build/helpers/pointer-events.js +4 -4
- package/build/helpers/pointer-events.js.map +1 -1
- package/build/helpers/text-content.d.ts +2 -2
- package/build/helpers/text-content.js +5 -5
- package/build/helpers/text-content.js.map +1 -1
- package/build/helpers/text-input.d.ts +3 -3
- package/build/helpers/text-input.js +6 -6
- package/build/helpers/text-input.js.map +1 -1
- package/build/matchers/to-be-busy.d.ts +2 -2
- package/build/matchers/to-be-busy.js +5 -5
- package/build/matchers/to-be-busy.js.map +1 -1
- package/build/matchers/to-be-checked.d.ts +2 -2
- package/build/matchers/to-be-checked.js +9 -9
- package/build/matchers/to-be-checked.js.map +1 -1
- package/build/matchers/to-be-disabled.d.ts +3 -3
- package/build/matchers/to-be-disabled.js +10 -10
- package/build/matchers/to-be-disabled.js.map +1 -1
- package/build/matchers/to-be-empty-element.d.ts +2 -2
- package/build/matchers/to-be-empty-element.js +4 -4
- package/build/matchers/to-be-empty-element.js.map +1 -1
- package/build/matchers/to-be-expanded.d.ts +3 -3
- package/build/matchers/to-be-expanded.js +10 -10
- package/build/matchers/to-be-expanded.js.map +1 -1
- package/build/matchers/to-be-on-the-screen.d.ts +2 -2
- package/build/matchers/to-be-on-the-screen.js +7 -7
- package/build/matchers/to-be-on-the-screen.js.map +1 -1
- package/build/matchers/to-be-partially-checked.d.ts +2 -2
- package/build/matchers/to-be-partially-checked.js +8 -8
- package/build/matchers/to-be-partially-checked.js.map +1 -1
- package/build/matchers/to-be-selected.d.ts +2 -2
- package/build/matchers/to-be-selected.js +4 -4
- package/build/matchers/to-be-selected.js.map +1 -1
- package/build/matchers/to-be-visible.d.ts +2 -2
- package/build/matchers/to-be-visible.js +12 -12
- package/build/matchers/to-be-visible.js.map +1 -1
- package/build/matchers/to-contain-element.d.ts +2 -2
- package/build/matchers/to-contain-element.js +6 -6
- package/build/matchers/to-contain-element.js.map +1 -1
- package/build/matchers/to-have-accessibility-value.d.ts +2 -2
- package/build/matchers/to-have-accessibility-value.js +6 -6
- package/build/matchers/to-have-accessibility-value.js.map +1 -1
- package/build/matchers/to-have-accessible-name.d.ts +2 -2
- package/build/matchers/to-have-accessible-name.js +5 -10
- package/build/matchers/to-have-accessible-name.js.map +1 -1
- package/build/matchers/to-have-display-value.d.ts +2 -2
- package/build/matchers/to-have-display-value.js +6 -6
- package/build/matchers/to-have-display-value.js.map +1 -1
- package/build/matchers/to-have-prop.d.ts +2 -2
- package/build/matchers/to-have-prop.js +6 -6
- package/build/matchers/to-have-prop.js.map +1 -1
- package/build/matchers/to-have-style.d.ts +2 -2
- package/build/matchers/to-have-style.js +5 -5
- package/build/matchers/to-have-style.js.map +1 -1
- package/build/matchers/to-have-text-content.d.ts +2 -2
- package/build/matchers/to-have-text-content.js +4 -4
- package/build/matchers/to-have-text-content.js.map +1 -1
- package/build/matchers/types.d.ts +20 -20
- package/build/matchers/types.js.map +1 -1
- package/build/matchers/utils.d.ts +4 -4
- package/build/matchers/utils.js +6 -6
- package/build/matchers/utils.js.map +1 -1
- package/build/native-state.d.ts +3 -3
- package/build/native-state.js +2 -2
- package/build/native-state.js.map +1 -1
- package/build/queries/display-value.d.ts +2 -2
- package/build/queries/display-value.js +12 -12
- package/build/queries/display-value.js.map +1 -1
- package/build/queries/hint-text.d.ts +2 -2
- package/build/queries/hint-text.js +11 -11
- package/build/queries/hint-text.js.map +1 -1
- package/build/queries/label-text.d.ts +2 -2
- package/build/queries/label-text.js +9 -9
- package/build/queries/label-text.js.map +1 -1
- package/build/queries/make-queries.d.ts +8 -8
- package/build/queries/make-queries.js +11 -11
- package/build/queries/make-queries.js.map +1 -1
- package/build/queries/placeholder-text.d.ts +2 -2
- package/build/queries/placeholder-text.js +11 -11
- package/build/queries/placeholder-text.js.map +1 -1
- package/build/queries/role.d.ts +2 -2
- package/build/queries/role.js +17 -27
- package/build/queries/role.js.map +1 -1
- package/build/queries/test-id.d.ts +2 -2
- package/build/queries/test-id.js +11 -11
- package/build/queries/test-id.js.map +1 -1
- package/build/queries/text.d.ts +2 -2
- package/build/queries/text.js +9 -9
- package/build/queries/text.js.map +1 -1
- package/build/render.d.ts +3 -4
- package/build/render.js +17 -3
- package/build/render.js.map +1 -1
- package/build/screen.js.map +1 -1
- package/build/test-utils/react-version-gates.d.ts +1 -0
- package/build/test-utils/react-version-gates.js +28 -0
- package/build/test-utils/react-version-gates.js.map +1 -0
- package/build/types.d.ts +7 -0
- package/build/types.js.map +1 -1
- package/build/user-event/clear.d.ts +2 -2
- package/build/user-event/clear.js +13 -13
- package/build/user-event/clear.js.map +1 -1
- package/build/user-event/index.d.ts +7 -7
- package/build/user-event/index.js +6 -6
- package/build/user-event/index.js.map +1 -1
- package/build/user-event/paste.d.ts +2 -2
- package/build/user-event/paste.js +18 -18
- package/build/user-event/paste.js.map +1 -1
- package/build/user-event/press/press.d.ts +3 -3
- package/build/user-event/press/press.js +35 -35
- package/build/user-event/press/press.js.map +1 -1
- package/build/user-event/scroll/scroll-to.d.ts +2 -2
- package/build/user-event/scroll/scroll-to.js +20 -20
- package/build/user-event/scroll/scroll-to.js.map +1 -1
- package/build/user-event/setup/setup.d.ts +11 -11
- package/build/user-event/setup/setup.js.map +1 -1
- package/build/user-event/type/type.d.ts +3 -3
- package/build/user-event/type/type.js +27 -28
- package/build/user-event/type/type.js.map +1 -1
- package/build/user-event/utils/dispatch-event.d.ts +3 -3
- package/build/user-event/utils/dispatch-event.js +4 -4
- package/build/user-event/utils/dispatch-event.js.map +1 -1
- package/build/user-event/utils/index.d.ts +0 -1
- package/build/user-event/utils/index.js +0 -11
- package/build/user-event/utils/index.js.map +1 -1
- package/build/within.d.ts +3 -3
- package/build/within.js +10 -10
- package/build/within.js.map +1 -1
- package/package.json +38 -27
- package/build/tsconfig.release.tsbuildinfo +0 -1
- package/build/user-event/event-builder/base.js.map +0 -1
- package/build/user-event/event-builder/common.d.ts +0 -155
- package/build/user-event/event-builder/common.js +0 -77
- package/build/user-event/event-builder/common.js.map +0 -1
- package/build/user-event/event-builder/index.d.ts +0 -318
- package/build/user-event/event-builder/index.js +0 -15
- package/build/user-event/event-builder/index.js.map +0 -1
- package/build/user-event/event-builder/scroll-view.d.ts +0 -58
- package/build/user-event/event-builder/scroll-view.js +0 -53
- package/build/user-event/event-builder/scroll-view.js.map +0 -1
- package/build/user-event/event-builder/text-input.d.ts +0 -165
- package/build/user-event/event-builder/text-input.js +0 -105
- package/build/user-event/event-builder/text-input.js.map +0 -1
- package/build/user-event/utils/text-range.d.ts +0 -4
- package/build/user-event/utils/text-range.js +0 -6
- package/build/user-event/utils/text-range.js.map +0 -1
- /package/build/{user-event/event-builder → event-builder}/base.d.ts +0 -0
- /package/build/{user-event/event-builder → event-builder}/base.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"display-value.js","names":["_findAll","require","_hostComponentNames","_textInput","_matches","_makeQueries","matchDisplayValue","
|
|
1
|
+
{"version":3,"file":"display-value.js","names":["_findAll","require","_hostComponentNames","_textInput","_matches","_makeQueries","matchDisplayValue","instance","expectedValue","options","exact","normalizer","instanceValue","getTextInputValue","matches","queryAllByDisplayValue","queryAllByDisplayValueFn","displayValue","queryOptions","findAll","item","isHostTextInput","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByDisplayValueQueries","getByDisplayValue","getAllByDisplayValue","queryByDisplayValue","findByDisplayValue","findAllByDisplayValue","exports"],"sources":["../../src/queries/display-value.ts"],"sourcesContent":["import type { TestInstance } from 'test-renderer';\n\nimport { findAll } from '../helpers/find-all';\nimport { isHostTextInput } from '../helpers/host-component-names';\nimport { getTextInputValue } from '../helpers/text-input';\nimport type { TextMatch, TextMatchOptions } from '../matches';\nimport { matches } from '../matches';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './make-queries';\nimport { makeQueries } from './make-queries';\nimport type { CommonQueryOptions } from './options';\n\ntype ByDisplayValueOptions = CommonQueryOptions & TextMatchOptions;\n\nconst matchDisplayValue = (\n instance: TestInstance,\n expectedValue: TextMatch,\n options: TextMatchOptions = {},\n) => {\n const { exact, normalizer } = options;\n const instanceValue = getTextInputValue(instance);\n return matches(expectedValue, instanceValue, normalizer, exact);\n};\n\nconst queryAllByDisplayValue = (\n instance: TestInstance,\n): QueryAllByQuery<TextMatch, ByDisplayValueOptions> =>\n function queryAllByDisplayValueFn(displayValue, queryOptions) {\n return findAll(\n instance,\n (item) => isHostTextInput(item) && matchDisplayValue(item, displayValue, queryOptions),\n queryOptions,\n );\n };\n\nconst getMultipleError = (displayValue: TextMatch) =>\n `Found multiple elements with display value: ${String(displayValue)} `;\nconst getMissingError = (displayValue: TextMatch) =>\n `Unable to find an element with displayValue: ${String(displayValue)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByDisplayValue,\n getMissingError,\n getMultipleError,\n);\n\nexport type ByDisplayValueQueries = {\n getByDisplayValue: GetByQuery<TextMatch, ByDisplayValueOptions>;\n getAllByDisplayValue: GetAllByQuery<TextMatch, ByDisplayValueOptions>;\n queryByDisplayValue: QueryByQuery<TextMatch, ByDisplayValueOptions>;\n queryAllByDisplayValue: QueryAllByQuery<TextMatch, ByDisplayValueOptions>;\n findByDisplayValue: FindByQuery<TextMatch, ByDisplayValueOptions>;\n findAllByDisplayValue: FindAllByQuery<TextMatch, ByDisplayValueOptions>;\n};\n\nexport const bindByDisplayValueQueries = (instance: TestInstance): ByDisplayValueQueries => ({\n getByDisplayValue: getBy(instance),\n getAllByDisplayValue: getAllBy(instance),\n queryByDisplayValue: queryBy(instance),\n queryAllByDisplayValue: queryAllBy(instance),\n findByDisplayValue: findBy(instance),\n findAllByDisplayValue: findAllBy(instance),\n});\n"],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EACxC4B,mBAAmB,EAAER,OAAO,CAACpB,QAAQ,CAAC;EACtCQ,sBAAsB,EAAEa,UAAU,CAACrB,QAAQ,CAAC;EAC5C6B,kBAAkB,EAAEP,MAAM,CAACtB,QAAQ,CAAC;EACpC8B,qBAAqB,EAAEP,SAAS,CAACvB,QAAQ;AAC3C,CAAC,CAAC;AAAC+B,OAAA,CAAAN,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TestInstance } from 'test-renderer';
|
|
2
2
|
import type { TextMatch, TextMatchOptions } from '../matches';
|
|
3
3
|
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './make-queries';
|
|
4
4
|
import type { CommonQueryOptions } from './options';
|
|
@@ -23,5 +23,5 @@ export type ByHintTextQueries = {
|
|
|
23
23
|
findByAccessibilityHint: FindByQuery<TextMatch, ByHintTextOptions>;
|
|
24
24
|
findAllByAccessibilityHint: FindAllByQuery<TextMatch, ByHintTextOptions>;
|
|
25
25
|
};
|
|
26
|
-
export declare const bindByHintTextQueries: (
|
|
26
|
+
export declare const bindByHintTextQueries: (instance: TestInstance) => ByHintTextQueries;
|
|
27
27
|
export {};
|
|
@@ -7,15 +7,15 @@ exports.bindByHintTextQueries = void 0;
|
|
|
7
7
|
var _findAll = require("../helpers/find-all");
|
|
8
8
|
var _matches = require("../matches");
|
|
9
9
|
var _makeQueries = require("./make-queries");
|
|
10
|
-
const
|
|
10
|
+
const getInstanceByHintText = (instance, text, options = {}) => {
|
|
11
11
|
const {
|
|
12
12
|
exact,
|
|
13
13
|
normalizer
|
|
14
14
|
} = options;
|
|
15
|
-
return (0, _matches.matches)(text,
|
|
15
|
+
return (0, _matches.matches)(text, instance.props.accessibilityHint, normalizer, exact);
|
|
16
16
|
};
|
|
17
|
-
const queryAllByHintText =
|
|
18
|
-
return (0, _findAll.findAll)(
|
|
17
|
+
const queryAllByHintText = instance => function queryAllByA11yHintFn(hint, queryOptions) {
|
|
18
|
+
return (0, _findAll.findAll)(instance, item => getInstanceByHintText(item, hint, queryOptions), queryOptions);
|
|
19
19
|
};
|
|
20
20
|
const getMultipleError = hint => `Found multiple elements with accessibility hint: ${String(hint)} `;
|
|
21
21
|
const getMissingError = hint => `Unable to find an element with accessibility hint: ${String(hint)}`;
|
|
@@ -27,13 +27,13 @@ const {
|
|
|
27
27
|
findBy,
|
|
28
28
|
findAllBy
|
|
29
29
|
} = (0, _makeQueries.makeQueries)(queryAllByHintText, getMissingError, getMultipleError);
|
|
30
|
-
const bindByHintTextQueries =
|
|
31
|
-
const getByHintText = getBy(
|
|
32
|
-
const getAllByHintText = getAllBy(
|
|
33
|
-
const queryByHintText = queryBy(
|
|
34
|
-
const queryAllByHintText = queryAllBy(
|
|
35
|
-
const findByHintText = findBy(
|
|
36
|
-
const findAllByHintText = findAllBy(
|
|
30
|
+
const bindByHintTextQueries = instance => {
|
|
31
|
+
const getByHintText = getBy(instance);
|
|
32
|
+
const getAllByHintText = getAllBy(instance);
|
|
33
|
+
const queryByHintText = queryBy(instance);
|
|
34
|
+
const queryAllByHintText = queryAllBy(instance);
|
|
35
|
+
const findByHintText = findBy(instance);
|
|
36
|
+
const findAllByHintText = findAllBy(instance);
|
|
37
37
|
return {
|
|
38
38
|
getByHintText,
|
|
39
39
|
getAllByHintText,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hint-text.js","names":["_findAll","require","_matches","_makeQueries","
|
|
1
|
+
{"version":3,"file":"hint-text.js","names":["_findAll","require","_matches","_makeQueries","getInstanceByHintText","instance","text","options","exact","normalizer","matches","props","accessibilityHint","queryAllByHintText","queryAllByA11yHintFn","hint","queryOptions","findAll","item","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByHintTextQueries","getByHintText","getAllByHintText","queryByHintText","findByHintText","findAllByHintText","getByA11yHint","getAllByA11yHint","queryByA11yHint","queryAllByA11yHint","findByA11yHint","findAllByA11yHint","getByAccessibilityHint","getAllByAccessibilityHint","queryByAccessibilityHint","queryAllByAccessibilityHint","findByAccessibilityHint","findAllByAccessibilityHint","exports"],"sources":["../../src/queries/hint-text.ts"],"sourcesContent":["import type { TestInstance } from 'test-renderer';\n\nimport { findAll } from '../helpers/find-all';\nimport type { TextMatch, TextMatchOptions } from '../matches';\nimport { matches } from '../matches';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './make-queries';\nimport { makeQueries } from './make-queries';\nimport type { CommonQueryOptions } from './options';\n\ntype ByHintTextOptions = CommonQueryOptions & TextMatchOptions;\n\nconst getInstanceByHintText = (\n instance: TestInstance,\n text: TextMatch,\n options: TextMatchOptions = {},\n) => {\n const { exact, normalizer } = options;\n return matches(text, instance.props.accessibilityHint, normalizer, exact);\n};\n\nconst queryAllByHintText = (\n instance: TestInstance,\n): QueryAllByQuery<TextMatch, ByHintTextOptions> =>\n function queryAllByA11yHintFn(hint, queryOptions) {\n return findAll(\n instance,\n (item) => getInstanceByHintText(item, hint, queryOptions),\n queryOptions,\n );\n };\n\nconst getMultipleError = (hint: TextMatch) =>\n `Found multiple elements with accessibility hint: ${String(hint)} `;\nconst getMissingError = (hint: TextMatch) =>\n `Unable to find an element with accessibility hint: ${String(hint)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByHintText,\n getMissingError,\n getMultipleError,\n);\n\nexport type ByHintTextQueries = {\n getByHintText: GetByQuery<TextMatch, ByHintTextOptions>;\n getAllByHintText: GetAllByQuery<TextMatch, ByHintTextOptions>;\n queryByHintText: QueryByQuery<TextMatch, ByHintTextOptions>;\n queryAllByHintText: QueryAllByQuery<TextMatch, ByHintTextOptions>;\n findByHintText: FindByQuery<TextMatch, ByHintTextOptions>;\n findAllByHintText: FindAllByQuery<TextMatch, ByHintTextOptions>;\n\n // a11yHint aliases\n getByA11yHint: GetByQuery<TextMatch, ByHintTextOptions>;\n getAllByA11yHint: GetAllByQuery<TextMatch, ByHintTextOptions>;\n queryByA11yHint: QueryByQuery<TextMatch, ByHintTextOptions>;\n queryAllByA11yHint: QueryAllByQuery<TextMatch, ByHintTextOptions>;\n findByA11yHint: FindByQuery<TextMatch, ByHintTextOptions>;\n findAllByA11yHint: FindAllByQuery<TextMatch, ByHintTextOptions>;\n\n // accessibilityHint aliases\n getByAccessibilityHint: GetByQuery<TextMatch, ByHintTextOptions>;\n getAllByAccessibilityHint: GetAllByQuery<TextMatch, ByHintTextOptions>;\n queryByAccessibilityHint: QueryByQuery<TextMatch, ByHintTextOptions>;\n queryAllByAccessibilityHint: QueryAllByQuery<TextMatch, ByHintTextOptions>;\n findByAccessibilityHint: FindByQuery<TextMatch, ByHintTextOptions>;\n findAllByAccessibilityHint: FindAllByQuery<TextMatch, ByHintTextOptions>;\n};\n\nexport const bindByHintTextQueries = (instance: TestInstance): ByHintTextQueries => {\n const getByHintText = getBy(instance);\n const getAllByHintText = getAllBy(instance);\n const queryByHintText = queryBy(instance);\n const queryAllByHintText = queryAllBy(instance);\n const findByHintText = findBy(instance);\n const findAllByHintText = findAllBy(instance);\n\n return {\n getByHintText,\n getAllByHintText,\n queryByHintText,\n queryAllByHintText,\n findByHintText,\n findAllByHintText,\n\n // a11yHint aliases\n getByA11yHint: getByHintText,\n getAllByA11yHint: getAllByHintText,\n queryByA11yHint: queryByHintText,\n queryAllByA11yHint: queryAllByHintText,\n findByA11yHint: findByHintText,\n findAllByA11yHint: findAllByHintText,\n\n // accessibilityHint aliases\n getByAccessibilityHint: getByHintText,\n getAllByAccessibilityHint: getAllByHintText,\n queryByAccessibilityHint: queryByHintText,\n queryAllByAccessibilityHint: queryAllByHintText,\n findByAccessibilityHint: findByHintText,\n findAllByAccessibilityHint: findAllByHintText,\n };\n};\n"],"mappings":";;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AAE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AM6B,iBAAiB,GAAGP,SAAS,CAACtB,QAAQ,CAAC;EAE7C,OAAO;IACLyB,aAAa;IACbC,gBAAgB;IAChBC,eAAe;IACfnB,kBAAkB;IAClBoB,cAAc;IACdC,iBAAiB;IAEjB;IACAC,aAAa,EAAEL,aAAa;IAC5BM,gBAAgB,EAAEL,gBAAgB;IAClCM,eAAe,EAAEL,eAAe;IAChCM,kBAAkB,EAAEzB,kBAAkB;IACtC0B,cAAc,EAAEN,cAAc;IAC9BO,iBAAiB,EAAEN,iBAAiB;IAEpC;IACAO,sBAAsB,EAAEX,aAAa;IACrCY,yBAAyB,EAAEX,gBAAgB;IAC3CY,wBAAwB,EAAEX,eAAe;IACzCY,2BAA2B,EAAE/B,kBAAkB;IAC/CgC,uBAAuB,EAAEZ,cAAc;IACvCa,0BAA0B,EAAEZ;EAC9B,CAAC;AACH,CAAC;AAACa,OAAA,CAAAlB,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TestInstance } from 'test-renderer';
|
|
2
2
|
import type { TextMatch, TextMatchOptions } from '../matches';
|
|
3
3
|
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './make-queries';
|
|
4
4
|
import type { CommonQueryOptions } from './options';
|
|
@@ -11,5 +11,5 @@ export type ByLabelTextQueries = {
|
|
|
11
11
|
findByLabelText: FindByQuery<TextMatch, ByLabelTextOptions>;
|
|
12
12
|
findAllByLabelText: FindAllByQuery<TextMatch, ByLabelTextOptions>;
|
|
13
13
|
};
|
|
14
|
-
export declare const bindByLabelTextQueries: (
|
|
14
|
+
export declare const bindByLabelTextQueries: (instance: TestInstance) => ByLabelTextQueries;
|
|
15
15
|
export {};
|
|
@@ -7,9 +7,9 @@ exports.bindByLabelTextQueries = void 0;
|
|
|
7
7
|
var _findAll = require("../helpers/find-all");
|
|
8
8
|
var _matchLabelText = require("../helpers/matchers/match-label-text");
|
|
9
9
|
var _makeQueries = require("./make-queries");
|
|
10
|
-
function queryAllByLabelText(
|
|
10
|
+
function queryAllByLabelText(instance) {
|
|
11
11
|
return (text, queryOptions) => {
|
|
12
|
-
return (0, _findAll.findAll)(
|
|
12
|
+
return (0, _findAll.findAll)(instance, item => (0, _matchLabelText.matchAccessibilityLabel)(item, text, queryOptions), queryOptions);
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
const getMultipleError = labelText => `Found multiple elements with accessibility label: ${String(labelText)} `;
|
|
@@ -22,13 +22,13 @@ const {
|
|
|
22
22
|
findBy,
|
|
23
23
|
findAllBy
|
|
24
24
|
} = (0, _makeQueries.makeQueries)(queryAllByLabelText, getMissingError, getMultipleError);
|
|
25
|
-
const bindByLabelTextQueries =
|
|
26
|
-
getByLabelText: getBy(
|
|
27
|
-
getAllByLabelText: getAllBy(
|
|
28
|
-
queryByLabelText: queryBy(
|
|
29
|
-
queryAllByLabelText: queryAllBy(
|
|
30
|
-
findByLabelText: findBy(
|
|
31
|
-
findAllByLabelText: findAllBy(
|
|
25
|
+
const bindByLabelTextQueries = instance => ({
|
|
26
|
+
getByLabelText: getBy(instance),
|
|
27
|
+
getAllByLabelText: getAllBy(instance),
|
|
28
|
+
queryByLabelText: queryBy(instance),
|
|
29
|
+
queryAllByLabelText: queryAllBy(instance),
|
|
30
|
+
findByLabelText: findBy(instance),
|
|
31
|
+
findAllByLabelText: findAllBy(instance)
|
|
32
32
|
});
|
|
33
33
|
exports.bindByLabelTextQueries = bindByLabelTextQueries;
|
|
34
34
|
//# sourceMappingURL=label-text.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"label-text.js","names":["_findAll","require","_matchLabelText","_makeQueries","queryAllByLabelText","
|
|
1
|
+
{"version":3,"file":"label-text.js","names":["_findAll","require","_matchLabelText","_makeQueries","queryAllByLabelText","instance","text","queryOptions","findAll","item","matchAccessibilityLabel","getMultipleError","labelText","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByLabelTextQueries","getByLabelText","getAllByLabelText","queryByLabelText","findByLabelText","findAllByLabelText","exports"],"sources":["../../src/queries/label-text.ts"],"sourcesContent":["import type { TestInstance } from 'test-renderer';\n\nimport { findAll } from '../helpers/find-all';\nimport { matchAccessibilityLabel } from '../helpers/matchers/match-label-text';\nimport type { TextMatch, TextMatchOptions } from '../matches';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './make-queries';\nimport { makeQueries } from './make-queries';\nimport type { CommonQueryOptions } from './options';\n\ntype ByLabelTextOptions = CommonQueryOptions & TextMatchOptions;\n\nfunction queryAllByLabelText(instance: TestInstance) {\n return (text: TextMatch, queryOptions?: ByLabelTextOptions) => {\n return findAll(\n instance,\n (item) => matchAccessibilityLabel(item, text, queryOptions),\n queryOptions,\n );\n };\n}\n\nconst getMultipleError = (labelText: TextMatch) =>\n `Found multiple elements with accessibility label: ${String(labelText)} `;\nconst getMissingError = (labelText: TextMatch) =>\n `Unable to find an element with accessibility label: ${String(labelText)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByLabelText,\n getMissingError,\n getMultipleError,\n);\n\nexport type ByLabelTextQueries = {\n getByLabelText: GetByQuery<TextMatch, ByLabelTextOptions>;\n getAllByLabelText: GetAllByQuery<TextMatch, ByLabelTextOptions>;\n queryByLabelText: QueryByQuery<TextMatch, ByLabelTextOptions>;\n queryAllByLabelText: QueryAllByQuery<TextMatch, ByLabelTextOptions>;\n findByLabelText: FindByQuery<TextMatch, ByLabelTextOptions>;\n findAllByLabelText: FindAllByQuery<TextMatch, ByLabelTextOptions>;\n};\n\nexport const bindByLabelTextQueries = (instance: TestInstance): ByLabelTextQueries => ({\n getByLabelText: getBy(instance),\n getAllByLabelText: getAllBy(instance),\n queryByLabelText: queryBy(instance),\n queryAllByLabelText: queryAllBy(instance),\n findByLabelText: findBy(instance),\n findAllByLabelText: findAllBy(instance),\n});\n"],"mappings":";;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAUA,IAAAE,YAAA,GAAAF,OAAA;AAKA,SAASG,mBAAmBA,CAACC,QAAsB,EAAE;EACnD,OAAO,CAACC,IAAe,EAAEC,YAAiC,KAAK;IAC7D,OAAO,IAAAC,gBAAO,EACZH,QAAQ,EACPI,IAAI,IAAK,IAAAC,uCAAuB,EAACD,IAAI,EAAEH,IAAI,EAAEC,YAAY,CAAC,EAC3DA,YACF,CAAC;EACH,CAAC;AACH;AAEA,MAAMI,gBAAgB,GAAIC,SAAoB,IAC5C,qDAAqDC,MAAM,CAACD,SAAS,CAAC,GAAG;AAC3E,MAAME,eAAe,GAAIF,SAAoB,IAC3C,uDAAuDC,MAAM,CAACD,SAAS,CAAC,EAAE;AAE5E,MAAM;EAAEG,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7EjB,mBAAmB,EACnBU,eAAe,EACfH,gBACF,CAAC;AAWM,MAAMW,sBAAsB,GAAIjB,QAAsB,KAA0B;EACrFkB,cAAc,EAAER,KAAK,CAACV,QAAQ,CAAC;EAC/BmB,iBAAiB,EAAER,QAAQ,CAACX,QAAQ,CAAC;EACrCoB,gBAAgB,EAAER,OAAO,CAACZ,QAAQ,CAAC;EACnCD,mBAAmB,EAAEc,UAAU,CAACb,QAAQ,CAAC;EACzCqB,eAAe,EAAEP,MAAM,CAACd,QAAQ,CAAC;EACjCsB,kBAAkB,EAAEP,SAAS,CAACf,QAAQ;AACxC,CAAC,CAAC;AAACuB,OAAA,CAAAN,sBAAA,GAAAA,sBAAA","ignoreList":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TestInstance } from 'test-renderer';
|
|
2
2
|
import type { WaitForOptions } from '../wait-for';
|
|
3
|
-
export type GetByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options) =>
|
|
4
|
-
export type GetAllByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options) =>
|
|
5
|
-
export type QueryByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options) =>
|
|
6
|
-
export type QueryAllByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options) =>
|
|
7
|
-
export type FindByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options & WaitForOptions, waitForOptions?: WaitForOptions) => Promise<
|
|
8
|
-
export type FindAllByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options & WaitForOptions, waitForOptions?: WaitForOptions) => Promise<
|
|
9
|
-
type UnboundQuery<Query> = (
|
|
3
|
+
export type GetByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options) => TestInstance;
|
|
4
|
+
export type GetAllByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options) => TestInstance[];
|
|
5
|
+
export type QueryByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options) => TestInstance | null;
|
|
6
|
+
export type QueryAllByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options) => TestInstance[];
|
|
7
|
+
export type FindByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options & WaitForOptions, waitForOptions?: WaitForOptions) => Promise<TestInstance>;
|
|
8
|
+
export type FindAllByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options & WaitForOptions, waitForOptions?: WaitForOptions) => Promise<TestInstance[]>;
|
|
9
|
+
type UnboundQuery<Query> = (instance: TestInstance) => Query;
|
|
10
10
|
export type UnboundQueries<Predicate, Options> = {
|
|
11
11
|
getBy: UnboundQuery<GetByQuery<Predicate, Options>>;
|
|
12
12
|
getAllBy: UnboundQuery<GetAllByQuery<Predicate, Options>>;
|
|
@@ -38,7 +38,7 @@ function formatErrorMessage(message, printElementTree) {
|
|
|
38
38
|
return message;
|
|
39
39
|
}
|
|
40
40
|
if (_screen.screen.isDetached) {
|
|
41
|
-
return `${message}\n\nScreen is no longer attached. Check your test for "findBy*" or "waitFor" calls that have not been awaited.\n\nWe recommend enabling "eslint-plugin-testing-library" to catch these issues at build time:\nhttps://callstack.
|
|
41
|
+
return `${message}\n\nScreen is no longer attached. Check your test for "findBy*" or "waitFor" calls that have not been awaited.\n\nWe recommend enabling "eslint-plugin-testing-library" to catch these issues at build time:\nhttps://oss.callstack.com/react-native-testing-library/docs/start/quick-start#eslint-plugin`;
|
|
42
42
|
}
|
|
43
43
|
const json = _screen.screen.toJSON();
|
|
44
44
|
if (!json) {
|
|
@@ -55,11 +55,11 @@ function appendElementTreeToError(error) {
|
|
|
55
55
|
return error;
|
|
56
56
|
}
|
|
57
57
|
function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
|
|
58
|
-
function getAllByQuery(
|
|
58
|
+
function getAllByQuery(instance, {
|
|
59
59
|
printElementTree = true
|
|
60
60
|
} = {}) {
|
|
61
61
|
return function getAllFn(predicate, options) {
|
|
62
|
-
const results = queryAllByQuery(
|
|
62
|
+
const results = queryAllByQuery(instance)(predicate, options);
|
|
63
63
|
if (results.length === 0) {
|
|
64
64
|
const errorMessage = formatErrorMessage(getMissingError(predicate, options), printElementTree);
|
|
65
65
|
throw new _errors.ErrorWithStack(errorMessage, getAllFn);
|
|
@@ -67,11 +67,11 @@ function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
|
|
|
67
67
|
return results;
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
-
function queryByQuery(
|
|
70
|
+
function queryByQuery(instance, {
|
|
71
71
|
printElementTree = true
|
|
72
72
|
} = {}) {
|
|
73
73
|
return function singleQueryFn(predicate, options) {
|
|
74
|
-
const results = queryAllByQuery(
|
|
74
|
+
const results = queryAllByQuery(instance)(predicate, options);
|
|
75
75
|
if (results.length > 1) {
|
|
76
76
|
throw new _errors.ErrorWithStack(formatErrorMessage(getMultipleError(predicate, options), printElementTree), singleQueryFn);
|
|
77
77
|
}
|
|
@@ -81,11 +81,11 @@ function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
|
|
|
81
81
|
return results[0];
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
-
function getByQuery(
|
|
84
|
+
function getByQuery(instance, {
|
|
85
85
|
printElementTree = true
|
|
86
86
|
} = {}) {
|
|
87
87
|
return function getFn(predicate, options) {
|
|
88
|
-
const results = queryAllByQuery(
|
|
88
|
+
const results = queryAllByQuery(instance)(predicate, options);
|
|
89
89
|
if (results.length > 1) {
|
|
90
90
|
throw new _errors.ErrorWithStack(getMultipleError(predicate, options), getFn);
|
|
91
91
|
}
|
|
@@ -96,14 +96,14 @@ function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
|
|
|
96
96
|
return results[0];
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
|
-
function findAllByQuery(
|
|
99
|
+
function findAllByQuery(instance) {
|
|
100
100
|
return function findAllFn(predicate, queryOptions, {
|
|
101
101
|
onTimeout = error => appendElementTreeToError(error),
|
|
102
102
|
...waitForOptions
|
|
103
103
|
} = {}) {
|
|
104
104
|
const stackTraceError = new _errors.ErrorWithStack('STACK_TRACE_ERROR', findAllFn);
|
|
105
105
|
const deprecatedWaitForOptions = extractDeprecatedWaitForOptions(queryOptions);
|
|
106
|
-
return (0, _waitFor.waitFor)(() => getAllByQuery(
|
|
106
|
+
return (0, _waitFor.waitFor)(() => getAllByQuery(instance, {
|
|
107
107
|
printElementTree: false
|
|
108
108
|
})(predicate, queryOptions), {
|
|
109
109
|
...deprecatedWaitForOptions,
|
|
@@ -113,14 +113,14 @@ function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
|
|
|
113
113
|
});
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
|
-
function findByQuery(
|
|
116
|
+
function findByQuery(instance) {
|
|
117
117
|
return function findFn(predicate, queryOptions, {
|
|
118
118
|
onTimeout = error => appendElementTreeToError(error),
|
|
119
119
|
...waitForOptions
|
|
120
120
|
} = {}) {
|
|
121
121
|
const stackTraceError = new _errors.ErrorWithStack('STACK_TRACE_ERROR', findFn);
|
|
122
122
|
const deprecatedWaitForOptions = extractDeprecatedWaitForOptions(queryOptions);
|
|
123
|
-
return (0, _waitFor.waitFor)(() => getByQuery(
|
|
123
|
+
return (0, _waitFor.waitFor)(() => getByQuery(instance, {
|
|
124
124
|
printElementTree: false
|
|
125
125
|
})(predicate, queryOptions), {
|
|
126
126
|
...deprecatedWaitForOptions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-queries.js","names":["_errors","require","_formatElement","_logger","_screen","_waitFor","deprecatedKeys","extractDeprecatedWaitForOptions","options","undefined","waitForOptions","timeout","interval","stackTraceError","forEach","key","option","logger","warn","toString","formatErrorMessage","message","printElementTree","screen","isDetached","json","toJSON","formatJson","appendElementTreeToError","error","oldMessage","stack","replace","makeQueries","queryAllByQuery","getMissingError","getMultipleError","getAllByQuery","element","getAllFn","predicate","results","length","errorMessage","ErrorWithStack","queryByQuery","singleQueryFn","getByQuery","getFn","findAllByQuery","findAllFn","queryOptions","onTimeout","deprecatedWaitForOptions","waitFor","findByQuery","findFn","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy"],"sources":["../../src/queries/make-queries.ts"],"sourcesContent":["import type { HostElement } from 'test-renderer';\n\nimport { ErrorWithStack } from '../helpers/errors';\nimport { formatJson } from '../helpers/format-element';\nimport { logger } from '../helpers/logger';\nimport { screen } from '../screen';\nimport type { WaitForOptions } from '../wait-for';\nimport { waitFor } from '../wait-for';\n\nexport type GetByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options,\n) => HostElement;\n\nexport type GetAllByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options,\n) => HostElement[];\n\nexport type QueryByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options,\n) => HostElement | null;\n\nexport type QueryAllByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options,\n) => HostElement[];\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<HostElement>;\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<HostElement[]>;\n\ntype UnboundQuery<Query> = (element: HostElement) => 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)[] = ['timeout', 'interval', 'stackTraceError'];\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 logger.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\nfunction formatErrorMessage(message: string, printElementTree: boolean) {\n if (!printElementTree) {\n return message;\n }\n\n if (screen.isDetached) {\n return `${message}\\n\\nScreen is no longer attached. Check your test for \"findBy*\" or \"waitFor\" calls that have not been awaited.\\n\\nWe recommend enabling \"eslint-plugin-testing-library\" to catch these issues at build time:\\nhttps://callstack.github.io/react-native-testing-library/docs/start/quick-start#eslint-plugin`;\n }\n\n const json = screen.toJSON();\n if (!json) {\n return message;\n }\n\n return `${message}\\n\\n${formatJson(json)}`;\n}\n\nfunction appendElementTreeToError(error: Error) {\n const oldMessage = error.message;\n error.message = formatErrorMessage(oldMessage, true);\n\n // Required to make Jest print the element tree on error\n error.stack = error.stack?.replace(oldMessage, error.message);\n\n return error;\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(element: HostElement, { printElementTree = true } = {}) {\n return function getAllFn(predicate: Predicate, options?: Options) {\n const results = queryAllByQuery(element)(predicate, options);\n\n if (results.length === 0) {\n const errorMessage = formatErrorMessage(\n getMissingError(predicate, options),\n printElementTree,\n );\n throw new ErrorWithStack(errorMessage, getAllFn);\n }\n\n return results;\n };\n }\n\n function queryByQuery(element: HostElement, { printElementTree = true } = {}) {\n return function singleQueryFn(predicate: Predicate, options?: Options) {\n const results = queryAllByQuery(element)(predicate, options);\n\n if (results.length > 1) {\n throw new ErrorWithStack(\n formatErrorMessage(getMultipleError(predicate, options), printElementTree),\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(element: HostElement, { printElementTree = true } = {}) {\n return function getFn(predicate: Predicate, options?: Options) {\n const results = queryAllByQuery(element)(predicate, options);\n\n if (results.length > 1) {\n throw new ErrorWithStack(getMultipleError(predicate, options), getFn);\n }\n\n if (results.length === 0) {\n const errorMessage = formatErrorMessage(\n getMissingError(predicate, options),\n printElementTree,\n );\n throw new ErrorWithStack(errorMessage, getFn);\n }\n\n return results[0];\n };\n }\n\n function findAllByQuery(element: HostElement) {\n return function findAllFn(\n predicate: Predicate,\n queryOptions?: Options & WaitForOptions,\n {\n onTimeout = (error) => appendElementTreeToError(error),\n ...waitForOptions\n }: WaitForOptions = {},\n ) {\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', findAllFn);\n const deprecatedWaitForOptions = extractDeprecatedWaitForOptions(queryOptions);\n\n return waitFor(\n () => getAllByQuery(element, { printElementTree: false })(predicate, queryOptions),\n {\n ...deprecatedWaitForOptions,\n ...waitForOptions,\n stackTraceError,\n onTimeout,\n },\n );\n };\n }\n\n function findByQuery(element: HostElement) {\n return function findFn(\n predicate: Predicate,\n queryOptions?: Options & WaitForOptions,\n {\n onTimeout = (error) => appendElementTreeToError(error),\n ...waitForOptions\n }: WaitForOptions = {},\n ) {\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', findFn);\n const deprecatedWaitForOptions = extractDeprecatedWaitForOptions(queryOptions);\n\n return waitFor(\n () => getByQuery(element, { printElementTree: false })(predicate, queryOptions),\n {\n ...deprecatedWaitForOptions,\n ...waitForOptions,\n stackTraceError,\n onTimeout,\n },\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":";;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAEA,IAAAI,QAAA,GAAAJ,OAAA;AA+CA,MAAMK,cAAwC,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,iBAAiB,CAAC;;AAE3F;AACA;AACA,SAASC,+BAA+BA,CAACC,OAAwB,EAAE;EACjE,IAAI,CAACA,OAAO,EAAE;IACZ,OAAOC,SAAS;EAClB;EAEA,MAAMC,cAA8B,GAAG;IACrCC,OAAO,EAAEH,OAAO,CAACG,OAAO;IAC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AAC,mBAAmB,EAAEY,MAAM,CAAC;MACvE,MAAMH,wBAAwB,GAAG9C,+BAA+B,CAAC4C,YAAY,CAAC;MAE9E,OAAO,IAAAG,gBAAO,EACZ,MAAMP,UAAU,CAACT,OAAO,EAAE;QAAEhB,gBAAgB,EAAE;MAAM,CAAC,CAAC,CAACkB,SAAS,EAAEW,YAAY,CAAC,EAC/E;QACE,GAAGE,wBAAwB;QAC3B,GAAG3C,cAAc;QACjBG,eAAe;QACfuC;MACF,CACF,CAAC;IACH,CAAC;EACH;EAEA,OAAO;IACLK,KAAK,EAAEV,UAAU;IACjBW,QAAQ,EAAErB,aAAa;IACvBsB,OAAO,EAAEd,YAAY;IACrBe,UAAU,EAAE1B,eAAe;IAC3B2B,MAAM,EAAEN,WAAW;IACnBO,SAAS,EAAEb;EACb,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"make-queries.js","names":["_errors","require","_formatElement","_logger","_screen","_waitFor","deprecatedKeys","extractDeprecatedWaitForOptions","options","undefined","waitForOptions","timeout","interval","stackTraceError","forEach","key","option","logger","warn","toString","formatErrorMessage","message","printElementTree","screen","isDetached","json","toJSON","formatJson","appendElementTreeToError","error","oldMessage","stack","replace","makeQueries","queryAllByQuery","getMissingError","getMultipleError","getAllByQuery","instance","getAllFn","predicate","results","length","errorMessage","ErrorWithStack","queryByQuery","singleQueryFn","getByQuery","getFn","findAllByQuery","findAllFn","queryOptions","onTimeout","deprecatedWaitForOptions","waitFor","findByQuery","findFn","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy"],"sources":["../../src/queries/make-queries.ts"],"sourcesContent":["import type { TestInstance } from 'test-renderer';\n\nimport { ErrorWithStack } from '../helpers/errors';\nimport { formatJson } from '../helpers/format-element';\nimport { logger } from '../helpers/logger';\nimport { screen } from '../screen';\nimport type { WaitForOptions } from '../wait-for';\nimport { waitFor } from '../wait-for';\n\nexport type GetByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options,\n) => TestInstance;\n\nexport type GetAllByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options,\n) => TestInstance[];\n\nexport type QueryByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options,\n) => TestInstance | null;\n\nexport type QueryAllByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options,\n) => TestInstance[];\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<TestInstance>;\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<TestInstance[]>;\n\ntype UnboundQuery<Query> = (instance: TestInstance) => 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)[] = ['timeout', 'interval', 'stackTraceError'];\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 logger.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\nfunction formatErrorMessage(message: string, printElementTree: boolean) {\n if (!printElementTree) {\n return message;\n }\n\n if (screen.isDetached) {\n return `${message}\\n\\nScreen is no longer attached. Check your test for \"findBy*\" or \"waitFor\" calls that have not been awaited.\\n\\nWe recommend enabling \"eslint-plugin-testing-library\" to catch these issues at build time:\\nhttps://oss.callstack.com/react-native-testing-library/docs/start/quick-start#eslint-plugin`;\n }\n\n const json = screen.toJSON();\n if (!json) {\n return message;\n }\n\n return `${message}\\n\\n${formatJson(json)}`;\n}\n\nfunction appendElementTreeToError(error: Error) {\n const oldMessage = error.message;\n error.message = formatErrorMessage(oldMessage, true);\n\n // Required to make Jest print the element tree on error\n error.stack = error.stack?.replace(oldMessage, error.message);\n\n return error;\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: TestInstance, { printElementTree = true } = {}) {\n return function getAllFn(predicate: Predicate, options?: Options) {\n const results = queryAllByQuery(instance)(predicate, options);\n\n if (results.length === 0) {\n const errorMessage = formatErrorMessage(\n getMissingError(predicate, options),\n printElementTree,\n );\n throw new ErrorWithStack(errorMessage, getAllFn);\n }\n\n return results;\n };\n }\n\n function queryByQuery(instance: TestInstance, { printElementTree = true } = {}) {\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 formatErrorMessage(getMultipleError(predicate, options), printElementTree),\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: TestInstance, { printElementTree = true } = {}) {\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 const errorMessage = formatErrorMessage(\n getMissingError(predicate, options),\n printElementTree,\n );\n throw new ErrorWithStack(errorMessage, getFn);\n }\n\n return results[0];\n };\n }\n\n function findAllByQuery(instance: TestInstance) {\n return function findAllFn(\n predicate: Predicate,\n queryOptions?: Options & WaitForOptions,\n {\n onTimeout = (error) => appendElementTreeToError(error),\n ...waitForOptions\n }: WaitForOptions = {},\n ) {\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', findAllFn);\n const deprecatedWaitForOptions = extractDeprecatedWaitForOptions(queryOptions);\n\n return waitFor(\n () => getAllByQuery(instance, { printElementTree: false })(predicate, queryOptions),\n {\n ...deprecatedWaitForOptions,\n ...waitForOptions,\n stackTraceError,\n onTimeout,\n },\n );\n };\n }\n\n function findByQuery(instance: TestInstance) {\n return function findFn(\n predicate: Predicate,\n queryOptions?: Options & WaitForOptions,\n {\n onTimeout = (error) => appendElementTreeToError(error),\n ...waitForOptions\n }: WaitForOptions = {},\n ) {\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', findFn);\n const deprecatedWaitForOptions = extractDeprecatedWaitForOptions(queryOptions);\n\n return waitFor(\n () => getByQuery(instance, { printElementTree: false })(predicate, queryOptions),\n {\n ...deprecatedWaitForOptions,\n ...waitForOptions,\n stackTraceError,\n onTimeout,\n },\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":";;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAEA,IAAAI,QAAA,GAAAJ,OAAA;AA+CA,M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AASG,WAAWA,CAACjB,QAAsB,EAAE;IAC3C,OAAO,SAASkB,MAAMA,CACpBhB,SAAoB,EACpBW,YAAuC,EACvC;MACEC,SAAS,GAAIvB,KAAK,IAAKD,wBAAwB,CAACC,KAAK,CAAC;MACtD,GAAGnB;IACW,CAAC,GAAG,CAAC,CAAC,EACtB;MACA,MAAMG,eAAe,GAAG,IAAI+B,sBAAc,CAAC,mBAAmB,EAAEY,MAAM,CAAC;MACvE,MAAMH,wBAAwB,GAAG9C,+BAA+B,CAAC4C,YAAY,CAAC;MAE9E,OAAO,IAAAG,gBAAO,EACZ,MAAMP,UAAU,CAACT,QAAQ,EAAE;QAAEhB,gBAAgB,EAAE;MAAM,CAAC,CAAC,CAACkB,SAAS,EAAEW,YAAY,CAAC,EAChF;QACE,GAAGE,wBAAwB;QAC3B,GAAG3C,cAAc;QACjBG,eAAe;QACfuC;MACF,CACF,CAAC;IACH,CAAC;EACH;EAEA,OAAO;IACLK,KAAK,EAAEV,UAAU;IACjBW,QAAQ,EAAErB,aAAa;IACvBsB,OAAO,EAAEd,YAAY;IACrBe,UAAU,EAAE1B,eAAe;IAC3B2B,MAAM,EAAEN,WAAW;IACnBO,SAAS,EAAEb;EACb,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TestInstance } from 'test-renderer';
|
|
2
2
|
import type { TextMatch, TextMatchOptions } from '../matches';
|
|
3
3
|
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './make-queries';
|
|
4
4
|
import type { CommonQueryOptions } from './options';
|
|
@@ -11,5 +11,5 @@ export type ByPlaceholderTextQueries = {
|
|
|
11
11
|
findByPlaceholderText: FindByQuery<TextMatch, ByPlaceholderTextOptions>;
|
|
12
12
|
findAllByPlaceholderText: FindAllByQuery<TextMatch, ByPlaceholderTextOptions>;
|
|
13
13
|
};
|
|
14
|
-
export declare const bindByPlaceholderTextQueries: (
|
|
14
|
+
export declare const bindByPlaceholderTextQueries: (instance: TestInstance) => ByPlaceholderTextQueries;
|
|
15
15
|
export {};
|
|
@@ -8,15 +8,15 @@ var _findAll = require("../helpers/find-all");
|
|
|
8
8
|
var _hostComponentNames = require("../helpers/host-component-names");
|
|
9
9
|
var _matches = require("../matches");
|
|
10
10
|
var _makeQueries = require("./make-queries");
|
|
11
|
-
const matchPlaceholderText = (
|
|
11
|
+
const matchPlaceholderText = (instance, placeholder, options = {}) => {
|
|
12
12
|
const {
|
|
13
13
|
exact,
|
|
14
14
|
normalizer
|
|
15
15
|
} = options;
|
|
16
|
-
return (0, _matches.matches)(placeholder,
|
|
16
|
+
return (0, _matches.matches)(placeholder, instance.props.placeholder, normalizer, exact);
|
|
17
17
|
};
|
|
18
|
-
const queryAllByPlaceholderText =
|
|
19
|
-
return (0, _findAll.findAll)(
|
|
18
|
+
const queryAllByPlaceholderText = instance => function queryAllByPlaceholderFn(placeholder, queryOptions) {
|
|
19
|
+
return (0, _findAll.findAll)(instance, item => (0, _hostComponentNames.isHostTextInput)(item) && matchPlaceholderText(item, placeholder, queryOptions), queryOptions);
|
|
20
20
|
};
|
|
21
21
|
const getMultipleError = placeholder => `Found multiple elements with placeholder: ${String(placeholder)} `;
|
|
22
22
|
const getMissingError = placeholder => `Unable to find an element with placeholder: ${String(placeholder)}`;
|
|
@@ -28,13 +28,13 @@ const {
|
|
|
28
28
|
findBy,
|
|
29
29
|
findAllBy
|
|
30
30
|
} = (0, _makeQueries.makeQueries)(queryAllByPlaceholderText, getMissingError, getMultipleError);
|
|
31
|
-
const bindByPlaceholderTextQueries =
|
|
32
|
-
getByPlaceholderText: getBy(
|
|
33
|
-
getAllByPlaceholderText: getAllBy(
|
|
34
|
-
queryByPlaceholderText: queryBy(
|
|
35
|
-
queryAllByPlaceholderText: queryAllBy(
|
|
36
|
-
findByPlaceholderText: findBy(
|
|
37
|
-
findAllByPlaceholderText: findAllBy(
|
|
31
|
+
const bindByPlaceholderTextQueries = instance => ({
|
|
32
|
+
getByPlaceholderText: getBy(instance),
|
|
33
|
+
getAllByPlaceholderText: getAllBy(instance),
|
|
34
|
+
queryByPlaceholderText: queryBy(instance),
|
|
35
|
+
queryAllByPlaceholderText: queryAllBy(instance),
|
|
36
|
+
findByPlaceholderText: findBy(instance),
|
|
37
|
+
findAllByPlaceholderText: findAllBy(instance)
|
|
38
38
|
});
|
|
39
39
|
exports.bindByPlaceholderTextQueries = bindByPlaceholderTextQueries;
|
|
40
40
|
//# sourceMappingURL=placeholder-text.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"placeholder-text.js","names":["_findAll","require","_hostComponentNames","_matches","_makeQueries","matchPlaceholderText","
|
|
1
|
+
{"version":3,"file":"placeholder-text.js","names":["_findAll","require","_hostComponentNames","_matches","_makeQueries","matchPlaceholderText","instance","placeholder","options","exact","normalizer","matches","props","queryAllByPlaceholderText","queryAllByPlaceholderFn","queryOptions","findAll","item","isHostTextInput","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByPlaceholderTextQueries","getByPlaceholderText","getAllByPlaceholderText","queryByPlaceholderText","findByPlaceholderText","findAllByPlaceholderText","exports"],"sources":["../../src/queries/placeholder-text.ts"],"sourcesContent":["import type { TestInstance } from 'test-renderer';\n\nimport { findAll } from '../helpers/find-all';\nimport { isHostTextInput } from '../helpers/host-component-names';\nimport type { TextMatch, TextMatchOptions } from '../matches';\nimport { matches } from '../matches';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './make-queries';\nimport { makeQueries } from './make-queries';\nimport type { CommonQueryOptions } from './options';\n\ntype ByPlaceholderTextOptions = CommonQueryOptions & TextMatchOptions;\n\nconst matchPlaceholderText = (\n instance: TestInstance,\n placeholder: TextMatch,\n options: TextMatchOptions = {},\n) => {\n const { exact, normalizer } = options;\n return matches(placeholder, instance.props.placeholder, normalizer, exact);\n};\n\nconst queryAllByPlaceholderText = (\n instance: TestInstance,\n): QueryAllByQuery<TextMatch, ByPlaceholderTextOptions> =>\n function queryAllByPlaceholderFn(placeholder, queryOptions) {\n return findAll(\n instance,\n (item) => isHostTextInput(item) && matchPlaceholderText(item, 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<TextMatch, ByPlaceholderTextOptions>;\n findByPlaceholderText: FindByQuery<TextMatch, ByPlaceholderTextOptions>;\n findAllByPlaceholderText: FindAllByQuery<TextMatch, ByPlaceholderTextOptions>;\n};\n\nexport const bindByPlaceholderTextQueries = (instance: TestInstance): 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":";;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AAEA,IAAAE,QAAA,GAAAF,OAAA;AASA,IAAAG,YAAA,GAAAH,OAAA;AAKA,MAAMI,oBAAoB,GAAGA,CAC3BC,QAAsB,EACtBC,WAAsB,EACtBC,OAAyB,GAAG,CAAC,CAAC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
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AccessibilityRole, Role } from 'react-native';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TestInstance } from 'test-renderer';
|
|
3
3
|
import type { AccessibilityStateMatcher } from '../helpers/matchers/match-accessibility-state';
|
|
4
4
|
import type { AccessibilityValueMatcher } from '../helpers/matchers/match-accessibility-value';
|
|
5
5
|
import { type TextMatch } from '../matches';
|
|
@@ -19,4 +19,4 @@ export type ByRoleQueries = {
|
|
|
19
19
|
findByRole: FindByQuery<ByRoleMatcher, ByRoleOptions>;
|
|
20
20
|
findAllByRole: FindAllByQuery<ByRoleMatcher, ByRoleOptions>;
|
|
21
21
|
};
|
|
22
|
-
export declare const bindByRoleQueries: (
|
|
22
|
+
export declare const bindByRoleQueries: (instance: TestInstance) => ByRoleQueries;
|
package/build/queries/role.js
CHANGED
|
@@ -10,33 +10,23 @@ var _matchAccessibilityState = require("../helpers/matchers/match-accessibility-
|
|
|
10
10
|
var _matchAccessibilityValue = require("../helpers/matchers/match-accessibility-value");
|
|
11
11
|
var _matchStringProp = require("../helpers/matchers/match-string-prop");
|
|
12
12
|
var _matches = require("../matches");
|
|
13
|
-
var _within = require("../within");
|
|
14
13
|
var _makeQueries = require("./make-queries");
|
|
15
|
-
const matchAccessibleNameIfNeeded = (
|
|
14
|
+
const matchAccessibleNameIfNeeded = (instance, name) => {
|
|
16
15
|
if (name == null) return true;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const accessibleName = (0, _accessibility.computeAccessibleName)(node);
|
|
20
|
-
if ((0, _matches.matches)(name, accessibleName)) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
const {
|
|
24
|
-
queryAllByText,
|
|
25
|
-
queryAllByLabelText
|
|
26
|
-
} = (0, _within.getQueriesForElement)(node);
|
|
27
|
-
return queryAllByText(name).length > 0 || queryAllByLabelText(name).length > 0;
|
|
16
|
+
const accessibleName = (0, _accessibility.computeAccessibleName)(instance);
|
|
17
|
+
return (0, _matches.matches)(name, accessibleName);
|
|
28
18
|
};
|
|
29
|
-
const matchAccessibleStateIfNeeded = (
|
|
30
|
-
return options != null ? (0, _matchAccessibilityState.matchAccessibilityState)(
|
|
19
|
+
const matchAccessibleStateIfNeeded = (instance, options) => {
|
|
20
|
+
return options != null ? (0, _matchAccessibilityState.matchAccessibilityState)(instance, options) : true;
|
|
31
21
|
};
|
|
32
|
-
const matchAccessibilityValueIfNeeded = (
|
|
33
|
-
return value != null ? (0, _matchAccessibilityValue.matchAccessibilityValue)(
|
|
22
|
+
const matchAccessibilityValueIfNeeded = (instance, value) => {
|
|
23
|
+
return value != null ? (0, _matchAccessibilityValue.matchAccessibilityValue)(instance, value) : true;
|
|
34
24
|
};
|
|
35
|
-
const queryAllByRole =
|
|
25
|
+
const queryAllByRole = instance => function queryAllByRoleFn(role, options) {
|
|
36
26
|
const normalizedRole = typeof role === 'string' ? (0, _accessibility.normalizeRole)(role) : role;
|
|
37
|
-
return (0, _findAll.findAll)(
|
|
27
|
+
return (0, _findAll.findAll)(instance, item =>
|
|
38
28
|
// run the cheapest checks first, and early exit to avoid unneeded computations
|
|
39
|
-
(0, _accessibility.isAccessibilityElement)(
|
|
29
|
+
(0, _accessibility.isAccessibilityElement)(item) && (0, _matchStringProp.matchStringProp)((0, _accessibility.getRole)(item), normalizedRole) && matchAccessibleStateIfNeeded(item, options) && matchAccessibilityValueIfNeeded(item, options?.value) && matchAccessibleNameIfNeeded(item, options?.name), options);
|
|
40
30
|
};
|
|
41
31
|
const formatQueryParams = (role, options = {}) => {
|
|
42
32
|
const params = [`role: ${String(role)}`];
|
|
@@ -65,13 +55,13 @@ const {
|
|
|
65
55
|
findBy,
|
|
66
56
|
findAllBy
|
|
67
57
|
} = (0, _makeQueries.makeQueries)(queryAllByRole, getMissingError, getMultipleError);
|
|
68
|
-
const bindByRoleQueries =
|
|
69
|
-
getByRole: getBy(
|
|
70
|
-
getAllByRole: getAllBy(
|
|
71
|
-
queryByRole: queryBy(
|
|
72
|
-
queryAllByRole: queryAllBy(
|
|
73
|
-
findByRole: findBy(
|
|
74
|
-
findAllByRole: findAllBy(
|
|
58
|
+
const bindByRoleQueries = instance => ({
|
|
59
|
+
getByRole: getBy(instance),
|
|
60
|
+
getAllByRole: getAllBy(instance),
|
|
61
|
+
queryByRole: queryBy(instance),
|
|
62
|
+
queryAllByRole: queryAllBy(instance),
|
|
63
|
+
findByRole: findBy(instance),
|
|
64
|
+
findAllByRole: findAllBy(instance)
|
|
75
65
|
});
|
|
76
66
|
exports.bindByRoleQueries = bindByRoleQueries;
|
|
77
67
|
//# sourceMappingURL=role.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role.js","names":["_accessibility","require","_findAll","_matchAccessibilityState","_matchAccessibilityValue","_matchStringProp","_matches","
|
|
1
|
+
{"version":3,"file":"role.js","names":["_accessibility","require","_findAll","_matchAccessibilityState","_matchAccessibilityValue","_matchStringProp","_matches","_makeQueries","matchAccessibleNameIfNeeded","instance","name","accessibleName","computeAccessibleName","matches","matchAccessibleStateIfNeeded","options","matchAccessibilityState","matchAccessibilityValueIfNeeded","value","matchAccessibilityValue","queryAllByRole","queryAllByRoleFn","role","normalizedRole","normalizeRole","findAll","item","isAccessibilityElement","matchStringProp","getRole","formatQueryParams","params","String","push","accessibilityStateKeys","forEach","stateKey","undefined","accessibilityValueKeys","valueKey","join","getMultipleError","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByRoleQueries","getByRole","getAllByRole","queryByRole","findByRole","findAllByRole","exports"],"sources":["../../src/queries/role.ts"],"sourcesContent":["import type { AccessibilityRole, Role } from 'react-native';\nimport type { TestInstance } from 'test-renderer';\n\nimport {\n accessibilityStateKeys,\n accessibilityValueKeys,\n computeAccessibleName,\n getRole,\n isAccessibilityElement,\n normalizeRole,\n} from '../helpers/accessibility';\nimport { findAll } from '../helpers/find-all';\nimport type { AccessibilityStateMatcher } from '../helpers/matchers/match-accessibility-state';\nimport { matchAccessibilityState } from '../helpers/matchers/match-accessibility-state';\nimport type { AccessibilityValueMatcher } from '../helpers/matchers/match-accessibility-value';\nimport { matchAccessibilityValue } from '../helpers/matchers/match-accessibility-value';\nimport { matchStringProp } from '../helpers/matchers/match-string-prop';\nimport { matches, type TextMatch } from '../matches';\nimport type { StringWithAutocomplete } from '../types';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './make-queries';\nimport { makeQueries } from './make-queries';\nimport type { CommonQueryOptions } from './options';\n\nexport type ByRoleMatcher = StringWithAutocomplete<AccessibilityRole | Role> | RegExp;\n\nexport type ByRoleOptions = CommonQueryOptions &\n AccessibilityStateMatcher & {\n name?: TextMatch;\n value?: AccessibilityValueMatcher;\n };\n\nconst matchAccessibleNameIfNeeded = (instance: TestInstance, name?: TextMatch) => {\n if (name == null) return true;\n\n const accessibleName = computeAccessibleName(instance);\n return matches(name, accessibleName);\n};\n\nconst matchAccessibleStateIfNeeded = (instance: TestInstance, options?: ByRoleOptions) => {\n return options != null ? matchAccessibilityState(instance, options) : true;\n};\n\nconst matchAccessibilityValueIfNeeded = (\n instance: TestInstance,\n value?: AccessibilityValueMatcher,\n) => {\n return value != null ? matchAccessibilityValue(instance, value) : true;\n};\n\nconst queryAllByRole = (instance: TestInstance): QueryAllByQuery<ByRoleMatcher, ByRoleOptions> =>\n function queryAllByRoleFn(role, options) {\n const normalizedRole = typeof role === 'string' ? normalizeRole(role) : role;\n return findAll(\n instance,\n (item) =>\n // run the cheapest checks first, and early exit to avoid unneeded computations\n isAccessibilityElement(item) &&\n matchStringProp(getRole(item), normalizedRole) &&\n matchAccessibleStateIfNeeded(item, options) &&\n matchAccessibilityValueIfNeeded(item, options?.value) &&\n matchAccessibleNameIfNeeded(item, 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 accessibilityValueKeys.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<ByRoleMatcher, ByRoleOptions>;\n getAllByRole: GetAllByQuery<ByRoleMatcher, ByRoleOptions>;\n queryByRole: QueryByQuery<ByRoleMatcher, ByRoleOptions>;\n queryAllByRole: QueryAllByQuery<ByRoleMatcher, ByRoleOptions>;\n findByRole: FindByQuery<ByRoleMatcher, ByRoleOptions>;\n findAllByRole: FindAllByQuery<ByRoleMatcher, ByRoleOptions>;\n};\n\nexport const bindByRoleQueries = (instance: TestInstance): 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":";;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AAQA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,wBAAA,GAAAF,OAAA;AAEA,IAAAG,wBAAA,GAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AAUA,IAAAM,YAAA,GAAAN,OAAA;AAWA,MAAMO,2BAA2B,GAAGA,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AY,EAAER,QAAQ,CAACnC,QAAQ,CAAC;EAChC4C,WAAW,EAAER,OAAO,CAACpC,QAAQ,CAAC;EAC9BW,cAAc,EAAE0B,UAAU,CAACrC,QAAQ,CAAC;EACpC6C,UAAU,EAAEP,MAAM,CAACtC,QAAQ,CAAC;EAC5B8C,aAAa,EAAEP,SAAS,CAACvC,QAAQ;AACnC,CAAC,CAAC;AAAC+C,OAAA,CAAAN,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TestInstance } from 'test-renderer';
|
|
2
2
|
import type { TextMatch, TextMatchOptions } from '../matches';
|
|
3
3
|
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './make-queries';
|
|
4
4
|
import type { CommonQueryOptions } from './options';
|
|
@@ -11,5 +11,5 @@ export type ByTestIdQueries = {
|
|
|
11
11
|
findByTestId: FindByQuery<TextMatch, ByTestIdOptions>;
|
|
12
12
|
findAllByTestId: FindAllByQuery<TextMatch, ByTestIdOptions>;
|
|
13
13
|
};
|
|
14
|
-
export declare const bindByTestIdQueries: (
|
|
14
|
+
export declare const bindByTestIdQueries: (instance: TestInstance) => ByTestIdQueries;
|
|
15
15
|
export {};
|