@testing-library/react-native 9.2.0 → 10.1.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.
Files changed (64) hide show
  1. package/README.md +4 -6
  2. package/build/cleanup.js +4 -0
  3. package/build/cleanup.js.map +1 -1
  4. package/build/index.flow.js +107 -95
  5. package/build/pure.d.ts +5 -1
  6. package/build/pure.js +8 -0
  7. package/build/pure.js.map +1 -1
  8. package/build/{helpers → queries}/a11yAPI.d.ts +0 -0
  9. package/build/{helpers → queries}/a11yAPI.js +0 -0
  10. package/build/{helpers → queries}/a11yAPI.js.map +1 -1
  11. package/build/queries/displayValue.d.ts +13 -0
  12. package/build/{helpers/byDisplayValue.js → queries/displayValue.js} +23 -18
  13. package/build/queries/displayValue.js.map +1 -0
  14. package/build/{helpers → queries}/makeA11yQuery.d.ts +0 -0
  15. package/build/{helpers → queries}/makeA11yQuery.js +1 -1
  16. package/build/{helpers → queries}/makeA11yQuery.js.map +1 -1
  17. package/build/queries/makeQueries.d.ts +19 -0
  18. package/build/{helpers → queries}/makeQueries.js +17 -16
  19. package/build/queries/makeQueries.js.map +1 -0
  20. package/build/queries/placeholderText.d.ts +13 -0
  21. package/build/{helpers/byPlaceholderText.js → queries/placeholderText.js} +23 -18
  22. package/build/queries/placeholderText.js.map +1 -0
  23. package/build/queries/testId.d.ts +13 -0
  24. package/build/{helpers/byTestId.js → queries/testId.js} +19 -14
  25. package/build/queries/testId.js.map +1 -0
  26. package/build/queries/text.d.ts +17 -0
  27. package/build/{helpers/byText.js → queries/text.js} +25 -20
  28. package/build/queries/text.js.map +1 -0
  29. package/build/queries/unsafeProps.d.ts +16 -0
  30. package/build/queries/unsafeProps.js +58 -0
  31. package/build/queries/unsafeProps.js.map +1 -0
  32. package/build/queries/unsafeType.d.ts +9 -0
  33. package/build/queries/unsafeType.js +54 -0
  34. package/build/queries/unsafeType.js.map +1 -0
  35. package/build/render.d.ts +35 -44
  36. package/build/render.js +7 -12
  37. package/build/render.js.map +1 -1
  38. package/build/screen.d.ts +4 -0
  39. package/build/screen.js +115 -0
  40. package/build/screen.js.map +1 -0
  41. package/build/within.d.ts +34 -44
  42. package/build/within.js +16 -7
  43. package/build/within.js.map +1 -1
  44. package/package.json +1 -1
  45. package/typings/index.flow.js +107 -95
  46. package/build/helpers/byDisplayValue.d.ts +0 -6
  47. package/build/helpers/byDisplayValue.js.map +0 -1
  48. package/build/helpers/byPlaceholderText.d.ts +0 -6
  49. package/build/helpers/byPlaceholderText.js.map +0 -1
  50. package/build/helpers/byTestId.d.ts +0 -6
  51. package/build/helpers/byTestId.js.map +0 -1
  52. package/build/helpers/byText.d.ts +0 -10
  53. package/build/helpers/byText.js.map +0 -1
  54. package/build/helpers/findByAPI.d.ts +0 -17
  55. package/build/helpers/findByAPI.js +0 -33
  56. package/build/helpers/findByAPI.js.map +0 -1
  57. package/build/helpers/getByAPI.d.ts +0 -31
  58. package/build/helpers/getByAPI.js +0 -83
  59. package/build/helpers/getByAPI.js.map +0 -1
  60. package/build/helpers/makeQueries.d.ts +0 -20
  61. package/build/helpers/makeQueries.js.map +0 -1
  62. package/build/helpers/queryByAPI.d.ts +0 -39
  63. package/build/helpers/queryByAPI.js +0 -87
  64. package/build/helpers/queryByAPI.js.map +0 -1
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.makeQueries = makeQueries;
7
7
 
8
- var _waitFor = _interopRequireDefault(require("../waitFor"));
8
+ var _errors = require("../helpers/errors");
9
9
 
10
- var _errors = require("./errors");
10
+ var _waitFor = _interopRequireDefault(require("../waitFor"));
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
@@ -39,11 +39,11 @@ Example:
39
39
 
40
40
  function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
