@testing-library/react-native 10.0.1 → 11.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/build/cleanup.js +4 -0
- package/build/cleanup.js.map +1 -1
- package/build/fireEvent.js +15 -13
- package/build/fireEvent.js.map +1 -1
- package/build/helpers/errors.js +1 -3
- package/build/helpers/errors.js.map +1 -1
- package/build/helpers/matchers/matchArrayProp.d.ts +8 -0
- package/build/helpers/matchers/matchArrayProp.js +26 -0
- package/build/helpers/matchers/matchArrayProp.js.map +1 -0
- package/build/helpers/matchers/matchObjectProp.d.ts +12 -0
- package/build/helpers/matchers/matchObjectProp.js +27 -0
- package/build/helpers/matchers/matchObjectProp.js.map +1 -0
- package/build/helpers/matchers/matchStringProp.d.ts +9 -0
- package/build/helpers/matchers/matchStringProp.js +26 -0
- package/build/helpers/matchers/matchStringProp.js.map +1 -0
- package/build/helpers/timers.js +12 -2
- package/build/helpers/timers.js.map +1 -1
- package/build/index.flow.js +8 -24
- package/build/matches.js +2 -1
- package/build/matches.js.map +1 -1
- package/build/pure.d.ts +5 -2
- package/build/pure.js +8 -0
- package/build/pure.js.map +1 -1
- package/build/queries/a11yState.d.ts +18 -0
- package/build/queries/a11yState.js +53 -0
- package/build/queries/a11yState.js.map +1 -0
- package/build/queries/a11yValue.d.ts +24 -0
- package/build/queries/a11yValue.js +53 -0
- package/build/queries/a11yValue.js.map +1 -0
- package/build/queries/hintText.d.ts +24 -0
- package/build/queries/hintText.js +61 -0
- package/build/queries/hintText.js.map +1 -0
- package/build/queries/labelText.d.ts +12 -0
- package/build/queries/labelText.js +39 -0
- package/build/queries/labelText.js.map +1 -0
- package/build/queries/makeQueries.d.ts +6 -6
- package/build/queries/makeQueries.js +4 -36
- package/build/queries/makeQueries.js.map +1 -1
- package/build/queries/role.d.ts +12 -0
- package/build/queries/role.js +39 -0
- package/build/queries/role.js.map +1 -0
- package/build/queries/text.js +1 -3
- package/build/queries/text.js.map +1 -1
- package/build/render.d.ts +107 -64
- package/build/render.js +5 -1
- package/build/render.js.map +1 -1
- package/build/renderHook.js +2 -2
- package/build/renderHook.js.map +1 -1
- package/build/screen.d.ts +4 -0
- package/build/screen.js +127 -0
- package/build/screen.js.map +1 -0
- package/build/waitFor.js +1 -1
- package/build/waitFor.js.map +1 -1
- package/build/within.d.ts +106 -64
- package/build/within.js +16 -4
- package/build/within.js.map +1 -1
- package/package.json +21 -17
- package/typings/index.flow.js +8 -24
- package/build/queries/a11yAPI.d.ts +0 -66
- package/build/queries/a11yAPI.js +0 -94
- package/build/queries/a11yAPI.js.map +0 -1
- package/build/queries/makeA11yQuery.d.ts +0 -13
- package/build/queries/makeA11yQuery.js +0 -80
- package/build/queries/makeA11yQuery.js.map +0 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.bindByA11yStateQueries = void 0;
|
|
7
|
+
|
|
8
|
+
var _matchObjectProp = require("../helpers/matchers/matchObjectProp");
|
|
9
|
+
|
|
10
|
+
var _makeQueries = require("./makeQueries");
|
|
11
|
+
|
|
12
|
+
const queryAllByA11yState = instance => function queryAllByA11yStateFn(state) {
|
|
13
|
+
return instance.findAll(node => typeof node.type === 'string' && (0, _matchObjectProp.matchObjectProp)(node.props.accessibilityState, state));
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const getMultipleError = state => `Found multiple elements with accessibilityState: ${JSON.stringify(state)}`;
|
|
17
|
+
|
|
18
|
+
const getMissingError = state => `Unable to find an element with accessibilityState: ${JSON.stringify(state)}`;
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
getBy,
|
|
22
|
+
getAllBy,
|
|
23
|
+
queryBy,
|
|
24
|
+
queryAllBy,
|
|
25
|
+
findBy,
|
|
26
|
+
findAllBy
|
|
27
|
+
} = (0, _makeQueries.makeQueries)(queryAllByA11yState, getMissingError, getMultipleError);
|
|
28
|
+
|
|
29
|
+
const bindByA11yStateQueries = instance => {
|
|
30
|
+
const getByA11yState = getBy(instance);
|
|
31
|
+
const getAllByA11yState = getAllBy(instance);
|
|
32
|
+
const queryByA11yState = queryBy(instance);
|
|
33
|
+
const queryAllByA11yState = queryAllBy(instance);
|
|
34
|
+
const findByA11yState = findBy(instance);
|
|
35
|
+
const findAllByA11yState = findAllBy(instance);
|
|
36
|
+
return {
|
|
37
|
+
getByA11yState,
|
|
38
|
+
getAllByA11yState,
|
|
39
|
+
queryByA11yState,
|
|
40
|
+
queryAllByA11yState,
|
|
41
|
+
findByA11yState,
|
|
42
|
+
findAllByA11yState,
|
|
43
|
+
getByAccessibilityState: getByA11yState,
|
|
44
|
+
getAllByAccessibilityState: getAllByA11yState,
|
|
45
|
+
queryByAccessibilityState: queryByA11yState,
|
|
46
|
+
queryAllByAccessibilityState: queryAllByA11yState,
|
|
47
|
+
findByAccessibilityState: findByA11yState,
|
|
48
|
+
findAllByAccessibilityState: findAllByA11yState
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.bindByA11yStateQueries = bindByA11yStateQueries;
|
|
53
|
+
//# sourceMappingURL=a11yState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/queries/a11yState.ts"],"names":["queryAllByA11yState","instance","queryAllByA11yStateFn","state","findAll","node","type","props","accessibilityState","getMultipleError","JSON","stringify","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","bindByA11yStateQueries","getByA11yState","getAllByA11yState","queryByA11yState","findByA11yState","findAllByA11yState","getByAccessibilityState","getAllByAccessibilityState","queryByAccessibilityState","queryAllByAccessibilityState","findByAccessibilityState","findAllByAccessibilityState"],"mappings":";;;;;;;AAEA;;AACA;;AAUA,MAAMA,mBAAmB,GACvBC,QAD0B,IAG1B,SAASC,qBAAT,CAA+BC,KAA/B,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;AAYL6B,IAAAA,wBAAwB,EAAEN,eAZrB;AAaLO,IAAAA,2BAA2B,EAAEN;AAbxB,GAAP;AAeD,CAzBM","sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { AccessibilityState } from 'react-native';\nimport { matchObjectProp } from '../helpers/matchers/matchObjectProp';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\nconst queryAllByA11yState = (\n instance: ReactTestInstance\n): ((state: AccessibilityState) => Array<ReactTestInstance>) =>\n function queryAllByA11yStateFn(state) {\n return instance.findAll(\n (node) =>\n typeof node.type === 'string' &&\n matchObjectProp(node.props.accessibilityState, state)\n );\n };\n\nconst getMultipleError = (state: AccessibilityState) =>\n `Found multiple elements with accessibilityState: ${JSON.stringify(state)}`;\nconst getMissingError = (state: AccessibilityState) =>\n `Unable to find an element with accessibilityState: ${JSON.stringify(state)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByA11yState,\n getMissingError,\n getMultipleError\n);\n\nexport type ByA11yStateQueries = {\n getByA11yState: GetByQuery<AccessibilityState>;\n getAllByA11yState: GetAllByQuery<AccessibilityState>;\n queryByA11yState: QueryByQuery<AccessibilityState>;\n queryAllByA11yState: QueryAllByQuery<AccessibilityState>;\n findByA11yState: FindByQuery<AccessibilityState>;\n findAllByA11yState: FindAllByQuery<AccessibilityState>;\n\n getByAccessibilityState: GetByQuery<AccessibilityState>;\n getAllByAccessibilityState: GetAllByQuery<AccessibilityState>;\n queryByAccessibilityState: QueryByQuery<AccessibilityState>;\n queryAllByAccessibilityState: QueryAllByQuery<AccessibilityState>;\n findByAccessibilityState: FindByQuery<AccessibilityState>;\n findAllByAccessibilityState: FindAllByQuery<AccessibilityState>;\n};\n\nexport const bindByA11yStateQueries = (\n instance: ReactTestInstance\n): ByA11yStateQueries => {\n const getByA11yState = getBy(instance);\n const getAllByA11yState = getAllBy(instance);\n const queryByA11yState = queryBy(instance);\n const queryAllByA11yState = queryAllBy(instance);\n const findByA11yState = findBy(instance);\n const findAllByA11yState = findAllBy(instance);\n\n return {\n getByA11yState,\n getAllByA11yState,\n queryByA11yState,\n queryAllByA11yState,\n findByA11yState,\n findAllByA11yState,\n\n getByAccessibilityState: getByA11yState,\n getAllByAccessibilityState: getAllByA11yState,\n queryByAccessibilityState: queryByA11yState,\n queryAllByAccessibilityState: queryAllByA11yState,\n findByAccessibilityState: findByA11yState,\n findAllByAccessibilityState: findAllByA11yState,\n };\n};\n"],"file":"a11yState.js"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
+
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './makeQueries';
|
|
3
|
+
declare type A11yValue = {
|
|
4
|
+
min?: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
now?: number;
|
|
7
|
+
text?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare type ByA11yValueQueries = {
|
|
10
|
+
getByA11yValue: GetByQuery<A11yValue>;
|
|
11
|
+
getAllByA11yValue: GetAllByQuery<A11yValue>;
|
|
12
|
+
queryByA11yValue: QueryByQuery<A11yValue>;
|
|
13
|
+
queryAllByA11yValue: QueryAllByQuery<A11yValue>;
|
|
14
|
+
findByA11yValue: FindByQuery<A11yValue>;
|
|
15
|
+
findAllByA11yValue: FindAllByQuery<A11yValue>;
|
|
16
|
+
getByAccessibilityValue: GetByQuery<A11yValue>;
|
|
17
|
+
getAllByAccessibilityValue: GetAllByQuery<A11yValue>;
|
|
18
|
+
queryByAccessibilityValue: QueryByQuery<A11yValue>;
|
|
19
|
+
queryAllByAccessibilityValue: QueryAllByQuery<A11yValue>;
|
|
20
|
+
findByAccessibilityValue: FindByQuery<A11yValue>;
|
|
21
|
+
findAllByAccessibilityValue: FindAllByQuery<A11yValue>;
|
|
22
|
+
};
|
|
23
|
+
export declare const bindByA11yValueQueries: (instance: ReactTestInstance) => ByA11yValueQueries;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.bindByA11yValueQueries = void 0;
|
|
7
|
+
|
|
8
|
+
var _matchObjectProp = require("../helpers/matchers/matchObjectProp");
|
|
9
|
+
|
|
10
|
+
var _makeQueries = require("./makeQueries");
|
|
11
|
+
|
|
12
|
+
const queryAllByA11yValue = instance => function queryAllByA11yValueFn(value) {
|
|
13
|
+
return instance.findAll(node => typeof node.type === 'string' && (0, _matchObjectProp.matchObjectProp)(node.props.accessibilityValue, value));
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const getMultipleError = value => `Found multiple elements with accessibilityValue: ${JSON.stringify(value)} `;
|
|
17
|
+
|
|
18
|
+
const getMissingError = value => `Unable to find an element with accessibilityValue: ${JSON.stringify(value)}`;
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
getBy,
|
|
22
|
+
getAllBy,
|
|
23
|
+
queryBy,
|
|
24
|
+
queryAllBy,
|
|
25
|
+
findBy,
|
|
26
|
+
findAllBy
|
|
27
|
+
} = (0, _makeQueries.makeQueries)(queryAllByA11yValue, getMissingError, getMultipleError);
|
|
28
|
+
|
|
29
|
+
const bindByA11yValueQueries = instance => {
|
|
30
|
+
const getByA11yValue = getBy(instance);
|
|
31
|
+
const getAllByA11yValue = getAllBy(instance);
|
|
32
|
+
const queryByA11yValue = queryBy(instance);
|
|
33
|
+
const queryAllByA11yValue = queryAllBy(instance);
|
|
34
|
+
const findByA11yValue = findBy(instance);
|
|
35
|
+
const findAllByA11yValue = findAllBy(instance);
|
|
36
|
+
return {
|
|
37
|
+
getByA11yValue,
|
|
38
|
+
getAllByA11yValue,
|
|
39
|
+
queryByA11yValue,
|
|
40
|
+
queryAllByA11yValue,
|
|
41
|
+
findByA11yValue,
|
|
42
|
+
findAllByA11yValue,
|
|
43
|
+
getByAccessibilityValue: getByA11yValue,
|
|
44
|
+
getAllByAccessibilityValue: getAllByA11yValue,
|
|
45
|
+
queryByAccessibilityValue: queryByA11yValue,
|
|
46
|
+
queryAllByAccessibilityValue: queryAllByA11yValue,
|
|
47
|
+
findByAccessibilityValue: findByA11yValue,
|
|
48
|
+
findAllByAccessibilityValue: findAllByA11yValue
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.bindByA11yValueQueries = bindByA11yValueQueries;
|
|
53
|
+
//# sourceMappingURL=a11yValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/queries/a11yValue.ts"],"names":["queryAllByA11yValue","instance","queryAllByA11yValueFn","value","findAll","node","type","props","accessibilityValue","getMultipleError","JSON","stringify","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","bindByA11yValueQueries","getByA11yValue","getAllByA11yValue","queryByA11yValue","findByA11yValue","findAllByA11yValue","getByAccessibilityValue","getAllByAccessibilityValue","queryByAccessibilityValue","queryAllByAccessibilityValue","findByAccessibilityValue","findAllByAccessibilityValue"],"mappings":";;;;;;;AACA;;AACA;;AAiBA,MAAMA,mBAAmB,GACvBC,QAD0B,IAG1B,SAASC,qBAAT,CAA+BC,KAA/B,EAAsC;AACpC,SAAOF,QAAQ,CAACG,OAAT,CACJC,IAAD,IACE,OAAOA,IAAI,CAACC,IAAZ,KAAqB,QAArB,IACA,sCAAgBD,IAAI,CAACE,KAAL,CAAWC,kBAA3B,EAA+CL,KAA/C,CAHG,CAAP;AAKD,CATH;;AAWA,MAAMM,gBAAgB,GAAIN,KAAD,IACtB,oDAAmDO,IAAI,CAACC,SAAL,CAAeR,KAAf,CAAsB,GAD5E;;AAEA,MAAMS,eAAe,GAAIT,KAAD,IACrB,sDAAqDO,IAAI,CAACC,SAAL,CAAeR,KAAf,CAAsB,EAD9E;;AAGA,MAAM;AAAEU,EAAAA,KAAF;AAASC,EAAAA,QAAT;AAAmBC,EAAAA,OAAnB;AAA4BC,EAAAA,UAA5B;AAAwCC,EAAAA,MAAxC;AAAgDC,EAAAA;AAAhD,IAA8D,8BAClElB,mBADkE,EAElEY,eAFkE,EAGlEH,gBAHkE,CAApE;;AAsBO,MAAMU,sBAAsB,GACjClB,QADoC,IAEb;AACvB,QAAMmB,cAAc,GAAGP,KAAK,CAACZ,QAAD,CAA5B;AACA,QAAMoB,iBAAiB,GAAGP,QAAQ,CAACb,QAAD,CAAlC;AACA,QAAMqB,gBAAgB,GAAGP,OAAO,CAACd,QAAD,CAAhC;AACA,QAAMD,mBAAmB,GAAGgB,UAAU,CAACf,QAAD,CAAtC;AACA,QAAMsB,eAAe,GAAGN,MAAM,CAAChB,QAAD,CAA9B;AACA,QAAMuB,kBAAkB,GAAGN,SAAS,CAACjB,QAAD,CAApC;AAEA,SAAO;AACLmB,IAAAA,cADK;AAELC,IAAAA,iBAFK;AAGLC,IAAAA,gBAHK;AAILtB,IAAAA,mBAJK;AAKLuB,IAAAA,eALK;AAMLC,IAAAA,kBANK;AAQLC,IAAAA,uBAAuB,EAAEL,cARpB;AASLM,IAAAA,0BAA0B,EAAEL,iBATvB;AAULM,IAAAA,yBAAyB,EAAEL,gBAVtB;AAWLM,IAAAA,4BAA4B,EAAE5B,mBAXzB;AAYL6B,IAAAA,wBAAwB,EAAEN,eAZrB;AAaLO,IAAAA,2BAA2B,EAAEN;AAbxB,GAAP;AAeD,CAzBM","sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matchObjectProp } from '../helpers/matchers/matchObjectProp';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\ntype A11yValue = {\n min?: number;\n max?: number;\n now?: number;\n text?: string;\n};\n\nconst queryAllByA11yValue = (\n instance: ReactTestInstance\n): ((value: A11yValue) => Array<ReactTestInstance>) =>\n function queryAllByA11yValueFn(value) {\n return instance.findAll(\n (node) =>\n typeof node.type === 'string' &&\n matchObjectProp(node.props.accessibilityValue, value)\n );\n };\n\nconst getMultipleError = (value: A11yValue) =>\n `Found multiple elements with accessibilityValue: ${JSON.stringify(value)} `;\nconst getMissingError = (value: A11yValue) =>\n `Unable to find an element with accessibilityValue: ${JSON.stringify(value)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByA11yValue,\n getMissingError,\n getMultipleError\n);\n\nexport type ByA11yValueQueries = {\n getByA11yValue: GetByQuery<A11yValue>;\n getAllByA11yValue: GetAllByQuery<A11yValue>;\n queryByA11yValue: QueryByQuery<A11yValue>;\n queryAllByA11yValue: QueryAllByQuery<A11yValue>;\n findByA11yValue: FindByQuery<A11yValue>;\n findAllByA11yValue: FindAllByQuery<A11yValue>;\n\n getByAccessibilityValue: GetByQuery<A11yValue>;\n getAllByAccessibilityValue: GetAllByQuery<A11yValue>;\n queryByAccessibilityValue: QueryByQuery<A11yValue>;\n queryAllByAccessibilityValue: QueryAllByQuery<A11yValue>;\n findByAccessibilityValue: FindByQuery<A11yValue>;\n findAllByAccessibilityValue: FindAllByQuery<A11yValue>;\n};\n\nexport const bindByA11yValueQueries = (\n instance: ReactTestInstance\n): ByA11yValueQueries => {\n const getByA11yValue = getBy(instance);\n const getAllByA11yValue = getAllBy(instance);\n const queryByA11yValue = queryBy(instance);\n const queryAllByA11yValue = queryAllBy(instance);\n const findByA11yValue = findBy(instance);\n const findAllByA11yValue = findAllBy(instance);\n\n return {\n getByA11yValue,\n getAllByA11yValue,\n queryByA11yValue,\n queryAllByA11yValue,\n findByA11yValue,\n findAllByA11yValue,\n\n getByAccessibilityValue: getByA11yValue,\n getAllByAccessibilityValue: getAllByA11yValue,\n queryByAccessibilityValue: queryByA11yValue,\n queryAllByAccessibilityValue: queryAllByA11yValue,\n findByAccessibilityValue: findByA11yValue,\n findAllByAccessibilityValue: findAllByA11yValue,\n };\n};\n"],"file":"a11yValue.js"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
+
import { TextMatch } from '../matches';
|
|
3
|
+
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './makeQueries';
|
|
4
|
+
export declare type ByHintTextQueries = {
|
|
5
|
+
getByHintText: GetByQuery<TextMatch>;
|
|
6
|
+
getAllByHintText: GetAllByQuery<TextMatch>;
|
|
7
|
+
queryByHintText: QueryByQuery<TextMatch>;
|
|
8
|
+
queryAllByHintText: QueryAllByQuery<TextMatch>;
|
|
9
|
+
findByHintText: FindByQuery<TextMatch>;
|
|
10
|
+
findAllByHintText: FindAllByQuery<TextMatch>;
|
|
11
|
+
getByA11yHint: GetByQuery<TextMatch>;
|
|
12
|
+
getAllByA11yHint: GetAllByQuery<TextMatch>;
|
|
13
|
+
queryByA11yHint: QueryByQuery<TextMatch>;
|
|
14
|
+
queryAllByA11yHint: QueryAllByQuery<TextMatch>;
|
|
15
|
+
findByA11yHint: FindByQuery<TextMatch>;
|
|
16
|
+
findAllByA11yHint: FindAllByQuery<TextMatch>;
|
|
17
|
+
getByAccessibilityHint: GetByQuery<TextMatch>;
|
|
18
|
+
getAllByAccessibilityHint: GetAllByQuery<TextMatch>;
|
|
19
|
+
queryByAccessibilityHint: QueryByQuery<TextMatch>;
|
|
20
|
+
queryAllByAccessibilityHint: QueryAllByQuery<TextMatch>;
|
|
21
|
+
findByAccessibilityHint: FindByQuery<TextMatch>;
|
|
22
|
+
findAllByAccessibilityHint: FindAllByQuery<TextMatch>;
|
|
23
|
+
};
|
|
24
|
+
export declare const bindByHintTextQueries: (instance: ReactTestInstance) => ByHintTextQueries;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.bindByHintTextQueries = void 0;
|
|
7
|
+
|
|
8
|
+
var _matchStringProp = require("../helpers/matchers/matchStringProp");
|
|
9
|
+
|
|
10
|
+
var _makeQueries = require("./makeQueries");
|
|
11
|
+
|
|
12
|
+
const queryAllByHintText = instance => function queryAllByA11yHintFn(hint) {
|
|
13
|
+
return instance.findAll(node => typeof node.type === 'string' && (0, _matchStringProp.matchStringProp)(node.props.accessibilityHint, hint));
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const getMultipleError = hint => `Found multiple elements with accessibilityHint: ${String(hint)} `;
|
|
17
|
+
|
|
18
|
+
const getMissingError = hint => `Unable to find an element with accessibilityHint: ${String(hint)}`;
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
getBy,
|
|
22
|
+
getAllBy,
|
|
23
|
+
queryBy,
|
|
24
|
+
queryAllBy,
|
|
25
|
+
findBy,
|
|
26
|
+
findAllBy
|
|
27
|
+
} = (0, _makeQueries.makeQueries)(queryAllByHintText, getMissingError, getMultipleError);
|
|
28
|
+
|
|
29
|
+
const bindByHintTextQueries = instance => {
|
|
30
|
+
const getByHintText = getBy(instance);
|
|
31
|
+
const getAllByHintText = getAllBy(instance);
|
|
32
|
+
const queryByHintText = queryBy(instance);
|
|
33
|
+
const queryAllByHintText = queryAllBy(instance);
|
|
34
|
+
const findByHintText = findBy(instance);
|
|
35
|
+
const findAllByHintText = findAllBy(instance);
|
|
36
|
+
return {
|
|
37
|
+
getByHintText,
|
|
38
|
+
getAllByHintText,
|
|
39
|
+
queryByHintText,
|
|
40
|
+
queryAllByHintText,
|
|
41
|
+
findByHintText,
|
|
42
|
+
findAllByHintText,
|
|
43
|
+
// a11yHint aliases
|
|
44
|
+
getByA11yHint: getByHintText,
|
|
45
|
+
getAllByA11yHint: getAllByHintText,
|
|
46
|
+
queryByA11yHint: queryByHintText,
|
|
47
|
+
queryAllByA11yHint: queryAllByHintText,
|
|
48
|
+
findByA11yHint: findByHintText,
|
|
49
|
+
findAllByA11yHint: findAllByHintText,
|
|
50
|
+
// accessibilityHint aliases
|
|
51
|
+
getByAccessibilityHint: getByHintText,
|
|
52
|
+
getAllByAccessibilityHint: getAllByHintText,
|
|
53
|
+
queryByAccessibilityHint: queryByHintText,
|
|
54
|
+
queryAllByAccessibilityHint: queryAllByHintText,
|
|
55
|
+
findByAccessibilityHint: findByHintText,
|
|
56
|
+
findAllByAccessibilityHint: findAllByHintText
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
exports.bindByHintTextQueries = bindByHintTextQueries;
|
|
61
|
+
//# sourceMappingURL=hintText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/queries/hintText.ts"],"names":["queryAllByHintText","instance","queryAllByA11yHintFn","hint","findAll","node","type","props","accessibilityHint","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","bindByHintTextQueries","getByHintText","getAllByHintText","queryByHintText","findByHintText","findAllByHintText","getByA11yHint","getAllByA11yHint","queryByA11yHint","queryAllByA11yHint","findByA11yHint","findAllByA11yHint","getByAccessibilityHint","getAllByAccessibilityHint","queryByAccessibilityHint","queryAllByAccessibilityHint","findByAccessibilityHint","findAllByAccessibilityHint"],"mappings":";;;;;;;AAEA;;AACA;;AAUA,MAAMA,kBAAkB,GACtBC,QADyB,IAGzB,SAASC,oBAAT,CAA8BC,IAA9B,EAAoC;AAClC,SAAOF,QAAQ,CAACG,OAAT,CACJC,IAAD,IACE,OAAOA,IAAI,CAACC,IAAZ,KAAqB,QAArB,IACA,sCAAgBD,IAAI,CAACE,KAAL,CAAWC,iBAA3B,EAA8CL,IAA9C,CAHG,CAAP;AAKD,CATH;;AAWA,MAAMM,gBAAgB,GAAIN,IAAD,IACtB,mDAAkDO,MAAM,CAACP,IAAD,CAAO,GADlE;;AAEA,MAAM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AtBvB,GAAP;AAwBD,CAlCM","sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { TextMatch } from '../matches';\nimport { matchStringProp } from '../helpers/matchers/matchStringProp';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\nconst queryAllByHintText = (\n instance: ReactTestInstance\n): ((hint: TextMatch) => Array<ReactTestInstance>) =>\n function queryAllByA11yHintFn(hint) {\n return instance.findAll(\n (node) =>\n typeof node.type === 'string' &&\n matchStringProp(node.props.accessibilityHint, hint)\n );\n };\n\nconst getMultipleError = (hint: TextMatch) =>\n `Found multiple elements with accessibilityHint: ${String(hint)} `;\nconst getMissingError = (hint: TextMatch) =>\n `Unable to find an element with accessibilityHint: ${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>;\n getAllByHintText: GetAllByQuery<TextMatch>;\n queryByHintText: QueryByQuery<TextMatch>;\n queryAllByHintText: QueryAllByQuery<TextMatch>;\n findByHintText: FindByQuery<TextMatch>;\n findAllByHintText: FindAllByQuery<TextMatch>;\n\n // a11yHint aliases\n getByA11yHint: GetByQuery<TextMatch>;\n getAllByA11yHint: GetAllByQuery<TextMatch>;\n queryByA11yHint: QueryByQuery<TextMatch>;\n queryAllByA11yHint: QueryAllByQuery<TextMatch>;\n findByA11yHint: FindByQuery<TextMatch>;\n findAllByA11yHint: FindAllByQuery<TextMatch>;\n\n // accessibilityHint aliases\n getByAccessibilityHint: GetByQuery<TextMatch>;\n getAllByAccessibilityHint: GetAllByQuery<TextMatch>;\n queryByAccessibilityHint: QueryByQuery<TextMatch>;\n queryAllByAccessibilityHint: QueryAllByQuery<TextMatch>;\n findByAccessibilityHint: FindByQuery<TextMatch>;\n findAllByAccessibilityHint: FindAllByQuery<TextMatch>;\n};\n\nexport const bindByHintTextQueries = (\n instance: ReactTestInstance\n): 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"],"file":"hintText.js"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
+
import { TextMatch } from '../matches';
|
|
3
|
+
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './makeQueries';
|
|
4
|
+
export declare type ByLabelTextQueries = {
|
|
5
|
+
getByLabelText: GetByQuery<TextMatch>;
|
|
6
|
+
getAllByLabelText: GetAllByQuery<TextMatch>;
|
|
7
|
+
queryByLabelText: QueryByQuery<TextMatch>;
|
|
8
|
+
queryAllByLabelText: QueryAllByQuery<TextMatch>;
|
|
9
|
+
findByLabelText: FindByQuery<TextMatch>;
|
|
10
|
+
findAllByLabelText: FindAllByQuery<TextMatch>;
|
|
11
|
+
};
|
|
12
|
+
export declare const bindByLabelTextQueries: (instance: ReactTestInstance) => ByLabelTextQueries;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.bindByLabelTextQueries = void 0;
|
|
7
|
+
|
|
8
|
+
var _matchStringProp = require("../helpers/matchers/matchStringProp");
|
|
9
|
+
|
|
10
|
+
var _makeQueries = require("./makeQueries");
|
|
11
|
+
|
|
12
|
+
const queryAllByLabelText = instance => function queryAllByLabelTextFn(text) {
|
|
13
|
+
return instance.findAll(node => typeof node.type === 'string' && (0, _matchStringProp.matchStringProp)(node.props.accessibilityLabel, text));
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const getMultipleError = labelText => `Found multiple elements with accessibilityLabel: ${String(labelText)} `;
|
|
17
|
+
|
|
18
|
+
const getMissingError = labelText => `Unable to find an element with accessibilityLabel: ${String(labelText)}`;
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
getBy,
|
|
22
|
+
getAllBy,
|
|
23
|
+
queryBy,
|
|
24
|
+
queryAllBy,
|
|
25
|
+
findBy,
|
|
26
|
+
findAllBy
|
|
27
|
+
} = (0, _makeQueries.makeQueries)(queryAllByLabelText, getMissingError, getMultipleError);
|
|
28
|
+
|
|
29
|
+
const bindByLabelTextQueries = instance => ({
|
|
30
|
+
getByLabelText: getBy(instance),
|
|
31
|
+
getAllByLabelText: getAllBy(instance),
|
|
32
|
+
queryByLabelText: queryBy(instance),
|
|
33
|
+
queryAllByLabelText: queryAllBy(instance),
|
|
34
|
+
findByLabelText: findBy(instance),
|
|
35
|
+
findAllByLabelText: findAllBy(instance)
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
exports.bindByLabelTextQueries = bindByLabelTextQueries;
|
|
39
|
+
//# sourceMappingURL=labelText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/queries/labelText.ts"],"names":["queryAllByLabelText","instance","queryAllByLabelTextFn","text","findAll","node","type","props","accessibilityLabel","getMultipleError","labelText","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","bindByLabelTextQueries","getByLabelText","getAllByLabelText","queryByLabelText","findByLabelText","findAllByLabelText"],"mappings":";;;;;;;AAEA;;AACA;;AAUA,MAAMA,mBAAmB,GACvBC,QAD0B,IAG1B,SAASC,qBAAT,CAA+BC,IAA/B,EAAqC;AACnC,SAAOF,QAAQ,CAACG,OAAT,CACJC,IAAD,IACE,OAAOA,IAAI,CAACC,IAAZ,KAAqB,QAArB,IACA,sCAAgBD,IAAI,CAACE,KAAL,CAAWC,kBAA3B,EAA+CL,IAA/C,CAHG,CAAP;AAKD,CATH;;AAWA,MAAMM,gBAAgB,GAAIC,SAAD,IACtB,oDAAmDC,MAAM,CAACD,SAAD,CAAY,GADxE;;AAEA,MAAME,eAAe,GAAIF,SAAD,IACrB,sDAAqDC,MAAM,CAACD,SAAD,CAAY,EAD1E;;AAGA,MAAM;AAAEG,EAAAA,KAAF;AAASC,EAAAA,QAAT;AAAmBC,EAAAA,OAAnB;AAA4BC,EAAAA,UAA5B;AAAwCC,EAAAA,MAAxC;AAAgDC,EAAAA;AAAhD,IAA8D,8BAClElB,mBADkE,EAElEY,eAFkE,EAGlEH,gBAHkE,CAApE;;AAeO,MAAMU,sBAAsB,GACjClB,QADoC,KAEZ;AACxBmB,EAAAA,cAAc,EAAEP,KAAK,CAACZ,QAAD,CADG;AAExBoB,EAAAA,iBAAiB,EAAEP,QAAQ,CAACb,QAAD,CAFH;AAGxBqB,EAAAA,gBAAgB,EAAEP,OAAO,CAACd,QAAD,CAHD;AAIxBD,EAAAA,mBAAmB,EAAEgB,UAAU,CAACf,QAAD,CAJP;AAKxBsB,EAAAA,eAAe,EAAEN,MAAM,CAAChB,QAAD,CALC;AAMxBuB,EAAAA,kBAAkB,EAAEN,SAAS,CAACjB,QAAD;AANL,CAFY,CAA/B","sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { TextMatch } from '../matches';\nimport { matchStringProp } from '../helpers/matchers/matchStringProp';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\nconst queryAllByLabelText = (\n instance: ReactTestInstance\n): ((text: TextMatch) => Array<ReactTestInstance>) =>\n function queryAllByLabelTextFn(text) {\n return instance.findAll(\n (node) =>\n typeof node.type === 'string' &&\n matchStringProp(node.props.accessibilityLabel, text)\n );\n };\n\nconst getMultipleError = (labelText: TextMatch) =>\n `Found multiple elements with accessibilityLabel: ${String(labelText)} `;\nconst getMissingError = (labelText: TextMatch) =>\n `Unable to find an element with accessibilityLabel: ${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>;\n getAllByLabelText: GetAllByQuery<TextMatch>;\n queryByLabelText: QueryByQuery<TextMatch>;\n queryAllByLabelText: QueryAllByQuery<TextMatch>;\n findByLabelText: FindByQuery<TextMatch>;\n findAllByLabelText: FindAllByQuery<TextMatch>;\n};\n\nexport const bindByLabelTextQueries = (\n instance: ReactTestInstance\n): 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"],"file":"labelText.js"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
2
|
import type { WaitForOptions } from '../waitFor';
|
|
3
|
-
export declare type GetByQuery<Predicate, Options> = (predicate: Predicate, options?: Options) => ReactTestInstance;
|
|
4
|
-
export declare type GetAllByQuery<Predicate, Options> = (predicate: Predicate, options?: Options) => ReactTestInstance[];
|
|
5
|
-
export declare type QueryByQuery<Predicate, Options> = (predicate: Predicate, options?: Options) => ReactTestInstance | null;
|
|
6
|
-
export declare type QueryAllByQuery<Predicate, Options> = (predicate: Predicate, options?: Options) => ReactTestInstance[];
|
|
7
|
-
export declare type FindByQuery<Predicate, Options> = (predicate: Predicate, options?: Options
|
|
8
|
-
export declare type FindAllByQuery<Predicate, Options> = (predicate: Predicate, options?: Options
|
|
3
|
+
export declare type GetByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options) => ReactTestInstance;
|
|
4
|
+
export declare type GetAllByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options) => ReactTestInstance[];
|
|
5
|
+
export declare type QueryByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options) => ReactTestInstance | null;
|
|
6
|
+
export declare type QueryAllByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options) => ReactTestInstance[];
|
|
7
|
+
export declare type FindByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options, waitForOptions?: WaitForOptions) => Promise<ReactTestInstance>;
|
|
8
|
+
export declare type FindAllByQuery<Predicate, Options = void> = (predicate: Predicate, options?: Options, waitForOptions?: WaitForOptions) => Promise<ReactTestInstance[]>;
|
|
9
9
|
declare type UnboundQuery<Query> = (instance: ReactTestInstance) => Query;
|
|
10
10
|
export declare type UnboundQueries<Predicate, Options> = {
|
|
11
11
|
getBy: UnboundQuery<GetByQuery<Predicate, Options>>;
|
|
@@ -11,32 +11,6 @@ var _waitFor = _interopRequireDefault(require("../waitFor"));
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
|
-
// The WaitForOptions has been moved to the second option param of findBy* methods with the adding of TextMatchOptions
|
|
15
|
-
// To make the migration easier and avoid a breaking change, keep reading this options from the first param but warn
|
|
16
|
-
const deprecatedKeys = ['timeout', 'interval', 'stackTraceError'];
|
|
17
|
-
|
|
18
|
-
const extractDeprecatedWaitForOptionUsage = queryOptions => {
|
|
19
|
-
if (queryOptions) {
|
|
20
|
-
const waitForOptions = {
|
|
21
|
-
timeout: queryOptions.timeout,
|
|
22
|
-
interval: queryOptions.interval,
|
|
23
|
-
stackTraceError: queryOptions.stackTraceError
|
|
24
|
-
};
|
|
25
|
-
deprecatedKeys.forEach(key => {
|
|
26
|
-
const option = queryOptions[key];
|
|
27
|
-
|
|
28
|
-
if (option) {
|
|
29
|
-
// eslint-disable-next-line no-console
|
|
30
|
-
console.warn(`Use of option "${key}" in a findBy* query's second parameter, TextMatchOptions, is deprecated. Please pass this option in the third, WaitForOptions, parameter.
|
|
31
|
-
Example:
|
|
32
|
-
|
|
33
|
-
findByText(text, {}, { ${key}: ${option.toString()} })`);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return waitForOptions;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
14
|
function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
|
|
41
15
|
function getAllByQuery(instance) {
|
|
42
16
|
return function getAllFn(predicate, options) {
|
|
@@ -83,20 +57,14 @@ function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
|
|
|
83
57
|
}
|
|
84
58
|
|
|
85
59
|
function findAllByQuery(instance) {
|
|
86
|
-
return function findAllFn(predicate, queryOptions, waitForOptions
|
|
87
|
-
|
|
88
|
-
return (0, _waitFor.default)(() => getAllByQuery(instance)(predicate, queryOptions), { ...deprecatedWaitForOptions,
|
|
89
|
-
...waitForOptions
|
|
90
|
-
});
|
|
60
|
+
return function findAllFn(predicate, queryOptions, waitForOptions) {
|
|
61
|
+
return (0, _waitFor.default)(() => getAllByQuery(instance)(predicate, queryOptions), waitForOptions);
|
|
91
62
|
};
|
|
92
63
|
}
|
|
93
64
|
|
|
94
65
|
function findByQuery(instance) {
|
|
95
|
-
return function findFn(predicate, queryOptions, waitForOptions
|
|
96
|
-
|
|
97
|
-
return (0, _waitFor.default)(() => getByQuery(instance)(predicate, queryOptions), { ...deprecatedWaitForOptions,
|
|
98
|
-
...waitForOptions
|
|
99
|
-
});
|
|
66
|
+
return function findFn(predicate, queryOptions, waitForOptions) {
|
|
67
|
+
return (0, _waitFor.default)(() => getByQuery(instance)(predicate, queryOptions), waitForOptions);
|
|
100
68
|
};
|
|
101
69
|
}
|
|
102
70
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/makeQueries.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../src/queries/makeQueries.ts"],"names":["makeQueries","queryAllByQuery","getMissingError","getMultipleError","getAllByQuery","instance","getAllFn","predicate","options","results","length","ErrorWithStack","queryByQuery","singleQueryFn","getByQuery","getFn","findAllByQuery","findAllFn","queryOptions","waitForOptions","findByQuery","findFn","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy"],"mappings":";;;;;;;AACA;;AACA;;;;AA8CO,SAASA,WAAT,CACLC,eADK,EAELC,eAFK,EAGLC,gBAHK,EAI+B;AACpC,WAASC,aAAT,CAAuBC,QAAvB,EAAoD;AAClD,WAAO,SAASC,QAAT,CAAkBC,SAAlB,EAAwCC,OAAxC,EAA2D;AAChE,YAAMC,OAAO,GAAGR,eAAe,CAACI,QAAD,CAAf,CAA0BE,SAA1B,EAAqCC,OAArC,CAAhB;;AAEA,UAAIC,OAAO,CAACC,MAAR,KAAmB,CAAvB,EAA0B;AACxB,cAAM,IAAIC,sBAAJ,CAAmBT,eAAe,CAACK,SAAD,CAAlC,EAA+CD,QAA/C,CAAN;AACD;;AAED,aAAOG,OAAP;AACD,KARD;AASD;;AAED,WAASG,YAAT,CAAsBP,QAAtB,EAAmD;AACjD,WAAO,SAASQ,aAAT,CAAuBN,SAAvB,EAA6CC,OAA7C,EAAgE;AACrE,YAAMC,OAAO,GAAGR,eAAe,CAACI,QAAD,CAAf,CAA0BE,SAA1B,EAAqCC,OAArC,CAAhB;;AAEA,UAAIC,OAAO,CAACC,MAAR,GAAiB,CAArB,EAAwB;AACtB,cAAM,IAAIC,sBAAJ,CAAm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nB,aAFL;AAGLoB,IAAAA,OAAO,EAAEZ,YAHJ;AAILa,IAAAA,UAAU,EAAExB,eAJP;AAKLyB,IAAAA,MAAM,EAAEN,WALH;AAMLO,IAAAA,SAAS,EAAEX;AANN,GAAP;AAQD","sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { ErrorWithStack } from '../helpers/errors';\nimport waitFor from '../waitFor';\nimport type { WaitForOptions } from '../waitFor';\n\nexport type GetByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options\n) => ReactTestInstance;\n\nexport type GetAllByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options\n) => ReactTestInstance[];\n\nexport type QueryByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options\n) => ReactTestInstance | null;\n\nexport type QueryAllByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options\n) => ReactTestInstance[];\n\nexport type FindByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options,\n waitForOptions?: WaitForOptions\n) => Promise<ReactTestInstance>;\n\nexport type FindAllByQuery<Predicate, Options = void> = (\n predicate: Predicate,\n options?: Options,\n waitForOptions?: WaitForOptions\n) => Promise<ReactTestInstance[]>;\n\ntype UnboundQuery<Query> = (instance: ReactTestInstance) => Query;\n\nexport type UnboundQueries<Predicate, Options> = {\n getBy: UnboundQuery<GetByQuery<Predicate, Options>>;\n getAllBy: UnboundQuery<GetAllByQuery<Predicate, Options>>;\n queryBy: UnboundQuery<QueryByQuery<Predicate, Options>>;\n queryAllBy: UnboundQuery<QueryAllByQuery<Predicate, Options>>;\n findBy: UnboundQuery<FindByQuery<Predicate, Options>>;\n findAllBy: UnboundQuery<FindAllByQuery<Predicate, Options>>;\n};\n\nexport function makeQueries<Predicate, Options>(\n queryAllByQuery: UnboundQuery<QueryAllByQuery<Predicate, Options>>,\n getMissingError: (predicate: Predicate) => string,\n getMultipleError: (predicate: Predicate) => string\n): UnboundQueries<Predicate, Options> {\n function getAllByQuery(instance: ReactTestInstance) {\n return function getAllFn(predicate: Predicate, options?: Options) {\n const results = queryAllByQuery(instance)(predicate, options);\n\n if (results.length === 0) {\n throw new ErrorWithStack(getMissingError(predicate), getAllFn);\n }\n\n return results;\n };\n }\n\n function queryByQuery(instance: ReactTestInstance) {\n return function singleQueryFn(predicate: Predicate, options?: Options) {\n const results = queryAllByQuery(instance)(predicate, options);\n\n if (results.length > 1) {\n throw new ErrorWithStack(getMultipleError(predicate), singleQueryFn);\n }\n\n if (results.length === 0) {\n return null;\n }\n\n return results[0];\n };\n }\n\n function getByQuery(instance: ReactTestInstance) {\n return function getFn(predicate: Predicate, options?: Options) {\n const results = queryAllByQuery(instance)(predicate, options);\n\n if (results.length > 1) {\n throw new ErrorWithStack(getMultipleError(predicate), getFn);\n }\n\n if (results.length === 0) {\n throw new ErrorWithStack(getMissingError(predicate), getFn);\n }\n\n return results[0];\n };\n }\n\n function findAllByQuery(instance: ReactTestInstance) {\n return function findAllFn(\n predicate: Predicate,\n queryOptions?: Options,\n waitForOptions?: WaitForOptions\n ) {\n return waitFor(\n () => getAllByQuery(instance)(predicate, queryOptions),\n waitForOptions\n );\n };\n }\n\n function findByQuery(instance: ReactTestInstance) {\n return function findFn(\n predicate: Predicate,\n queryOptions?: Options,\n waitForOptions?: WaitForOptions\n ) {\n return waitFor(\n () => getByQuery(instance)(predicate, queryOptions),\n waitForOptions\n );\n };\n }\n\n return {\n getBy: getByQuery,\n getAllBy: getAllByQuery,\n queryBy: queryByQuery,\n queryAllBy: queryAllByQuery,\n findBy: findByQuery,\n findAllBy: findAllByQuery,\n };\n}\n"],"file":"makeQueries.js"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
+
import { TextMatch } from '../matches';
|
|
3
|
+
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './makeQueries';
|
|
4
|
+
export declare type ByRoleQueries = {
|
|
5
|
+
getByRole: GetByQuery<TextMatch>;
|
|
6
|
+
getAllByRole: GetAllByQuery<TextMatch>;
|
|
7
|
+
queryByRole: QueryByQuery<TextMatch>;
|
|
8
|
+
queryAllByRole: QueryAllByQuery<TextMatch>;
|
|
9
|
+
findByRole: FindByQuery<TextMatch>;
|
|
10
|
+
findAllByRole: FindAllByQuery<TextMatch>;
|
|
11
|
+
};
|
|
12
|
+
export declare const bindByRoleQueries: (instance: ReactTestInstance) => ByRoleQueries;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.bindByRoleQueries = void 0;
|
|
7
|
+
|
|
8
|
+
var _matchStringProp = require("../helpers/matchers/matchStringProp");
|
|
9
|
+
|
|
10
|
+
var _makeQueries = require("./makeQueries");
|
|
11
|
+
|
|
12
|
+
const queryAllByRole = instance => function queryAllByRoleFn(role) {
|
|
13
|
+
return instance.findAll(node => typeof node.type === 'string' && (0, _matchStringProp.matchStringProp)(node.props.accessibilityRole, role));
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const getMultipleError = role => `Found multiple elements with accessibilityRole: ${String(role)} `;
|
|
17
|
+
|
|
18
|
+
const getMissingError = role => `Unable to find an element with accessibilityRole: ${String(role)}`;
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
getBy,
|
|
22
|
+
getAllBy,
|
|
23
|
+
queryBy,
|
|
24
|
+
queryAllBy,
|
|
25
|
+
findBy,
|
|
26
|
+
findAllBy
|
|
27
|
+
} = (0, _makeQueries.makeQueries)(queryAllByRole, getMissingError, getMultipleError);
|
|
28
|
+
|
|
29
|
+
const bindByRoleQueries = instance => ({
|
|
30
|
+
getByRole: getBy(instance),
|
|
31
|
+
getAllByRole: getAllBy(instance),
|
|
32
|
+
queryByRole: queryBy(instance),
|
|
33
|
+
queryAllByRole: queryAllBy(instance),
|
|
34
|
+
findByRole: findBy(instance),
|
|
35
|
+
findAllByRole: findAllBy(instance)
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
exports.bindByRoleQueries = bindByRoleQueries;
|
|
39
|
+
//# sourceMappingURL=role.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/queries/role.ts"],"names":["queryAllByRole","instance","queryAllByRoleFn","role","findAll","node","type","props","accessibilityRole","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","bindByRoleQueries","getByRole","getAllByRole","queryByRole","findByRole","findAllByRole"],"mappings":";;;;;;;AAEA;;AACA;;AAUA,MAAMA,cAAc,GAClBC,QADqB,IAGrB,SAASC,gBAAT,CAA0BC,IAA1B,EAAgC;AAC9B,SAAOF,QAAQ,CAACG,OAAT,CACJC,IAAD,IACE,OAAOA,IAAI,CAACC,IAAZ,KAAqB,QAArB,IACA,sCAAgBD,IAAI,CAACE,KAAL,CAAWC,iBAA3B,EAA8CL,IAA9C,CAHG,CAAP;AAKD,CATH;;AAWA,MAAMM,gBAAgB,GAAIN,IAAD,IACtB,mDAAkDO,MAAM,CAACP,IAAD,CAAO,GADlE;;AAEA,MAAMQ,eAAe,GAAIR,IAAD,IACrB,qDAAoDO,MAAM,CAACP,IAAD,CAAO,EADpE;;AAGA,MAAM;AAAES,EAAAA,KAAF;AAASC,EAAAA,QAAT;AAAmBC,EAAAA,OAAnB;AAA4BC,EAAAA,UAA5B;AAAwCC,EAAAA,MAAxC;AAAgDC,EAAAA;AAAhD,IAA8D,8BAClEjB,cADkE,EAElEW,eAFkE,EAGlEF,gBAHkE,CAApE;;AAeO,MAAMS,iBAAiB,GAC5BjB,QAD+B,KAEZ;AACnBkB,EAAAA,SAAS,EAAEP,KAAK,CAACX,QAAD,CADG;AAEnBmB,EAAAA,YAAY,EAAEP,QAAQ,CAACZ,QAAD,CAFH;AAGnBoB,EAAAA,WAAW,EAAEP,OAAO,CAACb,QAAD,CAHD;AAInBD,EAAAA,cAAc,EAAEe,UAAU,CAACd,QAAD,CAJP;AAKnBqB,EAAAA,UAAU,EAAEN,MAAM,CAACf,QAAD,CALC;AAMnBsB,EAAAA,aAAa,EAAEN,SAAS,CAAChB,QAAD;AANL,CAFY,CAA1B","sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { TextMatch } from '../matches';\nimport { matchStringProp } from '../helpers/matchers/matchStringProp';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\nconst queryAllByRole = (\n instance: ReactTestInstance\n): ((role: TextMatch) => Array<ReactTestInstance>) =>\n function queryAllByRoleFn(role) {\n return instance.findAll(\n (node) =>\n typeof node.type === 'string' &&\n matchStringProp(node.props.accessibilityRole, role)\n );\n };\n\nconst getMultipleError = (role: TextMatch) =>\n `Found multiple elements with accessibilityRole: ${String(role)} `;\nconst getMissingError = (role: TextMatch) =>\n `Unable to find an element with accessibilityRole: ${String(role)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByRole,\n getMissingError,\n getMultipleError\n);\n\nexport type ByRoleQueries = {\n getByRole: GetByQuery<TextMatch>;\n getAllByRole: GetAllByQuery<TextMatch>;\n queryByRole: QueryByQuery<TextMatch>;\n queryAllByRole: QueryAllByQuery<TextMatch>;\n findByRole: FindByQuery<TextMatch>;\n findAllByRole: FindAllByQuery<TextMatch>;\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"],"file":"role.js"}
|
package/build/queries/text.js
CHANGED
|
@@ -22,8 +22,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
22
22
|
const getChildrenAsText = (children, TextComponent) => {
|
|
23
23
|
const textContent = [];
|
|
24
24
|
React.Children.forEach(children, child => {
|
|
25
|
-
var _child$props;
|
|
26
|
-
|
|
27
25
|
if (typeof child === 'string') {
|
|
28
26
|
textContent.push(child);
|
|
29
27
|
return;
|
|
@@ -34,7 +32,7 @@ const getChildrenAsText = (children, TextComponent) => {
|
|
|
34
32
|
return;
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
if (child
|
|
35
|
+
if (child?.props?.children) {
|
|
38
36
|
// Bail on traversing text children down the tree if current node (child)
|
|
39
37
|
// has no text. In such situations, react-test-renderer will traverse down
|
|
40
38
|
// this tree in a separate call and run this query again. As a result, the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/text.ts"],"names":["getChildrenAsText","children","TextComponent","textContent","React","Children","forEach","child","push","toString","props","Fragment","getNodeByText","node","text","options","Text","require","isTextComponent","textChildren","textToTest","join","exact","normalizer","error","queryAllByText","instance","queryAllByTextFn","results","findAll","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","bindByTextQueries","getByText","getAllByText","queryByText","findByText","findAllByText"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAeA,MAAMA,iBAAiB,GAAG,CACxBC,QADwB,EAExBC,aAFwB,KAGrB;AACH,QAAMC,WAAqB,GAAG,EAA9B;AACAC,EAAAA,KAAK,CAACC,QAAN,CAAeC,OAAf,CAAuBL,QAAvB,EAAkCM,KAAD,IAAW;
|
|
1
|
+
{"version":3,"sources":["../../src/queries/text.ts"],"names":["getChildrenAsText","children","TextComponent","textContent","React","Children","forEach","child","push","toString","props","Fragment","getNodeByText","node","text","options","Text","require","isTextComponent","textChildren","textToTest","join","exact","normalizer","error","queryAllByText","instance","queryAllByTextFn","results","findAll","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy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QAAD,CAJP;AAKnBiB,EAAAA,UAAU,EAAEN,MAAM,CAACX,QAAD,CALC;AAMnBkB,EAAAA,aAAa,EAAEN,SAAS,CAACZ,QAAD;AANL,CAFY,CAA1B","sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport * as React from 'react';\nimport { createLibraryNotSupportedError } from '../helpers/errors';\nimport { filterNodeByType } from '../helpers/filterNodeByType';\nimport { matches, TextMatch } from '../matches';\nimport type { NormalizerFn } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\nexport type TextMatchOptions = {\n exact?: boolean;\n normalizer?: NormalizerFn;\n};\n\nconst getChildrenAsText = (\n children: React.ReactChild[],\n TextComponent: React.ComponentType\n) => {\n const textContent: string[] = [];\n React.Children.forEach(children, (child) => {\n if (typeof child === 'string') {\n textContent.push(child);\n return;\n }\n\n if (typeof child === 'number') {\n textContent.push(child.toString());\n return;\n }\n\n if (child?.props?.children) {\n // Bail on traversing text children down the tree if current node (child)\n // has no text. In such situations, react-test-renderer will traverse down\n // this tree in a separate call and run this query again. As a result, the\n // query will match the deepest text node that matches requested text.\n if (filterNodeByType(child, TextComponent)) {\n return;\n }\n\n if (filterNodeByType(child, React.Fragment)) {\n textContent.push(\n ...getChildrenAsText(child.props.children, TextComponent)\n );\n }\n }\n });\n\n return textContent;\n};\n\nconst getNodeByText = (\n node: ReactTestInstance,\n text: TextMatch,\n options: TextMatchOptions = {}\n) => {\n try {\n const { Text } = require('react-native');\n const isTextComponent = filterNodeByType(node, Text);\n if (isTextComponent) {\n const textChildren = getChildrenAsText(node.props.children, Text);\n if (textChildren) {\n const textToTest = textChildren.join('');\n const { exact, normalizer } = options;\n return matches(text, textToTest, normalizer, exact);\n }\n }\n return false;\n } catch (error) {\n throw createLibraryNotSupportedError(error);\n }\n};\n\nconst queryAllByText = (\n instance: ReactTestInstance\n): ((\n text: TextMatch,\n options?: TextMatchOptions\n) => Array<ReactTestInstance>) =>\n function queryAllByTextFn(text, options) {\n const results = instance.findAll((node) =>\n getNodeByText(node, text, options)\n );\n\n return results;\n };\n\nconst getMultipleError = (text: TextMatch) =>\n `Found multiple elements with text: ${String(text)}`;\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, TextMatchOptions>;\n getAllByText: GetAllByQuery<TextMatch, TextMatchOptions>;\n queryByText: QueryByQuery<TextMatch, TextMatchOptions>;\n queryAllByText: QueryAllByQuery<TextMatch, TextMatchOptions>;\n findByText: FindByQuery<TextMatch, TextMatchOptions>;\n findAllByText: FindAllByQuery<TextMatch, TextMatchOptions>;\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"],"file":"text.js"}
|