@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
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _waitFor = _interopRequireDefault(require("../waitFor"));
|
|
9
|
-
|
|
10
|
-
var _errors = require("../helpers/errors");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
function isNodeValid(node) {
|
|
15
|
-
return typeof node.type === 'string';
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function makeAliases(aliases, query) {
|
|
19
|
-
return aliases.map(alias => ({
|
|
20
|
-
[alias]: query
|
|
21
|
-
})).reduce((acc, query) => ({ ...acc,
|
|
22
|
-
...query
|
|
23
|
-
}), {});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const makeA11yQuery = (name, queryNames, matcherFn) => instance => {
|
|
27
|
-
const getBy = matcher => {
|
|
28
|
-
try {
|
|
29
|
-
return instance.find(node => isNodeValid(node) && matcherFn(node.props[name], matcher));
|
|
30
|
-
} catch (error) {
|
|
31
|
-
throw new _errors.ErrorWithStack((0, _errors.prepareErrorMessage)(error, name, matcher), getBy);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const getAllBy = matcher => {
|
|
36
|
-
const results = instance.findAll(node => isNodeValid(node) && matcherFn(node.props[name], matcher));
|
|
37
|
-
|
|
38
|
-
if (results.length === 0) {
|
|
39
|
-
throw new _errors.ErrorWithStack((0, _errors.prepareErrorMessage)(new Error('No instances found'), name, matcher), getAllBy);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return results;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const queryBy = matcher => {
|
|
46
|
-
try {
|
|
47
|
-
return getBy(matcher);
|
|
48
|
-
} catch (error) {
|
|
49
|
-
return (0, _errors.createQueryByError)(error, queryBy);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const queryAllBy = matcher => {
|
|
54
|
-
try {
|
|
55
|
-
return getAllBy(matcher);
|
|
56
|
-
} catch (error) {
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const findBy = (matcher, waitForOptions) => {
|
|
62
|
-
return (0, _waitFor.default)(() => getBy(matcher), waitForOptions);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const findAllBy = (matcher, waitForOptions) => {
|
|
66
|
-
return (0, _waitFor.default)(() => getAllBy(matcher), waitForOptions);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
return { ...makeAliases(queryNames.getBy, getBy),
|
|
70
|
-
...makeAliases(queryNames.getAllBy, getAllBy),
|
|
71
|
-
...makeAliases(queryNames.queryBy, queryBy),
|
|
72
|
-
...makeAliases(queryNames.queryAllBy, queryAllBy),
|
|
73
|
-
...makeAliases(queryNames.findBy, findBy),
|
|
74
|
-
...makeAliases(queryNames.findAllBy, findAllBy)
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
var _default = makeA11yQuery;
|
|
79
|
-
exports.default = _default;
|
|
80
|
-
//# sourceMappingURL=makeA11yQuery.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/makeA11yQuery.ts"],"names":["isNodeValid","node","type","makeAliases","aliases","query","map","alias","reduce","acc","makeA11yQuery","name","queryNames","matcherFn","instance","getBy","matcher","find","props","error","ErrorWithStack","getAllBy","results","findAll","length","Error","queryBy","queryAllBy","findBy","waitForOptions","findAllBy"],"mappings":";;;;;;;AACA;;AAEA;;;;AAMA,SAASA,WAAT,CAAqBC,IAArB,EAA8C;AAC5C,SAAO,OAAOA,IAAI,CAACC,IAAZ,KAAqB,QAA5B;AACD;;AAED,SAASC,WAAT,CAAqBC,OAArB,EAA6CC,KAA7C,EAA8D;AAC5D,SAAOD,OAAO,CACXE,GADI,CACCC,KAAD,KAAY;AAAE,KAACA,KAAD,GAASF;AAAX,GAAZ,CADA,EAEJG,MAFI,CAEG,CAACC,GAAD,EAAMJ,KAAN,MAAiB,EAAE,GAAGI,GAAL;AAAU,OAAGJ;AAAb,GAAjB,CAFH,EAE2C,EAF3C,CAAP;AAGD;;AAWD,MAAMK,aAAa,GAAG,CACpBC,IADoB,EAEpBC,UAFoB,EAGpBC,SAHoB,KAIhBC,QAAD,IAAiC;AACpC,QAAMC,KAAK,GAAIC,OAAD,IAAgB;AAC5B,QAAI;AACF,aAAOF,QAAQ,CAACG,IAAT,CACJhB,IAAD,IAAUD,WAAW,CAACC,IAAD,CAAX,IAAqBY,SAAS,CAACZ,IAAI,CAACiB,KAAL,CAAWP,IAAX,CAAD,EAAmBK,OAAnB,CADnC,CAAP;AAGD,KAJD,CAIE,OAAOG,KAAP,EAAc;AACd,YAAM,IAAIC,sBAAJ,CACJ,iCAAoBD,KAApB,EAA2BR,IAA3B,EAAiCK,OAAjC,CADI,EAEJD,KAFI,CAAN;AAID;AACF,GAXD;;AAaA,QAAMM,QAAQ,GAAIL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AAU,CAACc,OAAZ,EAAqBA,OAArB,CAHT;AAIL,OAAGvB,WAAW,CAACS,UAAU,CAACe,UAAZ,EAAwBA,UAAxB,CAJT;AAKL,OAAGxB,WAAW,CAACS,UAAU,CAACgB,MAAZ,EAAoBA,MAApB,CALT;AAML,OAAGzB,WAAW,CAACS,UAAU,CAACkB,SAAZ,EAAuBA,SAAvB;AANT,GAAP;AAQD,CAjED;;eAmEepB,a","sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport waitFor from '../waitFor';\nimport type { WaitForOptions } from '../waitFor';\nimport {\n ErrorWithStack,\n prepareErrorMessage,\n createQueryByError,\n} from '../helpers/errors';\n\nfunction isNodeValid(node: ReactTestInstance) {\n return typeof node.type === 'string';\n}\n\nfunction makeAliases(aliases: Array<string>, query: Function) {\n return aliases\n .map((alias) => ({ [alias]: query }))\n .reduce((acc, query) => ({ ...acc, ...query }), {});\n}\n\ntype QueryNames = {\n getBy: Array<string>;\n getAllBy: Array<string>;\n queryBy: Array<string>;\n queryAllBy: Array<string>;\n findBy: Array<string>;\n findAllBy: Array<string>;\n};\n\nconst makeA11yQuery = <P extends unknown, M extends unknown>(\n name: string,\n queryNames: QueryNames,\n matcherFn: (prop: P, value: M) => boolean\n) => (instance: ReactTestInstance) => {\n const getBy = (matcher: M) => {\n try {\n return instance.find(\n (node) => isNodeValid(node) && matcherFn(node.props[name], matcher)\n );\n } catch (error) {\n throw new ErrorWithStack(\n prepareErrorMessage(error, name, matcher),\n getBy\n );\n }\n };\n\n const getAllBy = (matcher: M) => {\n const results = instance.findAll(\n (node) => isNodeValid(node) && matcherFn(node.props[name], matcher)\n );\n\n if (results.length === 0) {\n throw new ErrorWithStack(\n prepareErrorMessage(new Error('No instances found'), name, matcher),\n getAllBy\n );\n }\n\n return results;\n };\n\n const queryBy = (matcher: M) => {\n try {\n return getBy(matcher);\n } catch (error) {\n return createQueryByError(error, queryBy);\n }\n };\n\n const queryAllBy = (matcher: M) => {\n try {\n return getAllBy(matcher);\n } catch (error) {\n return [];\n }\n };\n\n const findBy = (matcher: M, waitForOptions?: WaitForOptions) => {\n return waitFor(() => getBy(matcher), waitForOptions);\n };\n\n const findAllBy = (matcher: M, waitForOptions?: WaitForOptions) => {\n return waitFor(() => getAllBy(matcher), waitForOptions);\n };\n\n return {\n ...makeAliases(queryNames.getBy, getBy),\n ...makeAliases(queryNames.getAllBy, getAllBy),\n ...makeAliases(queryNames.queryBy, queryBy),\n ...makeAliases(queryNames.queryAllBy, queryAllBy),\n ...makeAliases(queryNames.findBy, findBy),\n ...makeAliases(queryNames.findAllBy, findAllBy),\n };\n};\n\nexport default makeA11yQuery;\n"],"file":"makeA11yQuery.js"}
|