41
41
  function getAllByQuery(instance) {
42
- return function getAllFn(args, queryOptions) {
43
- const results = queryAllByQuery(instance)(args, queryOptions);
42
+ return function getAllFn(predicate, options) {
43
+ const results = queryAllByQuery(instance)(predicate, options);
44
44
 
45
45
  if (results.length === 0) {
46
- throw new _errors.ErrorWithStack(getMissingError(args), getAllFn);
46
+ throw new _errors.ErrorWithStack(getMissingError(predicate), getAllFn);
47
47
  }
48
48
 
49
49
  return results;
@@ -51,11 +51,11 @@ function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
51
51
  }
52
52
 
53
53
  function queryByQuery(instance) {
54
- return function singleQueryFn(args, queryOptions) {
55
- const results = queryAllByQuery(instance)(args, queryOptions);
54
+ return function singleQueryFn(predicate, options) {
55
+ const results = queryAllByQuery(instance)(predicate, options);
56
56
 
57
57
  if (results.length > 1) {
58
- throw new _errors.ErrorWithStack(getMultipleError(args), singleQueryFn);
58
+ throw new _errors.ErrorWithStack(getMultipleError(predicate), singleQueryFn);
59
59
  }
60
60
 
61
61
  if (results.length === 0) {
@@ -67,15 +67,15 @@ function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
67
67
  }
68
68
 
69
69
  function getByQuery(instance) {
70
- return function getFn(args, queryOptions) {
71
- const results = queryAllByQuery(instance)(args, queryOptions);
70
+ return function getFn(predicate, options) {
71
+ const results = queryAllByQuery(instance)(predicate, options);
72
72
 
73
73
  if (results.length > 1) {
74
- throw new _errors.ErrorWithStack(getMultipleError(args), getFn);
74
+ throw new _errors.ErrorWithStack(getMultipleError(predicate), getFn);
75
75
  }
76
76
 
77
77
  if (results.length === 0) {
78
- throw new _errors.ErrorWithStack(getMissingError(args), getFn);
78
+ throw new _errors.ErrorWithStack(getMissingError(predicate), getFn);
79
79
  }
80
80
 
81
81
  return results[0];
@@ -83,18 +83,18 @@ function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
83
83
  }
84
84
 
85
85
  function findAllByQuery(instance) {
86
- return function findAllFn(args, queryOptions, waitForOptions = {}) {
86
+ return function findAllFn(predicate, queryOptions, waitForOptions = {}) {
87
87
  const deprecatedWaitForOptions = extractDeprecatedWaitForOptionUsage(queryOptions);
88
- return (0, _waitFor.default)(() => getAllByQuery(instance)(args, queryOptions), { ...deprecatedWaitForOptions,
88
+ return (0, _waitFor.default)(() => getAllByQuery(instance)(predicate, queryOptions), { ...deprecatedWaitForOptions,
89
89
  ...waitForOptions
90
90
  });
91
91
  };
92
92
  }
93
93
 
94
94
  function findByQuery(instance) {
95
- return function findFn(args, queryOptions, waitForOptions = {}) {
95
+ return function findFn(predicate, queryOptions, waitForOptions = {}) {
96
96
  const deprecatedWaitForOptions = extractDeprecatedWaitForOptionUsage(queryOptions);
97
- return (0, _waitFor.default)(() => getByQuery(instance)(args, queryOptions), { ...deprecatedWaitForOptions,
97
+ return (0, _waitFor.default)(() => getByQuery(instance)(predicate, queryOptions), { ...deprecatedWaitForOptions,
98
98
  ...waitForOptions
99
99
  });
100
100
  };
@@ -104,6 +104,7 @@ function makeQueries(queryAllByQuery, getMissingError, getMultipleError) {
104
104
  getBy: getByQuery,
105
105
  getAllBy: getAllByQuery,
106
106
  queryBy: queryByQuery,
107
+ queryAllBy: queryAllByQuery,
107
108
  findBy: findByQuery,
108
109
  findAllBy: findAllByQuery
109
110
  };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/queries/makeQueries.ts"],"names":["deprecatedKeys","extractDeprecatedWaitForOptionUsage","queryOptions","waitForOptions","timeout","interval","stackTraceError","forEach","key","option","console","warn","toString","makeQueries","queryAllByQuery","getMissingError","getMultipleError","getAllByQuery","instance","getAllFn","predicate","options","results","length","ErrorWithStack","queryByQuery","singleQueryFn","getByQuery","getFn","findAllByQuery","findAllFn","deprecatedWaitForOptions","findByQuery","findFn","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy"],"mappings":";;;;;;;AACA;;AACA;;;;AA8CA;AACA;AACA,MAAMA,cAAwC,GAAG,CAC/C,SAD+C,EAE/C,UAF+C,EAG/C,iBAH+C,CAAjD;;AAKA,MAAMC,mCAAmC,GAAIC,YAAD,IAAmC;AAC7E,MAAIA,YAAJ,EAAk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Q,MAAMyB,UAAU,CAACT,QAAD,CAAV,CAAqBE,SAArB,EAAgClB,YAAhC,CAAd,EAA6D,EAClE,GAAG6B,wBAD+D;AAElE,WAAG5B;AAF+D,OAA7D,CAAP;AAID,KAZD;AAaD;;AAED,SAAO;AACL+B,IAAAA,KAAK,EAAEP,UADF;AAELQ,IAAAA,QAAQ,EAAElB,aAFL;AAGLmB,IAAAA,OAAO,EAAEX,YAHJ;AAILY,IAAAA,UAAU,EAAEvB,eAJP;AAKLwB,IAAAA,MAAM,EAAEN,WALH;AAMLO,IAAAA,SAAS,EAAEV;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> = (\n predicate: Predicate,\n options?: Options\n) => ReactTestInstance;\n\nexport type GetAllByQuery<Predicate, Options> = (\n predicate: Predicate,\n options?: Options\n) => ReactTestInstance[];\n\nexport type QueryByQuery<Predicate, Options> = (\n predicate: Predicate,\n options?: Options\n) => ReactTestInstance | null;\n\nexport type QueryAllByQuery<Predicate, Options> = (\n predicate: Predicate,\n options?: Options\n) => ReactTestInstance[];\n\nexport type FindByQuery<Predicate, Options> = (\n predicate: Predicate,\n options?: Options & WaitForOptions,\n waitForOptions?: WaitForOptions\n) => Promise<ReactTestInstance>;\n\nexport type FindAllByQuery<Predicate, Options> = (\n predicate: Predicate,\n options?: Options & WaitForOptions,\n waitForOptions?: WaitForOptions\n) => Promise<ReactTestInstance[]>;\n\ntype UnboundQuery<Query> = (instance: ReactTestInstance) => Query;\n\nexport type UnboundQueries<Predicate, Options> = {\n getBy: UnboundQuery<GetByQuery<Predicate, Options>>;\n getAllBy: UnboundQuery<GetAllByQuery<Predicate, Options>>;\n queryBy: UnboundQuery<QueryByQuery<Predicate, Options>>;\n queryAllBy: UnboundQuery<QueryAllByQuery<Predicate, Options>>;\n findBy: UnboundQuery<FindByQuery<Predicate, Options>>;\n findAllBy: UnboundQuery<FindAllByQuery<Predicate, Options>>;\n};\n\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\nconst deprecatedKeys: (keyof WaitForOptions)[] = [\n 'timeout',\n 'interval',\n 'stackTraceError',\n];\nconst extractDeprecatedWaitForOptionUsage = (queryOptions?: WaitForOptions) => {\n if (queryOptions) {\n const waitForOptions: WaitForOptions = {\n timeout: queryOptions.timeout,\n interval: queryOptions.interval,\n stackTraceError: queryOptions.stackTraceError,\n };\n deprecatedKeys.forEach((key) => {\n const option = queryOptions[key];\n if (option) {\n // eslint-disable-next-line no-console\n console.warn(\n `Use of option \"${key}\" in a findBy* query's second parameter, TextMatchOptions, is deprecated. Please pass this option in the third, WaitForOptions, parameter. \nExample: \n\n findByText(text, {}, { ${key}: ${option.toString()} })`\n );\n }\n });\n return waitForOptions;\n }\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 & WaitForOptions,\n waitForOptions: WaitForOptions = {}\n ) {\n const deprecatedWaitForOptions = extractDeprecatedWaitForOptionUsage(\n queryOptions\n );\n return waitFor(() => getAllByQuery(instance)(predicate, queryOptions), {\n ...deprecatedWaitForOptions,\n ...waitForOptions,\n });\n };\n }\n\n function findByQuery(instance: ReactTestInstance) {\n return function findFn(\n predicate: Predicate,\n queryOptions?: Options & WaitForOptions,\n waitForOptions: WaitForOptions = {}\n ) {\n const deprecatedWaitForOptions = extractDeprecatedWaitForOptionUsage(\n queryOptions\n );\n return waitFor(() => getByQuery(instance)(predicate, queryOptions), {\n ...deprecatedWaitForOptions,\n ...waitForOptions,\n });\n };\n }\n\n return {\n getBy: getByQuery,\n getAllBy: getAllByQuery,\n queryBy: queryByQuery,\n queryAllBy: queryAllByQuery,\n findBy: findByQuery,\n findAllBy: findAllByQuery,\n };\n}\n"],"file":"makeQueries.js"}
@@ -0,0 +1,13 @@
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
+ import type { TextMatchOptions } from './text';
5
+ export declare type ByPlaceholderTextQueries = {
6
+ getByPlaceholderText: GetByQuery<TextMatch, TextMatchOptions>;
7
+ getAllByPlaceholderText: GetAllByQuery<TextMatch, TextMatchOptions>;
8
+ queryByPlaceholderText: QueryByQuery<TextMatch, TextMatchOptions>;
9
+ queryAllByPlaceholderText: QueryAllByQuery<TextMatch, TextMatchOptions>;
10
+ findByPlaceholderText: FindByQuery<TextMatch, TextMatchOptions>;
11
+ findAllByPlaceholderText: FindAllByQuery<TextMatch, TextMatchOptions>;
12
+ };
13
+ export declare const bindByPlaceholderTextQueries: (instance: ReactTestInstance) => ByPlaceholderTextQueries;
@@ -3,15 +3,15 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.queryByPlaceholderText = exports.queryAllByPlaceholderText = exports.getByPlaceholderText = exports.getAllByPlaceholderText = exports.findByPlaceholderText = exports.findAllByPlaceholderText = void 0;
6
+ exports.bindByPlaceholderTextQueries = void 0;
7
7
 
8
- var _matches = require("../matches");
8
+ var _errors = require("../helpers/errors");
9
9
 
10
- var _makeQueries = require("./makeQueries");
10
+ var _filterNodeByType = require("../helpers/filterNodeByType");
11
11
 
12
- var _filterNodeByType = require("./filterNodeByType");
12
+ var _matches = require("../matches");
13
13
 
14
- var _errors = require("./errors");
14
+ var _makeQueries = require("./makeQueries");
15
15
 
16
16
  const getTextInputNodeByPlaceholderText = (node, placeholder, options = {}) => {
17
17
  try {
@@ -33,22 +33,27 @@ const queryAllByPlaceholderText = instance => function queryAllByPlaceholderFn(p
33
33
  return instance.findAll(node => getTextInputNodeByPlaceholderText(node, placeholder, queryOptions));
34
34
  };
35
35
 
36
- exports.queryAllByPlaceholderText = queryAllByPlaceholderText;
37
-
38
36
  const getMultipleError = placeholder => `Found multiple elements with placeholder: ${String(placeholder)} `;
39
37
 
40
38
  const getMissingError = placeholder => `Unable to find an element with placeholder: ${String(placeholder)}`;
41
39
 
42
40
  const {
43
- getBy: getByPlaceholderText,
44
- getAllBy: getAllByPlaceholderText,
45
- queryBy: queryByPlaceholderText,
46
- findBy: findByPlaceholderText,
47
- findAllBy: findAllByPlaceholderText
41
+ getBy,
42
+ getAllBy,
43
+ queryBy,
44
+ queryAllBy,
45
+ findBy,
46
+ findAllBy
48
47
  } = (0, _makeQueries.makeQueries)(queryAllByPlaceholderText, getMissingError, getMultipleError);
49
- exports.findAllByPlaceholderText = findAllByPlaceholderText;
50
- exports.findByPlaceholderText = findByPlaceholderText;
51
- exports.queryByPlaceholderText = queryByPlaceholderText;
52
- exports.getAllByPlaceholderText = getAllByPlaceholderText;
53
- exports.getByPlaceholderText = getByPlaceholderText;
54
- //# sourceMappingURL=byPlaceholderText.js.map
48
+
49
+ const bindByPlaceholderTextQueries = instance => ({
50
+ getByPlaceholderText: getBy(instance),
51
+ getAllByPlaceholderText: getAllBy(instance),
52
+ queryByPlaceholderText: queryBy(instance),
53
+ queryAllByPlaceholderText: queryAllBy(instance),
54
+ findByPlaceholderText: findBy(instance),
55
+ findAllByPlaceholderText: findAllBy(instance)
56
+ });
57
+
58
+ exports.bindByPlaceholderTextQueries = bindByPlaceholderTextQueries;
59
+ //# sourceMappingURL=placeholderText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/queries/placeholderText.ts"],"names":["getTextInputNodeByPlaceholderText","node","placeholder","options","TextInput","require","exact","normalizer","props","error","queryAllByPlaceholderText","instance","queryAllByPlaceholderFn","queryOptions","findAll","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","bindByPlaceholderTextQueries","getByPlaceholderText","getAllByPlaceholderText","queryByPlaceholderText","findByPlaceholderText","findAllByPlaceholderText"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AAWA,MAAMA,iCAAiC,GAAG,CACxCC,IADwC,EAExCC,WAFwC,EAGxCC,OAAyB,GAAG,EAHY,KAIrC;AACH,MAAI;AACF,UAAM;AAAEC,MAAAA;AAAF,QAAgBC,OAAO,CAAC,cAAD,CAA7B;;AACA,UAAM;AAAEC,MAAAA,KAAF;AAASC,MAAAA;AAAT,QAAwBJ,OAA9B;AACA,WACE,wCAAiBF,IAAjB,EAAuBG,SAAvB,KACA,sBAAQF,WAAR,EAAqBD,IAAI,CAACO,KAAL,CAAWN,WAAhC,EAA6CK,UAA7C,EAAyDD,KAAzD,CAFF;AAID,GAPD,CAOE,OAAOG,KAAP,EAAc;AACd,UAAM,4CAA+BA,KAA/B,CAAN;AACD;AACF,CAfD;;AAiBA,MAAMC,yBAAyB,GAC7BC,QADgC,IAMhC,SAASC,uBAAT,CAAiCV,WAAjC,EAA8CW,YAA9C,EAA4D;AAC1D,SAAOF,QAAQ,CAACG,OAAT,CAAkBb,IAAD,IACtBD,iCAAiC,CAACC,IAAD,EAAOC,WAAP,EAAoBW,YAApB,CAD5B,CAAP;AAGD,CAVH;;AAYA,MAAME,gBAAgB,GAAIb,WAAD,IACtB,6CAA4Cc,MAAM,CAACd,WAAD,CAAc,GADnE;;AAEA,MAAMe,eAAe,GAAIf,WAAD,IACrB,+CAA8Cc,MAAM,CAACd,WAAD,CAAc,EADrE;;AAGA,MAAM;AAAEgB,EAAAA,KAAF;AAASC,EAAAA,QAAT;AAAmBC,EAAAA,OAAnB;AAA4BC,EAAAA,UAA5B;AAAwCC,EAAAA,MAAxC;AAAgDC,EAAAA;AAAhD,IAA8D,8BAClEb,yBADkE,EAElEO,eAFkE,EAGlEF,gBAHkE,CAApE;;AAeO,MAAMS,4BAA4B,GACvCb,QAD0C,KAEZ;AAC9Bc,EAAAA,oBAAoB,EAAEP,KAAK,CAACP,QAAD,CADG;AAE9Be,EAAAA,uBAAuB,EAAEP,QAAQ,CAACR,QAAD,CAFH;AAG9BgB,EAAAA,sBAAsB,EAAEP,OAAO,CAACT,QAAD,CAHD;AAI9BD,EAAAA,yBAAyB,EAAEW,UAAU,CAACV,QAAD,CAJP;AAK9BiB,EAAAA,qBAAqB,EAAEN,MAAM,CAACX,QAAD,CALC;AAM9BkB,EAAAA,wBAAwB,EAAEN,SAAS,CAACZ,QAAD;AANL,CAFY,CAArC","sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { createLibraryNotSupportedError } from '../helpers/errors';\nimport { filterNodeByType } from '../helpers/filterNodeByType';\nimport { matches, TextMatch } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport type { TextMatchOptions } from './text';\n\nconst getTextInputNodeByPlaceholderText = (\n node: ReactTestInstance,\n placeholder: TextMatch,\n options: TextMatchOptions = {}\n) => {\n try {\n const { TextInput } = require('react-native');\n const { exact, normalizer } = options;\n return (\n filterNodeByType(node, TextInput) &&\n matches(placeholder, node.props.placeholder, normalizer, exact)\n );\n } catch (error) {\n throw createLibraryNotSupportedError(error);\n }\n};\n\nconst queryAllByPlaceholderText = (\n instance: ReactTestInstance\n): ((\n placeholder: TextMatch,\n queryOptions?: TextMatchOptions\n) => Array<ReactTestInstance>) =>\n function queryAllByPlaceholderFn(placeholder, queryOptions) {\n return instance.findAll((node) =>\n getTextInputNodeByPlaceholderText(node, placeholder, 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, TextMatchOptions>;\n getAllByPlaceholderText: GetAllByQuery<TextMatch, TextMatchOptions>;\n queryByPlaceholderText: QueryByQuery<TextMatch, TextMatchOptions>;\n queryAllByPlaceholderText: QueryAllByQuery<TextMatch, TextMatchOptions>;\n findByPlaceholderText: FindByQuery<TextMatch, TextMatchOptions>;\n findAllByPlaceholderText: FindAllByQuery<TextMatch, TextMatchOptions>;\n};\n\nexport const bindByPlaceholderTextQueries = (\n instance: ReactTestInstance\n): ByPlaceholderTextQueries => ({\n getByPlaceholderText: getBy(instance),\n getAllByPlaceholderText: getAllBy(instance),\n queryByPlaceholderText: queryBy(instance),\n queryAllByPlaceholderText: queryAllBy(instance),\n findByPlaceholderText: findBy(instance),\n findAllByPlaceholderText: findAllBy(instance),\n});\n"],"file":"placeholderText.js"}
@@ -0,0 +1,13 @@
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
+ import type { TextMatchOptions } from './text';
5
+ export declare type ByTestIdQueries = {
6
+ getByTestId: GetByQuery<TextMatch, TextMatchOptions>;
7
+ getAllByTestId: GetAllByQuery<TextMatch, TextMatchOptions>;
8
+ queryByTestId: QueryByQuery<TextMatch, TextMatchOptions>;
9
+ queryAllByTestId: QueryAllByQuery<TextMatch, TextMatchOptions>;
10
+ findByTestId: FindByQuery<TextMatch, TextMatchOptions>;
11
+ findAllByTestId: FindAllByQuery<TextMatch, TextMatchOptions>;
12
+ };
13
+ export declare const bindByTestIdQueries: (instance: ReactTestInstance) => ByTestIdQueries;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.queryByTestId = exports.queryAllByTestId = exports.getByTestId = exports.getAllByTestId = exports.findByTestId = exports.findAllByTestId = void 0;
6
+ exports.bindByTestIdQueries = void 0;
7
7
 
8
8
  var _matches = require("../matches");
9
9
 
@@ -22,22 +22,27 @@ const queryAllByTestId = instance => function queryAllByTestIdFn(testId, queryOp
22
22
  return results;
23
23
  };
24
24
 
25
- exports.queryAllByTestId = queryAllByTestId;
26
-
27
25
  const getMultipleError = testId => `Found multiple elements with testID: ${String(testId)}`;
28
26
 
29
27
  const getMissingError = testId => `Unable to find an element with testID: ${String(testId)}`;
30
28
 
31
29
  const {
32
- getBy: getByTestId,
33
- getAllBy: getAllByTestId,
34
- queryBy: queryByTestId,
35
- findBy: findByTestId,
36
- findAllBy: findAllByTestId
30
+ getBy,
31
+ getAllBy,
32
+ queryBy,
33
+ queryAllBy,
34
+ findBy,
35
+ findAllBy
37
36
  } = (0, _makeQueries.makeQueries)(queryAllByTestId, getMissingError, getMultipleError);
38
- exports.findAllByTestId = findAllByTestId;
39
- exports.findByTestId = findByTestId;
40
- exports.queryByTestId = queryByTestId;
41
- exports.getAllByTestId = getAllByTestId;
42
- exports.getByTestId = getByTestId;
43
- //# sourceMappingURL=byTestId.js.map
37
+
38
+ const bindByTestIdQueries = instance => ({
39
+ getByTestId: getBy(instance),
40
+ getAllByTestId: getAllBy(instance),
41
+ queryByTestId: queryBy(instance),
42
+ queryAllByTestId: queryAllBy(instance),
43
+ findByTestId: findBy(instance),
44
+ findAllByTestId: findAllBy(instance)
45
+ });
46
+
47
+ exports.bindByTestIdQueries = bindByTestIdQueries;
48
+ //# sourceMappingURL=testId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/queries/testId.ts"],"names":["getNodeByTestId","node","testID","options","exact","normalizer","props","queryAllByTestId","instance","queryAllByTestIdFn","testId","queryOptions","results","findAll","filter","element","type","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","bindByTestIdQueries","getByTestId","getAllByTestId","queryByTestId","findByTestId","findAllByTestId"],"mappings":";;;;;;;AACA;;AACA;;AAWA,MAAMA,eAAe,GAAG,CACtBC,IADsB,EAEtBC,MAFsB,EAGtBC,OAAyB,GAAG,EAHN,KAInB;AACH,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAAwBF,OAA9B;AACA,SAAO,sBAAQD,MAAR,EAAgBD,IAAI,CAACK,KAAL,CAAWJ,MAA3B,EAAmCG,UAAnC,EAA+CD,KAA/C,CAAP;AACD,CAPD;;AASA,MAAMG,gBAAgB,GACpBC,QADuB,IAMvB,SAASC,kBAAT,CAA4BC,MAA5B,EAAoCC,YAApC,EAAkD;AAChD,QAAMC,OAAO,GAAGJ,QAAQ,CACrBK,OADa,CACJZ,IAAD,IAAUD,eAAe,CAACC,IAAD,EAAOS,MAAP,EAAeC,YAAf,CADpB,EAEbG,MAFa,CAELC,OAAD,IAAa,OAAOA,OAAO,CAACC,IAAf,KAAwB,QAF/B,CAAhB;AAIA,SAAOJ,OAAP;AACD,CAZH;;AAcA,MAAMK,gBAAgB,GAAIP,MAAD,IACtB,wCAAuCQ,MAAM,CAACR,MAAD,CAAS,EADzD;;AAEA,MAAMS,eAAe,GAAIT,MAAD,IACrB,0CAAyCQ,MAAM,CAACR,MAAD,CAAS,EAD3D;;AAGA,MAAM;AAAEU,EAAAA,KAAF;AAASC,EAAAA,QAAT;AAAmBC,EAAAA,OAAnB;AAA4BC,EAAAA,UAA5B;AAAwCC,EAAAA,MAAxC;AAAgDC,EAAAA;AAAhD,IAA8D,8BAClElB,gBADkE,EAElEY,eAFkE,EAGlEF,gBAHkE,CAApE;;AAeO,MAAMS,mBAAmB,GAC9BlB,QADiC,KAEZ;AACrBmB,EAAAA,WAAW,EAAEP,KAAK,CAACZ,QAAD,CADG;AAErBoB,EAAAA,cAAc,EAAEP,QAAQ,CAACb,QAAD,CAFH;AAGrBqB,EAAAA,aAAa,EAAEP,OAAO,CAACd,QAAD,CAHD;AAIrBD,EAAAA,gBAAgB,EAAEgB,UAAU,CAACf,QAAD,CAJP;AAKrBsB,EAAAA,YAAY,EAAEN,MAAM,CAAChB,QAAD,CALC;AAMrBuB,EAAAA,eAAe,EAAEN,SAAS,CAACjB,QAAD;AANL,CAFY,CAA5B","sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matches, TextMatch } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport type { TextMatchOptions } from './text';\n\nconst getNodeByTestId = (\n node: ReactTestInstance,\n testID: TextMatch,\n options: TextMatchOptions = {}\n) => {\n const { exact, normalizer } = options;\n return matches(testID, node.props.testID, normalizer, exact);\n};\n\nconst queryAllByTestId = (\n instance: ReactTestInstance\n): ((\n testId: TextMatch,\n queryOptions?: TextMatchOptions\n) => Array<ReactTestInstance>) =>\n function queryAllByTestIdFn(testId, queryOptions) {\n const results = instance\n .findAll((node) => getNodeByTestId(node, testId, queryOptions))\n .filter((element) => typeof element.type === 'string');\n\n return results;\n };\n\nconst getMultipleError = (testId: TextMatch) =>\n `Found multiple elements with testID: ${String(testId)}`;\nconst getMissingError = (testId: TextMatch) =>\n `Unable to find an element with testID: ${String(testId)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByTestId,\n getMissingError,\n getMultipleError\n);\n\nexport type ByTestIdQueries = {\n getByTestId: GetByQuery<TextMatch, TextMatchOptions>;\n getAllByTestId: GetAllByQuery<TextMatch, TextMatchOptions>;\n queryByTestId: QueryByQuery<TextMatch, TextMatchOptions>;\n queryAllByTestId: QueryAllByQuery<TextMatch, TextMatchOptions>;\n findByTestId: FindByQuery<TextMatch, TextMatchOptions>;\n findAllByTestId: FindAllByQuery<TextMatch, TextMatchOptions>;\n};\n\nexport const bindByTestIdQueries = (\n instance: ReactTestInstance\n): ByTestIdQueries => ({\n getByTestId: getBy(instance),\n getAllByTestId: getAllBy(instance),\n queryByTestId: queryBy(instance),\n queryAllByTestId: queryAllBy(instance),\n findByTestId: findBy(instance),\n findAllByTestId: findAllBy(instance),\n});\n"],"file":"testId.js"}
@@ -0,0 +1,17 @@
1
+ import type { ReactTestInstance } from 'react-test-renderer';
2
+ import { TextMatch } from '../matches';
3
+ import type { NormalizerFn } from '../matches';
4
+ import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './makeQueries';
5
+ export declare type TextMatchOptions = {
6
+ exact?: boolean;
7
+ normalizer?: NormalizerFn;
8
+ };
9
+ export declare type ByTextQueries = {
10
+ getByText: GetByQuery<TextMatch, TextMatchOptions>;
11
+ getAllByText: GetAllByQuery<TextMatch, TextMatchOptions>;
12
+ queryByText: QueryByQuery<TextMatch, TextMatchOptions>;
13
+ queryAllByText: QueryAllByQuery<TextMatch, TextMatchOptions>;
14
+ findByText: FindByQuery<TextMatch, TextMatchOptions>;
15
+ findAllByText: FindAllByQuery<TextMatch, TextMatchOptions>;
16
+ };
17
+ export declare const bindByTextQueries: (instance: ReactTestInstance) => ByTextQueries;
@@ -3,17 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.queryByText = exports.queryAllByText = exports.getByText = exports.getAllByText = exports.findByText = exports.findAllByText = void 0;
6
+ exports.bindByTextQueries = void 0;
7
7
 
8
8
  var React = _interopRequireWildcard(require("react"));
9
9
 
10
- var _matches = require("../matches");
10
+ var _errors = require("../helpers/errors");
11
11
 
12
- var _makeQueries = require("./makeQueries");
12
+ var _filterNodeByType = require("../helpers/filterNodeByType");
13
13
 
14
- var _filterNodeByType = require("./filterNodeByType");
14
+ var _matches = require("../matches");
15
15
 
16
- var _errors = require("./errors");
16
+ var _makeQueries = require("./makeQueries");
17
17
 
18
18
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
19
 
@@ -78,27 +78,32 @@ const getNodeByText = (node, text, options = {}) => {
78
78
  }
79
79
  };
80
80
 
81
- const queryAllByText = instance => function queryAllByTextFn(text, queryOptions) {
82
- const results = instance.findAll(node => getNodeByText(node, text, queryOptions));
81
+ const queryAllByText = instance => function queryAllByTextFn(text, options) {
82
+ const results = instance.findAll(node => getNodeByText(node, text, options));
83
83
  return results;
84
84
  };
85
85
 
86
- exports.queryAllByText = queryAllByText;
87
-
88
86
  const getMultipleError = text => `Found multiple elements with text: ${String(text)}`;
89
87
 
90
88
  const getMissingError = text => `Unable to find an element with text: ${String(text)}`;
91
89
 
92
90
  const {
93
- getBy: getByText,
94
- getAllBy: getAllByText,
95
- queryBy: queryByText,
96
- findBy: findByText,
97
- findAllBy: findAllByText
91
+ getBy,
92
+ getAllBy,
93
+ queryBy,
94
+ queryAllBy,
95
+ findBy,
96
+ findAllBy
98
97
  } = (0, _makeQueries.makeQueries)(queryAllByText, getMissingError, getMultipleError);
99
- exports.findAllByText = findAllByText;
100
- exports.findByText = findByText;
101
- exports.queryByText = queryByText;
102
- exports.getAllByText = getAllByText;
103
- exports.getByText = getByText;
104
- //# sourceMappingURL=byText.js.map
98
+
99
+ const bindByTextQueries = instance => ({
100
+ getByText: getBy(instance),
101
+ getAllByText: getAllBy(instance),
102
+ queryByText: queryBy(instance),
103
+ queryAllByText: queryAllBy(instance),
104
+ findByText: findBy(instance),
105
+ findAllByText: findAllBy(instance)
106
+ });
107
+
108
+ exports.bindByTextQueries = bindByTextQueries;
109
+ //# sourceMappingURL=text.js.map
@@ -0,0 +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;AAAA;;AAC1C,QAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;AAC7BJ,MAAAA,WAAW,CAACK,IAAZ,CAAiBD,KAAjB;AACA;AACD;;AAED,QAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;AAC7BJ,MAAAA,WAAW,CAACK,IAAZ,CAAiBD,KAAK,CAACE,QAAN,EAAjB;AACA;AACD;;AAED,QAAIF,KAAJ,aAAIA,KAAJ,+BAAIA,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hB,IAAD,IAC/BD,aAAa,CAACC,IAAD,EAAOC,IAAP,EAAaC,OAAb,CADC,CAAhB;AAIA,SAAOa,OAAP;AACD,CAZH;;AAcA,MAAME,gBAAgB,GAAIhB,IAAD,IACtB,sCAAqCiB,MAAM,CAACjB,IAAD,CAAO,EADrD;;AAEA,MAAMkB,eAAe,GAAIlB,IAAD,IACrB,wCAAuCiB,MAAM,CAACjB,IAAD,CAAO,EADvD;;AAGA,MAAM;AAAEmB,EAAAA,KAAF;AAASC,EAAAA,QAAT;AAAmBC,EAAAA,OAAnB;AAA4BC,EAAAA,UAA5B;AAAwCC,EAAAA,MAAxC;AAAgDC,EAAAA;AAAhD,IAA8D,8BAClEb,cADkE,EAElEO,eAFkE,EAGlEF,gBAHkE,CAApE;;AAeO,MAAMS,iBAAiB,GAC5Bb,QAD+B,KAEZ;AACnBc,EAAAA,SAAS,EAAEP,KAAK,CAACP,QAAD,CADG;AAEnBe,EAAAA,YAAY,EAAEP,QAAQ,CAACR,QAAD,CAFH;AAGnBgB,EAAAA,WAAW,EAAEP,OAAO,CAACT,QAAD,CAHD;AAInBD,EAAAA,cAAc,EAAEW,UAAU,CAACV,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"}
@@ -0,0 +1,16 @@
1
+ import type { ReactTestInstance } from 'react-test-renderer';
2
+ export declare type UnsafeByPropsQueries = {
3
+ UNSAFE_getByProps: (props: {
4
+ [key: string]: any;
5
+ }) => ReactTestInstance;
6
+ UNSAFE_getAllByProps: (props: {
7
+ [key: string]: any;
8
+ }) => Array<ReactTestInstance>;
9
+ UNSAFE_queryByProps: (props: {
10
+ [key: string]: any;
11
+ }) => ReactTestInstance | null;
12
+ UNSAFE_queryAllByProps: (props: {
13
+ [key: string]: any;
14
+ }) => Array<ReactTestInstance>;
15
+ };
16
+ export declare const bindUnsafeByPropsQueries: (instance: ReactTestInstance) => UnsafeByPropsQueries;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.bindUnsafeByPropsQueries = void 0;
7
+
8
+ var _prettyFormat = _interopRequireDefault(require("pretty-format"));
9
+
10
+ var _errors = require("../helpers/errors");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const UNSAFE_getByProps = instance => function getByPropsFn(props) {
15
+ try {
16
+ return instance.findByProps(props);
17
+ } catch (error) {
18
+ throw new _errors.ErrorWithStack((0, _errors.prepareErrorMessage)(error), getByPropsFn);
19
+ }
20
+ };
21
+
22
+ const UNSAFE_getAllByProps = instance => function getAllByPropsFn(props) {
23
+ const results = instance.findAllByProps(props);
24
+
25
+ if (results.length === 0) {
26
+ throw new _errors.ErrorWithStack(`No instances found with props:\n${(0, _prettyFormat.default)(props)}`, getAllByPropsFn);
27
+ }
28
+
29
+ return results;
30
+ };
31
+
32
+ const UNSAFE_queryByProps = instance => function queryByPropsFn(props) {
33
+ try {
34
+ return UNSAFE_getByProps(instance)(props);
35
+ } catch (error) {
36
+ return (0, _errors.createQueryByError)(error, queryByPropsFn);
37
+ }
38
+ };
39
+
40
+ const UNSAFE_queryAllByProps = instance => props => {
41
+ try {
42
+ return UNSAFE_getAllByProps(instance)(props);
43
+ } catch (error) {
44
+ return [];
45
+ }
46
+ }; // Unsafe aliases
47
+
48
+
49
+ // TODO: migrate to makeQueries pattern
50
+ const bindUnsafeByPropsQueries = instance => ({
51
+ UNSAFE_getByProps: UNSAFE_getByProps(instance),
52
+ UNSAFE_getAllByProps: UNSAFE_getAllByProps(instance),
53
+ UNSAFE_queryByProps: UNSAFE_queryByProps(instance),
54
+ UNSAFE_queryAllByProps: UNSAFE_queryAllByProps(instance)
55
+ });
56
+
57
+ exports.bindUnsafeByPropsQueries = bindUnsafeByPropsQueries;
58
+ //# sourceMappingURL=unsafeProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/queries/unsafeProps.ts"],"names":["UNSAFE_getByProps","instance","getByPropsFn","props","findByProps","error","ErrorWithStack","UNSAFE_getAllByProps","getAllByPropsFn","results","findAllByProps","length","UNSAFE_queryByProps","queryByPropsFn","UNSAFE_queryAllByProps","bindUnsafeByPropsQueries"],"mappings":";;;;;;;AACA;;AACA;;;;AAGA,MAAMA,iBAAiB,GACrBC,QADwB,IAGxB,SAASC,YAAT,CAAsBC,KAAtB,EAA0D;AACxD,MAAI;AACF,WAAOF,QAAQ,CAACG,WAAT,CAAqBD,KAArB,CAAP;AACD,GAFD,CAEE,OAAOE,KAAP,EAAc;AACd,UAAM,IAAIC,sBAAJ,CAAmB,iCAAoBD,KAApB,CAAnB,EAA+CH,YAA/C,CAAN;AACD;AACF,CATH;;AAWA,MAAMK,oBAAoB,GACxBN,QAD2B,IAG3B,SAASO,eAAT,CAAyBL,KAAzB,EAA6D;AAC3D,QAAMM,OAAO,GAAGR,QAAQ,CAACS,cAAT,CAAwBP,KAAxB,CAAhB;;AACA,MAAIM,OAAO,CAACE,MAAR,KAAmB,CAAvB,EAA0B;AACxB,UAAM,IAAIL,sBAAJ,CACH,mCAAkC,2BAAaH,KAAb,CAAoB,EADnD,EAEJK,eAFI,CAAN;AAID;;AACD,SAAOC,OAAP;AACD,CAZH;;AAcA,MAAMG,mBAAmB,GACvBX,QAD0B,IAG1B,SAASY,cAAT,CAAwBV,KAAxB,EAA4D;AAC1D,MAAI;AACF,WAAOH,iBAAiB,CAACC,QAAD,CAAjB,CAA4BE,KAA5B,CAAP;AACD,GAFD,CAEE,OAAOE,KAAP,EAAc;AACd,WAAO,gCAAmBA,KAAnB,EAA0BQ,cAA1B,CAAP;AACD;AACF,CATH;;AAWA,MAAMC,sBAAsB,GAC1Bb,QAD6B,IAIKE,KAAD,IAAwC;AACzE,MAAI;AACF,WAAOI,oBAAoB,CAACN,QAAD,CAApB,CAA+BE,KAA/B,CAAP;AACD,GAFD,CAEE,OAAOE,KAAP,EAAc;AACd,WAAO,EAAP;AACD;AACF,CAVD,C,CAYA;;;AAcA;AACO,MAAMU,wBAAwB,GACnCd,QADsC,KAEZ;AAC1BD,EAAAA,iBAAiB,EAAEA,iBAAiB,CAACC,QAAD,CADV;AAE1BM,EAAAA,oBAAoB,EAAEA,oBAAoB,CAACN,QAAD,CAFhB;AAG1BW,EAAAA,mBAAmB,EAAEA,mBAAmB,CAACX,QAAD,CAHd;AAI1Ba,EAAAA,sBAAsB,EAAEA,sBAAsB,CAACb,QAAD;AAJpB,CAFY,CAAjC","sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport prettyFormat from 'pretty-format';\nimport { ErrorWithStack, prepareErrorMessage } from '../helpers/errors';\nimport { createQueryByError } from '../helpers/errors';\n\nconst UNSAFE_getByProps = (\n instance: ReactTestInstance\n): ((props: { [propName: string]: any }) => ReactTestInstance) =>\n function getByPropsFn(props: { [propName: string]: any }) {\n try {\n return instance.findByProps(props);\n } catch (error) {\n throw new ErrorWithStack(prepareErrorMessage(error), getByPropsFn);\n }\n };\n\nconst UNSAFE_getAllByProps = (\n instance: ReactTestInstance\n): ((props: { [propName: string]: any }) => Array<ReactTestInstance>) =>\n function getAllByPropsFn(props: { [propName: string]: any }) {\n const results = instance.findAllByProps(props);\n if (results.length === 0) {\n throw new ErrorWithStack(\n `No instances found with props:\\n${prettyFormat(props)}`,\n getAllByPropsFn\n );\n }\n return results;\n };\n\nconst UNSAFE_queryByProps = (\n instance: ReactTestInstance\n): ((props: { [propName: string]: any }) => ReactTestInstance | null) =>\n function queryByPropsFn(props: { [propName: string]: any }) {\n try {\n return UNSAFE_getByProps(instance)(props);\n } catch (error) {\n return createQueryByError(error, queryByPropsFn);\n }\n };\n\nconst UNSAFE_queryAllByProps = (\n instance: ReactTestInstance\n): ((props: {\n [propName: string]: any;\n}) => Array<ReactTestInstance>) => (props: { [propName: string]: any }) => {\n try {\n return UNSAFE_getAllByProps(instance)(props);\n } catch (error) {\n return [];\n }\n};\n\n// Unsafe aliases\nexport type UnsafeByPropsQueries = {\n UNSAFE_getByProps: (props: { [key: string]: any }) => ReactTestInstance;\n UNSAFE_getAllByProps: (props: {\n [key: string]: any;\n }) => Array<ReactTestInstance>;\n UNSAFE_queryByProps: (props: {\n [key: string]: any;\n }) => ReactTestInstance | null;\n UNSAFE_queryAllByProps: (props: {\n [key: string]: any;\n }) => Array<ReactTestInstance>;\n};\n\n// TODO: migrate to makeQueries pattern\nexport const bindUnsafeByPropsQueries = (\n instance: ReactTestInstance\n): UnsafeByPropsQueries => ({\n UNSAFE_getByProps: UNSAFE_getByProps(instance),\n UNSAFE_getAllByProps: UNSAFE_getAllByProps(instance),\n UNSAFE_queryByProps: UNSAFE_queryByProps(instance),\n UNSAFE_queryAllByProps: UNSAFE_queryAllByProps(instance),\n});\n"],"file":"unsafeProps.js"}
@@ -0,0 +1,9 @@
1
+ import type { ReactTestInstance } from 'react-test-renderer';
2
+ import * as React from 'react';
3
+ export declare type UnsafeByTypeQueries = {
4
+ UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;
5
+ UNSAFE_getAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance>;
6
+ UNSAFE_queryByType: <P>(type: React.ComponentType<P>) => ReactTestInstance | null;
7
+ UNSAFE_queryAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance>;
8
+ };
9
+ export declare const bindUnsafeByTypeQueries: (instance: ReactTestInstance) => UnsafeByTypeQueries;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.bindUnsafeByTypeQueries = void 0;
7
+
8
+ var _errors = require("../helpers/errors");
9
+
10
+ const UNSAFE_getByType = instance => function getByTypeFn(type) {
11
+ try {
12
+ return instance.findByType(type);
13
+ } catch (error) {
14
+ throw new _errors.ErrorWithStack((0, _errors.prepareErrorMessage)(error), getByTypeFn);
15
+ }
16
+ };
17
+
18
+ const UNSAFE_getAllByType = instance => function getAllByTypeFn(type) {
19
+ const results = instance.findAllByType(type);
20
+
21
+ if (results.length === 0) {
22
+ throw new _errors.ErrorWithStack('No instances found', getAllByTypeFn);
23
+ }
24
+
25
+ return results;
26
+ };
27
+
28
+ const UNSAFE_queryByType = instance => function queryByTypeFn(type) {
29
+ try {
30
+ return UNSAFE_getByType(instance)(type);
31
+ } catch (error) {
32
+ return (0, _errors.createQueryByError)(error, queryByTypeFn);
33
+ }
34
+ };
35
+
36
+ const UNSAFE_queryAllByType = instance => type => {
37
+ try {
38
+ return UNSAFE_getAllByType(instance)(type);
39
+ } catch (error) {
40
+ return [];
41
+ }
42
+ }; // Unsafe aliases
43
+
44
+
45
+ // TODO: migrate to makeQueries pattern
46
+ const bindUnsafeByTypeQueries = instance => ({
47
+ UNSAFE_getByType: UNSAFE_getByType(instance),
48
+ UNSAFE_getAllByType: UNSAFE_getAllByType(instance),
49
+ UNSAFE_queryByType: UNSAFE_queryByType(instance),
50
+ UNSAFE_queryAllByType: UNSAFE_queryAllByType(instance)
51
+ });
52
+
53
+ exports.bindUnsafeByTypeQueries = bindUnsafeByTypeQueries;
54
+ //# sourceMappingURL=unsafeType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/queries/unsafeType.ts"],"names":["UNSAFE_getByType","instance","getByTypeFn","type","findByType","error","ErrorWithStack","UNSAFE_getAllByType","getAllByTypeFn","results","findAllByType","length","UNSAFE_queryByType","queryByTypeFn","UNSAFE_queryAllByType","bindUnsafeByTypeQueries"],"mappings":";;;;;;;AAEA;;AAGA,MAAMA,gBAAgB,GACpBC,QADuB,IAGvB,SAASC,WAAT,CAAqBC,IAArB,EAAqD;AACnD,MAAI;AACF,WAAOF,QAAQ,CAACG,UAAT,CAAoBD,IAApB,CAAP;AACD,GAFD,CAEE,OAAOE,KAAP,EAAc;AACd,UAAM,IAAIC,sBAAJ,CAAmB,iCAAoBD,KAApB,CAAnB,EAA+CH,WAA/C,CAAN;AACD;AACF,CATH;;AAWA,MAAMK,mBAAmB,GACvBN,QAD0B,IAG1B,SAASO,cAAT,CAAwBL,IAAxB,EAAwD;AACtD,QAAMM,OAAO,GAAGR,QAAQ,CAACS,aAAT,CAAuBP,IAAvB,CAAhB;;AACA,MAAIM,OAAO,CAACE,MAAR,KAAmB,CAAvB,EAA0B;AACxB,UAAM,IAAIL,sBAAJ,CAAmB,oBAAnB,EAAyCE,cAAzC,CAAN;AACD;;AACD,SAAOC,OAAP;AACD,CATH;;AAWA,MAAMG,kBAAkB,GACtBX,QADyB,IAGzB,SAASY,aAAT,CAAuBV,IAAvB,EAAuD;AACrD,MAAI;AACF,WAAOH,gBAAgB,CAACC,QAAD,CAAhB,CAA2BE,IAA3B,CAAP;AACD,GAFD,CAEE,OAAOE,KAAP,EAAc;AACd,WAAO,gCAAmBA,KAAnB,EAA0BQ,aAA1B,CAAP;AACD;AACF,CATH;;AAWA,MAAMC,qBAAqB,GACzBb,QAD4B,IAG5BE,IADmE,IAEhE;AACH,MAAI;AACF,WAAOI,mBAAmB,CAACN,QAAD,CAAnB,CAA8BE,IAA9B,CAAP;AACD,GAFD,CAEE,OAAOE,KAAP,EAAc;AACd,WAAO,EAAP;AACD;AACF,CAVD,C,CAYA;;;AAcA;AACO,MAAMU,uBAAuB,GAClCd,QADqC,KAEZ;AACzBD,EAAAA,gBAAgB,EAAEA,gBAAgB,CAACC,QAAD,CADT;AAEzBM,EAAAA,mBAAmB,EAAEA,mBAAmB,CAACN,QAAD,CAFf;AAGzBW,EAAAA,kBAAkB,EAAEA,kBAAkB,CAACX,QAAD,CAHb;AAIzBa,EAAAA,qBAAqB,EAAEA,qBAAqB,CAACb,QAAD;AAJnB,CAFY,CAAhC","sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport * as React from 'react';\nimport { ErrorWithStack, prepareErrorMessage } from '../helpers/errors';\nimport { createQueryByError } from '../helpers/errors';\n\nconst UNSAFE_getByType = (\n instance: ReactTestInstance\n): ((type: React.ComponentType<any>) => ReactTestInstance) =>\n function getByTypeFn(type: React.ComponentType<any>) {\n try {\n return instance.findByType(type);\n } catch (error) {\n throw new ErrorWithStack(prepareErrorMessage(error), getByTypeFn);\n }\n };\n\nconst UNSAFE_getAllByType = (\n instance: ReactTestInstance\n): ((type: React.ComponentType<any>) => Array<ReactTestInstance>) =>\n function getAllByTypeFn(type: React.ComponentType<any>) {\n const results = instance.findAllByType(type);\n if (results.length === 0) {\n throw new ErrorWithStack('No instances found', getAllByTypeFn);\n }\n return results;\n };\n\nconst UNSAFE_queryByType = (\n instance: ReactTestInstance\n): ((type: React.ComponentType<any>) => ReactTestInstance | null) =>\n function queryByTypeFn(type: React.ComponentType<any>) {\n try {\n return UNSAFE_getByType(instance)(type);\n } catch (error) {\n return createQueryByError(error, queryByTypeFn);\n }\n };\n\nconst UNSAFE_queryAllByType = (\n instance: ReactTestInstance\n): ((type: React.ComponentType<any>) => Array<ReactTestInstance>) => (\n type: React.ComponentType<any>\n) => {\n try {\n return UNSAFE_getAllByType(instance)(type);\n } catch (error) {\n return [];\n }\n};\n\n// Unsafe aliases\nexport type UnsafeByTypeQueries = {\n UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;\n UNSAFE_getAllByType: <P>(\n type: React.ComponentType<P>\n ) => Array<ReactTestInstance>;\n UNSAFE_queryByType: <P>(\n type: React.ComponentType<P>\n ) => ReactTestInstance | null;\n UNSAFE_queryAllByType: <P>(\n type: React.ComponentType<P>\n ) => Array<ReactTestInstance>;\n};\n\n// TODO: migrate to makeQueries pattern\nexport const bindUnsafeByTypeQueries = (\n instance: ReactTestInstance\n): UnsafeByTypeQueries => ({\n UNSAFE_getByType: UNSAFE_getByType(instance),\n UNSAFE_getAllByType: UNSAFE_getAllByType(instance),\n UNSAFE_queryByType: UNSAFE_queryByType(instance),\n UNSAFE_queryAllByType: UNSAFE_queryAllByType(instance),\n});\n"],"file":"unsafeType.js"}