@testing-library/react-native 9.2.0 → 10.0.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 (55) hide show
  1. package/build/index.flow.js +105 -95
  2. package/build/{helpers → queries}/a11yAPI.d.ts +0 -0
  3. package/build/{helpers → queries}/a11yAPI.js +0 -0
  4. package/build/{helpers → queries}/a11yAPI.js.map +1 -1
  5. package/build/queries/displayValue.d.ts +13 -0
  6. package/build/{helpers/byDisplayValue.js → queries/displayValue.js} +23 -18
  7. package/build/queries/displayValue.js.map +1 -0
  8. package/build/{helpers → queries}/makeA11yQuery.d.ts +0 -0
  9. package/build/{helpers → queries}/makeA11yQuery.js +1 -1
  10. package/build/{helpers → queries}/makeA11yQuery.js.map +1 -1
  11. package/build/queries/makeQueries.d.ts +19 -0
  12. package/build/{helpers → queries}/makeQueries.js +17 -16
  13. package/build/queries/makeQueries.js.map +1 -0
  14. package/build/queries/placeholderText.d.ts +13 -0
  15. package/build/{helpers/byPlaceholderText.js → queries/placeholderText.js} +23 -18
  16. package/build/queries/placeholderText.js.map +1 -0
  17. package/build/queries/testId.d.ts +13 -0
  18. package/build/{helpers/byTestId.js → queries/testId.js} +19 -14
  19. package/build/queries/testId.js.map +1 -0
  20. package/build/queries/text.d.ts +17 -0
  21. package/build/{helpers/byText.js → queries/text.js} +25 -20
  22. package/build/queries/text.js.map +1 -0
  23. package/build/queries/unsafeProps.d.ts +16 -0
  24. package/build/queries/unsafeProps.js +58 -0
  25. package/build/queries/unsafeProps.js.map +1 -0
  26. package/build/queries/unsafeType.d.ts +9 -0
  27. package/build/queries/unsafeType.js +54 -0
  28. package/build/queries/unsafeType.js.map +1 -0
  29. package/build/render.d.ts +34 -44
  30. package/build/render.js +3 -12
  31. package/build/render.js.map +1 -1
  32. package/build/within.d.ts +34 -44
  33. package/build/within.js +16 -7
  34. package/build/within.js.map +1 -1
  35. package/package.json +1 -1
  36. package/typings/index.flow.js +105 -95
  37. package/build/helpers/byDisplayValue.d.ts +0 -6
  38. package/build/helpers/byDisplayValue.js.map +0 -1
  39. package/build/helpers/byPlaceholderText.d.ts +0 -6
  40. package/build/helpers/byPlaceholderText.js.map +0 -1
  41. package/build/helpers/byTestId.d.ts +0 -6
  42. package/build/helpers/byTestId.js.map +0 -1
  43. package/build/helpers/byText.d.ts +0 -10
  44. package/build/helpers/byText.js.map +0 -1
  45. package/build/helpers/findByAPI.d.ts +0 -17
  46. package/build/helpers/findByAPI.js +0 -33
  47. package/build/helpers/findByAPI.js.map +0 -1
  48. package/build/helpers/getByAPI.d.ts +0 -31
  49. package/build/helpers/getByAPI.js +0 -83
  50. package/build/helpers/getByAPI.js.map +0 -1
  51. package/build/helpers/makeQueries.d.ts +0 -20
  52. package/build/helpers/makeQueries.js.map +0 -1
  53. package/build/helpers/queryByAPI.d.ts +0 -39
  54. package/build/helpers/queryByAPI.js +0 -87
  55. package/build/helpers/queryByAPI.js.map +0 -1
@@ -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","findAllBy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P,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,E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AAAA,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","getA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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"}
package/build/render.d.ts CHANGED
@@ -87,56 +87,46 @@ export default function render<T>(component: React.ReactElement<T>, { wrapper: W
87
87
  now?: number | undefined;
88
88
  text?: string | undefined;
89
89
  }, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance[]>;
90
- findAllByDisplayValue: (value: import("./matches").TextMatch, queryOptions?: (import("./helpers/byText").TextMatchOptions & import("./waitFor").WaitForOptions) | undefined, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance[]>;
91
- findAllByPlaceholder: () => void;
92
- findAllByPlaceholderText: (placeholder: import("./matches").TextMatch, queryOptions?: (import("./helpers/byText").TextMatchOptions & import("./waitFor").WaitForOptions) | undefined, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance[]>;
93
- findAllByTestId: (testId: import("./matches").TextMatch, queryOptions?: (import("./helpers/byText").TextMatchOptions & import("./waitFor").WaitForOptions) | undefined, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance[]>;
94
- findAllByText: (text: import("./matches").TextMatch, queryOptions?: (import("./helpers/byText").TextMatchOptions & import("./waitFor").WaitForOptions) | undefined, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance[]>;
95
- findByDisplayValue: (value: import("./matches").TextMatch, queryOptions?: (import("./helpers/byText").TextMatchOptions & import("./waitFor").WaitForOptions) | undefined, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance>;
96
- findByPlaceholder: () => void;
97
- findByPlaceholderText: (placeholder: import("./matches").TextMatch, queryOptions?: (import("./helpers/byText").TextMatchOptions & import("./waitFor").WaitForOptions) | undefined, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance>;
98
- findByTestId: (testId: import("./matches").TextMatch, queryOptions?: (import("./helpers/byText").TextMatchOptions & import("./waitFor").WaitForOptions) | undefined, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance>;
99
- findByText: (text: import("./matches").TextMatch, queryOptions?: (import("./helpers/byText").TextMatchOptions & import("./waitFor").WaitForOptions) | undefined, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance>;
100
- queryByText: (name: import("./matches").TextMatch, queryOptions?: import("./helpers/byText").TextMatchOptions | undefined) => TestRenderer.ReactTestInstance | null;
101
- queryAllByText: (text: import("./matches").TextMatch, queryOptions?: import("./helpers/byText").TextMatchOptions | undefined) => TestRenderer.ReactTestInstance[];
102
- queryByPlaceholderText: (placeholder: import("./matches").TextMatch, queryOptions?: import("./helpers/byText").TextMatchOptions | undefined) => TestRenderer.ReactTestInstance | null;
103
- queryAllByPlaceholderText: (placeholder: import("./matches").TextMatch, queryOptions?: import("./helpers/byText").TextMatchOptions | undefined) => TestRenderer.ReactTestInstance[];
104
- queryByDisplayValue: (value: import("./matches").TextMatch, queryOptions?: import("./helpers/byText").TextMatchOptions | undefined) => TestRenderer.ReactTestInstance | null;
105
- queryAllByDisplayValue: (value: import("./matches").TextMatch, queryOptions?: import("./helpers/byText").TextMatchOptions | undefined) => TestRenderer.ReactTestInstance[];
106
- queryByTestId: (testID: import("./matches").TextMatch) => TestRenderer.ReactTestInstance | null;
107
- queryAllByTestId: (testID: import("./matches").TextMatch) => TestRenderer.ReactTestInstance[];
108
- UNSAFE_queryByType: <P>(type: React.ComponentType<P>) => TestRenderer.ReactTestInstance | null;
109
- UNSAFE_queryAllByType: <P_1>(type: React.ComponentType<P_1>) => TestRenderer.ReactTestInstance[];
110
- UNSAFE_queryByProps: (props: {
111
- [key: string]: any;
112
- }) => TestRenderer.ReactTestInstance | null;
113
- UNSAFE_queryAllByProps: (props: {
114
- [key: string]: any;
115
- }) => TestRenderer.ReactTestInstance[];
116
- queryByName: () => void;
117
- queryByType: () => void;
118
- queryByProps: () => void;
119
- queryAllByName: () => void;
120
- queryAllByType: () => void;
121
- queryAllByProps: () => void;
122
- queryByPlaceholder: () => void;
123
- queryAllByPlaceholder: () => void;
124
- getByText: (text: import("./matches").TextMatch, queryOptions?: import("./helpers/byText").TextMatchOptions | undefined) => TestRenderer.ReactTestInstance;
125
- getByPlaceholderText: (placeholder: import("./matches").TextMatch, queryOptions?: import("./helpers/byText").TextMatchOptions | undefined) => TestRenderer.ReactTestInstance;
126
- getByDisplayValue: (value: import("./matches").TextMatch, queryOptions?: import("./helpers/byText").TextMatchOptions | undefined) => TestRenderer.ReactTestInstance;
127
- getByTestId: (testID: import("./matches").TextMatch, queryOptions?: import("./helpers/byText").TextMatchOptions | undefined) => TestRenderer.ReactTestInstance;
128
- getAllByTestId: (testID: import("./matches").TextMatch, queryOptions?: import("./helpers/byText").TextMatchOptions | undefined) => TestRenderer.ReactTestInstance[];
129
- getAllByText: (text: import("./matches").TextMatch, queryOptions?: import("./helpers/byText").TextMatchOptions | undefined) => TestRenderer.ReactTestInstance[];
130
- getAllByPlaceholderText: (placeholder: import("./matches").TextMatch, queryOptions?: import("./helpers/byText").TextMatchOptions | undefined) => TestRenderer.ReactTestInstance[];
131
- getAllByDisplayValue: (value: import("./matches").TextMatch, queryOptions?: import("./helpers/byText").TextMatchOptions | undefined) => TestRenderer.ReactTestInstance[];
132
- UNSAFE_getByType: <P_2>(type: React.ComponentType<P_2>) => TestRenderer.ReactTestInstance;
133
- UNSAFE_getAllByType: <P_3>(type: React.ComponentType<P_3>) => TestRenderer.ReactTestInstance[];
134
90
  UNSAFE_getByProps: (props: {
135
91
  [key: string]: any;
136
92
  }) => TestRenderer.ReactTestInstance;
137
93
  UNSAFE_getAllByProps: (props: {
138
94
  [key: string]: any;
139
95
  }) => TestRenderer.ReactTestInstance[];
96
+ UNSAFE_queryByProps: (props: {
97
+ [key: string]: any;
98
+ }) => TestRenderer.ReactTestInstance | null;
99
+ UNSAFE_queryAllByProps: (props: {
100
+ [key: string]: any;
101
+ }) => TestRenderer.ReactTestInstance[];
102
+ UNSAFE_getByType: <P>(type: React.ComponentType<P>) => TestRenderer.ReactTestInstance;
103
+ UNSAFE_getAllByType: <P_1>(type: React.ComponentType<P_1>) => TestRenderer.ReactTestInstance[];
104
+ UNSAFE_queryByType: <P_2>(type: React.ComponentType<P_2>) => TestRenderer.ReactTestInstance | null;
105
+ UNSAFE_queryAllByType: <P_3>(type: React.ComponentType<P_3>) => TestRenderer.ReactTestInstance[];
106
+ getByPlaceholderText: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
107
+ getAllByPlaceholderText: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
108
+ queryByPlaceholderText: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
109
+ queryAllByPlaceholderText: import("./queries/makeQueries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
110
+ findByPlaceholderText: import("./queries/makeQueries").FindByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
111
+ findAllByPlaceholderText: import("./queries/makeQueries").FindAllByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
112
+ getByDisplayValue: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
113
+ getAllByDisplayValue: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
114
+ queryByDisplayValue: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
115
+ queryAllByDisplayValue: import("./queries/makeQueries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
116
+ findByDisplayValue: import("./queries/makeQueries").FindByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
117
+ findAllByDisplayValue: import("./queries/makeQueries").FindAllByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
118
+ getByTestId: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
119
+ getAllByTestId: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
120
+ queryByTestId: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
121
+ queryAllByTestId: import("./queries/makeQueries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
122
+ findByTestId: import("./queries/makeQueries").FindByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
123
+ findAllByTestId: import("./queries/makeQueries").FindAllByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
124
+ getByText: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
125
+ getAllByText: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
126
+ queryByText: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
127
+ queryAllByText: import("./queries/makeQueries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
128
+ findByText: import("./queries/makeQueries").FindByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
129
+ findAllByText: import("./queries/makeQueries").FindAllByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
140
130
  };
141
131
  interface DebugFunction {
142
132
  (message?: string): void;
package/build/render.js CHANGED
@@ -13,18 +13,12 @@ var _act = _interopRequireDefault(require("./act"));
13
13
 
14
14
  var _cleanup = require("./cleanup");
15
15
 
16
- var _getByAPI = require("./helpers/getByAPI");
17
-
18
- var _queryByAPI = require("./helpers/queryByAPI");
19
-
20
- var _findByAPI = require("./helpers/findByAPI");
21
-
22
- var _a11yAPI = require("./helpers/a11yAPI");
23
-
24
16
  var _debugShallow = _interopRequireDefault(require("./helpers/debugShallow"));
25
17
 
26
18
  var _debugDeep = _interopRequireDefault(require("./helpers/debugDeep"));
27
19
 
20
+ var _within = require("./within");
21
+
28
22
  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); }
29
23
 
30
24
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -54,10 +48,7 @@ function render(component, {
54
48
  };
55
49
 
56
50
  (0, _cleanup.addToCleanupQueue)(unmount);
57
- return { ...(0, _getByAPI.getByAPI)(instance),
58
- ...(0, _queryByAPI.queryByAPI)(instance),
59
- ...(0, _findByAPI.findByAPI)(instance),
60
- ...(0, _a11yAPI.a11yAPI)(instance),
51
+ return { ...(0, _within.getQueriesForElement)(instance),
61
52
  update,
62
53
  unmount,
63
54
  container: instance,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/render.tsx"],"names":["render","component","wrapper","Wrapper","createNodeMock","wrap","innerElement","renderer","renderWithAct","undefined","update","updateWithAct","instance","root","unmount","container","rerender","toJSON","debug","options","TestRenderer","create","debugImpl","message","json","shallow"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAUA;AACA;AACA;AACA;AACe,SAASA,MAAT,CACbC,SADa,EAEb;AAAEC,EAAAA,OAAO,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ACRM,MAAAA,QAAQ,CAACG,MAAT,CAAgBL,IAAI,CAACJ,SAAD,CAApB;AACD,KAFD;AAGD,GAJD;AAKD;;AAOD,SAASiB,KAAT,CACEN,QADF,EAEEL,QAFF,EAGiB;AACf,WAASe,SAAT,CAAmBC,OAAnB,EAAqC;AACnC,UAAMC,IAAI,GAAGjB,QAAQ,CAACU,MAAT,EAAb;;AACA,QAAIO,IAAJ,EAAU;AACR,aAAO,wBAAUA,IAAV,EAAgBD,OAAhB,CAAP;AACD;AACF;;AACDD,EAAAA,SAAS,CAACG,OAAV,GAAqBF,OAAD,IAAsB,2BAAaX,QAAb,EAAuBW,OAAvB,CAA1C;;AACA,SAAOD,SAAP;AACD","sourcesContent":["import TestRenderer from 'react-test-renderer';\nimport type { ReactTestInstance, ReactTestRenderer } from 'react-test-renderer';\nimport * as React from 'react';\nimport act from './act';\nimport { addToCleanupQueue } from './cleanup';\nimport { getByAPI } from './helpers/getByAPI';\nimport { queryByAPI } from './helpers/queryByAPI';\nimport { findByAPI } from './helpers/findByAPI';\nimport { a11yAPI } from './helpers/a11yAPI';\nimport debugShallow from './helpers/debugShallow';\nimport debugDeep from './helpers/debugDeep';\n\ntype Options = {\n wrapper?: React.ComponentType<any>;\n createNodeMock?: (element: React.ReactElement) => any;\n};\ntype TestRendererOptions = {\n createNodeMock: (element: React.ReactElement) => any;\n};\n\n/**\n * Renders test component deeply using react-test-renderer and exposes helpers\n * to assert on the output.\n */\nexport default function render<T>(\n component: React.ReactElement<T>,\n { wrapper: Wrapper, createNodeMock }: Options = {}\n) {\n const wrap = (innerElement: React.ReactElement) =>\n Wrapper ? <Wrapper>{innerElement}</Wrapper> : innerElement;\n\n const renderer = renderWithAct(\n wrap(component),\n createNodeMock ? { createNodeMock } : undefined\n );\n const update = updateWithAct(renderer, wrap);\n const instance = renderer.root;\n const unmount = () => {\n act(() => {\n renderer.unmount();\n });\n };\n\n addToCleanupQueue(unmount);\n\n return {\n ...getByAPI(instance),\n ...queryByAPI(instance),\n ...findByAPI(instance),\n ...a11yAPI(instance),\n update,\n unmount,\n container: instance,\n rerender: update, // alias for `update`\n toJSON: renderer.toJSON,\n debug: debug(instance, renderer),\n };\n}\n\nfunction renderWithAct(\n component: React.ReactElement,\n options?: TestRendererOptions\n): ReactTestRenderer {\n let renderer: ReactTestRenderer;\n\n act(() => {\n renderer = TestRenderer.create(component, options);\n });\n\n // @ts-ignore act is sync, so renderer is always initialised here\n return renderer;\n}\n\nfunction updateWithAct(\n renderer: ReactTestRenderer,\n wrap: (innerElement: React.ReactElement) => React.ReactElement\n) {\n return function (component: React.ReactElement) {\n act(() => {\n renderer.update(wrap(component));\n });\n };\n}\n\ninterface DebugFunction {\n (message?: string): void;\n shallow: (message?: string) => void;\n}\n\nfunction debug(\n instance: ReactTestInstance,\n renderer: ReactTestRenderer\n): DebugFunction {\n function debugImpl(message?: string) {\n const json = renderer.toJSON();\n if (json) {\n return debugDeep(json, message);\n }\n }\n debugImpl.shallow = (message?: string) => debugShallow(instance, message);\n return debugImpl;\n}\n"],"file":"render.js"}
1
+ {"version":3,"sources":["../src/render.tsx"],"names":["render","component","wrapper","Wrapper","createNodeMock","wrap","innerElement","renderer","renderWithAct","undefined","update","updateWithAct","instance","root","unmount","container","rerender","toJSON","debug","options","TestRenderer","create","debugImpl","message","json","shallow"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAUA;AACA;AACA;AACA;AACe,SAASA,MAAT,CACbC,SADa,EAEb;AAAEC,EAAAA,OAAO,EAAEC,OAAX;AAAoBC,EAAAA;AAApB,IAAgD,EAFnC,EAGb;AACA,QAAMC,IAAI,GAAIC,YAAD,IACXH,OAAO,gBAAG,oBAAC,OAAD,QAAUG,YAAV,CAAH,GAAuCA,YADhD;;AAGA,QAAMC,QAAQ,GAAGC,aAAa,CAC5BH,IAAI,CAACJ,SAAD,CADwB,EAE5BG,cAAc,GAAG;AAAEA,IAAAA;AAAF,GAAH,GAAwB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AAsB,2BAAaX,QAAb,EAAuBW,OAAvB,CAA1C;;AACA,SAAOD,SAAP;AACD","sourcesContent":["import TestRenderer from 'react-test-renderer';\nimport type { ReactTestInstance, ReactTestRenderer } from 'react-test-renderer';\nimport * as React from 'react';\nimport act from './act';\nimport { addToCleanupQueue } from './cleanup';\nimport debugShallow from './helpers/debugShallow';\nimport debugDeep from './helpers/debugDeep';\nimport { getQueriesForElement } from './within';\n\ntype Options = {\n wrapper?: React.ComponentType<any>;\n createNodeMock?: (element: React.ReactElement) => any;\n};\ntype TestRendererOptions = {\n createNodeMock: (element: React.ReactElement) => any;\n};\n\n/**\n * Renders test component deeply using react-test-renderer and exposes helpers\n * to assert on the output.\n */\nexport default function render<T>(\n component: React.ReactElement<T>,\n { wrapper: Wrapper, createNodeMock }: Options = {}\n) {\n const wrap = (innerElement: React.ReactElement) =>\n Wrapper ? <Wrapper>{innerElement}</Wrapper> : innerElement;\n\n const renderer = renderWithAct(\n wrap(component),\n createNodeMock ? { createNodeMock } : undefined\n );\n const update = updateWithAct(renderer, wrap);\n const instance = renderer.root;\n const unmount = () => {\n act(() => {\n renderer.unmount();\n });\n };\n\n addToCleanupQueue(unmount);\n\n return {\n ...getQueriesForElement(instance),\n update,\n unmount,\n container: instance,\n rerender: update, // alias for `update`\n toJSON: renderer.toJSON,\n debug: debug(instance, renderer),\n };\n}\n\nfunction renderWithAct(\n component: React.ReactElement,\n options?: TestRendererOptions\n): ReactTestRenderer {\n let renderer: ReactTestRenderer;\n\n act(() => {\n renderer = TestRenderer.create(component, options);\n });\n\n // @ts-ignore act is sync, so renderer is always initialised here\n return renderer;\n}\n\nfunction updateWithAct(\n renderer: ReactTestRenderer,\n wrap: (innerElement: React.ReactElement) => React.ReactElement\n) {\n return function (component: React.ReactElement) {\n act(() => {\n renderer.update(wrap(component));\n });\n };\n}\n\ninterface DebugFunction {\n (message?: string): void;\n shallow: (message?: string) => void;\n}\n\nfunction debug(\n instance: ReactTestInstance,\n renderer: ReactTestRenderer\n): DebugFunction {\n function debugImpl(message?: string) {\n const json = renderer.toJSON();\n if (json) {\n return debugDeep(json, message);\n }\n }\n debugImpl.shallow = (message?: string) => debugShallow(instance, message);\n return debugImpl;\n}\n"],"file":"render.js"}