@testing-library/react-native 11.2.0 → 11.4.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 (100) hide show
  1. package/README.md +3 -0
  2. package/build/act.js +9 -15
  3. package/build/act.js.map +1 -1
  4. package/build/cleanup.js +0 -4
  5. package/build/cleanup.js.map +1 -1
  6. package/build/config.d.ts +15 -0
  7. package/build/config.js +27 -0
  8. package/build/config.js.map +1 -0
  9. package/build/fireEvent.js +3 -33
  10. package/build/fireEvent.js.map +1 -1
  11. package/build/flushMicroTasks.js +0 -3
  12. package/build/flushMicroTasks.js.map +1 -1
  13. package/build/helpers/accessiblity.d.ts +3 -0
  14. package/build/helpers/accessiblity.js +14 -20
  15. package/build/helpers/accessiblity.js.map +1 -1
  16. package/build/helpers/component-tree.d.ts +15 -0
  17. package/build/helpers/component-tree.js +49 -15
  18. package/build/helpers/component-tree.js.map +1 -1
  19. package/build/helpers/debugDeep.d.ts +5 -1
  20. package/build/helpers/debugDeep.js +7 -6
  21. package/build/helpers/debugDeep.js.map +1 -1
  22. package/build/helpers/debugShallow.js +0 -5
  23. package/build/helpers/debugShallow.js.map +1 -1
  24. package/build/helpers/errors.js +4 -25
  25. package/build/helpers/errors.js.map +1 -1
  26. package/build/helpers/filterNodeByType.js +0 -2
  27. package/build/helpers/filterNodeByType.js.map +1 -1
  28. package/build/helpers/format.d.ts +5 -1
  29. package/build/helpers/format.js +17 -7
  30. package/build/helpers/format.js.map +1 -1
  31. package/build/helpers/matchers/accessibilityState.d.ts +3 -0
  32. package/build/helpers/matchers/accessibilityState.js +28 -0
  33. package/build/helpers/matchers/accessibilityState.js.map +1 -0
  34. package/build/helpers/matchers/matchArrayProp.js +0 -3
  35. package/build/helpers/matchers/matchArrayProp.js.map +1 -1
  36. package/build/helpers/matchers/matchObjectProp.js +0 -2
  37. package/build/helpers/matchers/matchObjectProp.js.map +1 -1
  38. package/build/helpers/matchers/matchStringProp.js +0 -3
  39. package/build/helpers/matchers/matchStringProp.js.map +1 -1
  40. package/build/helpers/stringValidation.js +0 -7
  41. package/build/helpers/stringValidation.js.map +1 -1
  42. package/build/helpers/timers.js +11 -22
  43. package/build/helpers/timers.js.map +1 -1
  44. package/build/index.flow.js +74 -21
  45. package/build/index.js +0 -6
  46. package/build/index.js.map +1 -1
  47. package/build/matches.js +2 -4
  48. package/build/matches.js.map +1 -1
  49. package/build/pure.d.ts +2 -0
  50. package/build/pure.js +13 -12
  51. package/build/pure.js.map +1 -1
  52. package/build/queries/a11yState.d.ts +1 -1
  53. package/build/queries/a11yState.js +15 -13
  54. package/build/queries/a11yState.js.map +1 -1
  55. package/build/queries/a11yValue.js +0 -8
  56. package/build/queries/a11yValue.js.map +1 -1
  57. package/build/queries/displayValue.js +7 -26
  58. package/build/queries/displayValue.js.map +1 -1
  59. package/build/queries/hintText.d.ts +19 -18
  60. package/build/queries/hintText.js +10 -11
  61. package/build/queries/hintText.js.map +1 -1
  62. package/build/queries/labelText.d.ts +7 -6
  63. package/build/queries/labelText.js +10 -11
  64. package/build/queries/labelText.js.map +1 -1
  65. package/build/queries/makeQueries.d.ts +3 -3
  66. package/build/queries/makeQueries.js +40 -24
  67. package/build/queries/makeQueries.js.map +1 -1
  68. package/build/queries/placeholderText.js +6 -25
  69. package/build/queries/placeholderText.js.map +1 -1
  70. package/build/queries/role.d.ts +3 -2
  71. package/build/queries/role.js +23 -13
  72. package/build/queries/role.js.map +1 -1
  73. package/build/queries/testId.js +0 -9
  74. package/build/queries/testId.js.map +1 -1
  75. package/build/queries/text.js +21 -45
  76. package/build/queries/text.js.map +1 -1
  77. package/build/queries/unsafeProps.js +2 -11
  78. package/build/queries/unsafeProps.js.map +1 -1
  79. package/build/queries/unsafeType.js +2 -9
  80. package/build/queries/unsafeType.js.map +1 -1
  81. package/build/react-versions.js +0 -4
  82. package/build/react-versions.js.map +1 -1
  83. package/build/render.d.ts +32 -31
  84. package/build/render.js +21 -31
  85. package/build/render.js.map +1 -1
  86. package/build/renderHook.js +2 -12
  87. package/build/renderHook.js.map +1 -1
  88. package/build/screen.js +0 -6
  89. package/build/screen.js.map +1 -1
  90. package/build/shallow.js +0 -6
  91. package/build/shallow.js.map +1 -1
  92. package/build/waitFor.js +31 -53
  93. package/build/waitFor.js.map +1 -1
  94. package/build/waitForElementToBeRemoved.js +2 -11
  95. package/build/waitForElementToBeRemoved.js.map +1 -1
  96. package/build/within.d.ts +30 -30
  97. package/build/within.js +2 -14
  98. package/build/within.js.map +1 -1
  99. package/package.json +18 -17
  100. package/typings/index.flow.js +74 -21
@@ -4,13 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.bindByRoleQueries = void 0;
7
-
7
+ var _accessiblity = require("../helpers/accessiblity");
8
+ var _accessibilityState = require("../helpers/matchers/accessibilityState");
8
9
  var _matchStringProp = require("../helpers/matchers/matchStringProp");
9
-
10
10
  var _within = require("../within");
11
-
12
11
  var _makeQueries = require("./makeQueries");
13
-
14
12
  const matchAccessibleNameIfNeeded = (node, name) => {
15
13
  if (name == null) return true;
16
14
  const {
@@ -19,15 +17,29 @@ const matchAccessibleNameIfNeeded = (node, name) => {
19
17
  } = (0, _within.getQueriesForElement)(node);
20
18
  return queryAllByText(name).length > 0 || queryAllByLabelText(name).length > 0;
21
19
  };
22
-
23
- const queryAllByRole = instance => function queryAllByRoleFn(role, options) {
24
- return instance.findAll(node => typeof node.type === 'string' && (0, _matchStringProp.matchStringProp)(node.props.accessibilityRole, role) && matchAccessibleNameIfNeeded(node, options?.name));
20
+ const matchAccessibleStateIfNeeded = (node, options) => {
21
+ return options != null ? (0, _accessibilityState.matchAccessibilityState)(node, options) : true;
25
22
  };
23
+ const queryAllByRole = instance => function queryAllByRoleFn(role, options) {
24
+ return instance.findAll(node =>
25
+ // run the cheapest checks first, and early exit too avoid unneeded computations
26
26
 
27
- const getMultipleError = role => `Found multiple elements with accessibilityRole: ${String(role)} `;
28
-
29
- const getMissingError = role => `Unable to find an element with accessibilityRole: ${String(role)}`;
30
-
27
+ typeof node.type === 'string' && (0, _matchStringProp.matchStringProp)(node.props.accessibilityRole, role) && matchAccessibleStateIfNeeded(node, options) && matchAccessibleNameIfNeeded(node, options?.name));
28
+ };
29
+ const buildErrorMessage = (role, options = {}) => {
30
+ const errors = [`role: "${String(role)}"`];
31
+ if (options.name) {
32
+ errors.push(`name: "${String(options.name)}"`);
33
+ }
34
+ _accessiblity.accessibilityStateKeys.forEach(stateKey => {
35
+ if (options[stateKey] !== undefined) {
36
+ errors.push(`${stateKey} state: ${options[stateKey]}`);
37
+ }
38
+ });
39
+ return errors.join(', ');
40
+ };
41
+ const getMultipleError = (role, options) => `Found multiple elements with ${buildErrorMessage(role, options)}`;
42
+ const getMissingError = (role, options) => `Unable to find an element with ${buildErrorMessage(role, options)}`;
31
43
  const {
32
44
  getBy,
33
45
  getAllBy,
@@ -36,7 +48,6 @@ const {
36
48
  findBy,
37
49
  findAllBy
38
50
  } = (0, _makeQueries.makeQueries)(queryAllByRole, getMissingError, getMultipleError);
39
-
40
51
  const bindByRoleQueries = instance => ({
41
52
  getByRole: getBy(instance),
42
53
  getAllByRole: getAllBy(instance),
@@ -45,6 +56,5 @@ const bindByRoleQueries = instance => ({
45
56
  findByRole: findBy(instance),
46
57
  findAllByRole: findAllBy(instance)
47
58
  });
48
-
49
59
  exports.bindByRoleQueries = bindByRoleQueries;
50
60
  //# sourceMappingURL=role.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"role.js","names":["matchAccessibleNameIfNeeded","node","name","queryAllByText","queryAllByLabelText","getQueriesForElement","length","queryAllByRole","instance","queryAllByRoleFn","role","options","findAll","type","matchStringProp","props","accessibilityRole","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByRoleQueries","getByRole","getAllByRole","queryByRole","findByRole","findAllByRole"],"sources":["../../src/queries/role.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matchStringProp } from '../helpers/matchers/matchStringProp';\nimport { TextMatch } from '../matches';\nimport { getQueriesForElement } from '../within';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\ntype ByRoleOptions = {\n name?: TextMatch;\n};\n\nconst matchAccessibleNameIfNeeded = (\n node: ReactTestInstance,\n name?: TextMatch\n) => {\n if (name == null) return true;\n\n const { queryAllByText, queryAllByLabelText } = getQueriesForElement(node);\n return (\n queryAllByText(name).length > 0 || queryAllByLabelText(name).length > 0\n );\n};\n\nconst queryAllByRole = (\n instance: ReactTestInstance\n): ((role: TextMatch, options?: ByRoleOptions) => Array<ReactTestInstance>) =>\n function queryAllByRoleFn(role, options) {\n return instance.findAll(\n (node) =>\n typeof node.type === 'string' &&\n matchStringProp(node.props.accessibilityRole, role) &&\n matchAccessibleNameIfNeeded(node, options?.name)\n );\n };\n\nconst getMultipleError = (role: TextMatch) =>\n `Found multiple elements with accessibilityRole: ${String(role)} `;\nconst getMissingError = (role: TextMatch) =>\n `Unable to find an element with accessibilityRole: ${String(role)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByRole,\n getMissingError,\n getMultipleError\n);\n\nexport type ByRoleQueries = {\n getByRole: GetByQuery<TextMatch, ByRoleOptions>;\n getAllByRole: GetAllByQuery<TextMatch, ByRoleOptions>;\n queryByRole: QueryByQuery<TextMatch, ByRoleOptions>;\n queryAllByRole: QueryAllByQuery<TextMatch, ByRoleOptions>;\n findByRole: FindByQuery<TextMatch, ByRoleOptions>;\n findAllByRole: FindAllByQuery<TextMatch, ByRoleOptions>;\n};\n\nexport const bindByRoleQueries = (\n instance: ReactTestInstance\n): ByRoleQueries => ({\n getByRole: getBy(instance),\n getAllByRole: getAllBy(instance),\n queryByRole: queryBy(instance),\n queryAllByRole: queryAllBy(instance),\n findByRole: findBy(instance),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WAAW,EAAER,OAAO,CAACd,QAAD,CAHD;EAInBD,cAAc,EAAEgB,UAAU,CAACf,QAAD,CAJP;EAKnBuB,UAAU,EAAEP,MAAM,CAAChB,QAAD,CALC;EAMnBwB,aAAa,EAAEP,SAAS,CAACjB,QAAD;AANL,CAFY,CAA1B"}
1
+ {"version":3,"file":"role.js","names":["matchAccessibleNameIfNeeded","node","name","queryAllByText","queryAllByLabelText","getQueriesForElement","length","matchAccessibleStateIfNeeded","options","matchAccessibilityState","queryAllByRole","instance","queryAllByRoleFn","role","findAll","type","matchStringProp","props","accessibilityRole","buildErrorMessage","errors","String","push","accessibilityStateKeys","forEach","stateKey","undefined","join","getMultipleError","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByRoleQueries","getByRole","getAllByRole","queryByRole","findByRole","findAllByRole"],"sources":["../../src/queries/role.ts"],"sourcesContent":["import { type AccessibilityState } from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\nimport { accessibilityStateKeys } from '../helpers/accessiblity';\nimport { matchAccessibilityState } from '../helpers/matchers/accessibilityState';\nimport { matchStringProp } from '../helpers/matchers/matchStringProp';\nimport type { TextMatch } from '../matches';\nimport { getQueriesForElement } from '../within';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\ntype ByRoleOptions = {\n name?: TextMatch;\n} & AccessibilityState;\n\nconst matchAccessibleNameIfNeeded = (\n node: ReactTestInstance,\n name?: TextMatch\n) => {\n if (name == null) return true;\n\n const { queryAllByText, queryAllByLabelText } = getQueriesForElement(node);\n return (\n queryAllByText(name).length > 0 || queryAllByLabelText(name).length > 0\n );\n};\n\nconst matchAccessibleStateIfNeeded = (\n node: ReactTestInstance,\n options?: ByRoleOptions\n) => {\n return options != null ? matchAccessibilityState(node, options) : true;\n};\n\nconst queryAllByRole = (\n instance: ReactTestInstance\n): ((role: TextMatch, options?: ByRoleOptions) => Array<ReactTestInstance>) =>\n function queryAllByRoleFn(role, options) {\n return instance.findAll(\n (node) =>\n // run the cheapest checks first, and early exit too avoid unneeded computations\n\n typeof node.type === 'string' &&\n matchStringProp(node.props.accessibilityRole, role) &&\n matchAccessibleStateIfNeeded(node, options) &&\n matchAccessibleNameIfNeeded(node, options?.name)\n );\n };\n\nconst buildErrorMessage = (role: TextMatch, options: ByRoleOptions = {}) => {\n const errors = [`role: \"${String(role)}\"`];\n\n if (options.name) {\n errors.push(`name: \"${String(options.name)}\"`);\n }\n\n accessibilityStateKeys.forEach((stateKey) => {\n if (options[stateKey] !== undefined) {\n errors.push(`${stateKey} state: ${options[stateKey]}`);\n }\n });\n\n return errors.join(', ');\n};\n\nconst getMultipleError = (role: TextMatch, options?: ByRoleOptions) =>\n `Found multiple elements with ${buildErrorMessage(role, options)}`;\n\nconst getMissingError = (role: TextMatch, options?: ByRoleOptions) =>\n `Unable to find an element with ${buildErrorMessage(role, options)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByRole,\n getMissingError,\n getMultipleError\n);\n\nexport type ByRoleQueries = {\n getByRole: GetByQuery<TextMatch, ByRoleOptions>;\n getAllByRole: GetAllByQuery<TextMatch, ByRoleOptions>;\n queryByRole: QueryByQuery<TextMatch, ByRoleOptions>;\n queryAllByRole: QueryAllByQuery<TextMatch, ByRoleOptions>;\n findByRole: FindByQuery<TextMatch, ByRoleOptions>;\n findAllByRole: FindAllByQuery<TextMatch, ByRoleOptions>;\n};\n\nexport const bindByRoleQueries = (\n instance: ReactTestInstance\n): ByRoleQueries => ({\n getByRole: getBy(instance),\n getAllByRole: getAllBy(instance),\n queryByRole: queryBy(instance),\n queryAllByRole: queryAllBy(instance),\n findByRole: findBy(instance),\n findAllByRole: findAllBy(instance),\n});\n"],"mappings":";;;;;;AAEA;AACA;AACA;AAEA;AACA;AAcA,MAAMA,2BAA2B,GAAG,C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KAAKC,SAAS,EAAE;MACnCN,MAAM,CAACE,IAAI,CAAE,GAAEG,QAAS,WAAUjB,OAAO,CAACiB,QAAQ,CAAE,EAAC,CAAC;IACxD;EACF,CAAC,CAAC;EAEF,OAAOL,MAAM,CAACO,IAAI,CAAC,IAAI,CAAC;AAC1B,CAAC;AAED,MAAMC,gBAAgB,GAAG,CAACf,IAAe,EAAEL,OAAuB,KAC/D,gCAA+BW,iBAAiB,CAACN,IAAI,EAAEL,OAAO,CAAE,EAAC;AAEpE,MAAMqB,eAAe,GAAG,CAAChB,IAAe,EAAEL,OAAuB,KAC9D,kCAAiCW,iBAAiB,CAACN,IAAI,EAAEL,OAAO,CAAE,EAAC;AAEtE,MAAM;EAAEsB,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7E1B,cAAc,EACdmB,eAAe,EACfD,gBAAgB,CACjB;AAWM,MAAMS,iBAAiB,GAC5B1B,QAA2B,KACR;EACnB2B,SAAS,EAAER,KAAK,CAACnB,QAAQ,CAAC;EAC1B4B,YAAY,EAAER,QAAQ,CAACpB,QAAQ,CAAC;EAChC6B,WAAW,EAAER,OAAO,CAACrB,QAAQ,CAAC;EAC9BD,cAAc,EAAEuB,UAAU,CAACtB,QAAQ,CAAC;EACpC8B,UAAU,EAAEP,MAAM,CAACvB,QAAQ,CAAC;EAC5B+B,aAAa,EAAEP,SAAS,CAACxB,QAAQ;AACnC,CAAC,CAAC;AAAC"}
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.bindByTestIdQueries = void 0;
7
-
8
7
  var _matches = require("../matches");
9
-
10
8
  var _makeQueries = require("./makeQueries");
11
-
12
9
  const getNodeByTestId = (node, testID, options = {}) => {
13
10
  const {
14
11
  exact,
@@ -16,16 +13,12 @@ const getNodeByTestId = (node, testID, options = {}) => {
16
13
  } = options;
17
14
  return (0, _matches.matches)(testID, node.props.testID, normalizer, exact);
18
15
  };
19
-
20
16
  const queryAllByTestId = instance => function queryAllByTestIdFn(testId, queryOptions) {
21
17
  const results = instance.findAll(node => getNodeByTestId(node, testId, queryOptions)).filter(element => typeof element.type === 'string');
22
18
  return results;
23
19
  };
24
-
25
20
  const getMultipleError = testId => `Found multiple elements with testID: ${String(testId)}`;
26
-
27
21
  const getMissingError = testId => `Unable to find an element with testID: ${String(testId)}`;
28
-
29
22
  const {
30
23
  getBy,
31
24
  getAllBy,
@@ -34,7 +27,6 @@ const {
34
27
  findBy,
35
28
  findAllBy
36
29
  } = (0, _makeQueries.makeQueries)(queryAllByTestId, getMissingError, getMultipleError);
37
-
38
30
  const bindByTestIdQueries = instance => ({
39
31
  getByTestId: getBy(instance),
40
32
  getAllByTestId: getAllBy(instance),
@@ -43,6 +35,5 @@ const bindByTestIdQueries = instance => ({
43
35
  findByTestId: findBy(instance),
44
36
  findAllByTestId: findAllBy(instance)
45
37
  });
46
-
47
38
  exports.bindByTestIdQueries = bindByTestIdQueries;
48
39
  //# sourceMappingURL=testId.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"testId.js","names":["getNodeByTestId","node","testID","options","exact","normalizer","matches","props","queryAllByTestId","instance","queryAllByTestIdFn","testId","queryOptions","results","findAll","filter","element","type","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTestIdQueries","getByTestId","getAllByTestId","queryByTestId","findByTestId","findAllByTestId"],"sources":["../../src/queries/testId.ts"],"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"],"mappings":";;;;;;;AACA;;AACA;;AAWA,MAAMA,eAAe,GAAG,CACtBC,IADsB,EAEtBC,MAFsB,EAGtBC,OAAyB,GAAG,EAHN,KAInB;EACH,MAAM;IAAEC,KAAF;IAASC;EAAT,IAAwBF,OAA9B;EACA,OAAO,IAAAG,gBAAA,EAAQJ,MAAR,EAAgBD,IAAI,CAACM,KAAL,CAAWL,MAA3B,EAAmCG,UAAnC,EAA+CD,KAA/C,CAAP;AACD,CAPD;;AASA,MAAMI,gBAAgB,GACpBC,QADuB,IAMvB,SAASC,kBAAT,CAA4BC,MAA5B,EAAoCC,YAApC,EAAkD;EAChD,MAAMC,OAAO,GAAGJ,QAAQ,CACrBK,OADa,CACJb,IAAD,IAAUD,eAAe,CAACC,IAAD,EAAOU,MAAP,EAAeC,YAAf,CADpB,EAEbG,MAFa,CAELC,OAAD,IAAa,OAAOA,OAAO,CAACC,IAAf,KAAwB,QAF/B,CAAhB;EAIA,OAAOJ,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;EAAEU,KAAF;EAASC,QAAT;EAAmBC,OAAnB;EAA4BC,UAA5B;EAAwCC,MAAxC;EAAgDC;AAAhD,IAA8D,IAAAC,wBAAA,EAClEnB,gBADkE,EAElEY,eAFkE,EAGlEF,gBAHkE,CAApE;;AAeO,MAAMU,mBAAmB,GAC9BnB,QADiC,KAEZ;EACrBoB,WAAW,EAAER,KAAK,CAACZ,QAAD,CADG;EAErBqB,cAAc,EAAER,QAAQ,CAACb,QAAD,CAFH;EAGrBsB,aAAa,EAAER,OAAO,CAACd,QAAD,CAHD;EAIrBD,gBAAgB,EAAEgB,UAAU,CAACf,QAAD,CAJP;EAKrBuB,YAAY,EAAEP,MAAM,CAAChB,QAAD,CALC;EAMrBwB,eAAe,EAAEP,SAAS,CAACjB,QAAD;AANL,CAFY,CAA5B"}
1
+ {"version":3,"file":"testId.js","names":["getNodeByTestId","node","testID","options","exact","normalizer","matches","props","queryAllByTestId","instance","queryAllByTestIdFn","testId","queryOptions","results","findAll","filter","element","type","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTestIdQueries","getByTestId","getAllByTestId","queryByTestId","findByTestId","findAllByTestId"],"sources":["../../src/queries/testId.ts"],"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"],"mappings":";;;;;;A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AAe,EAAEP,SAAS,CAACjB,QAAQ;AACrC,CAAC,CAAC;AAAC"}
@@ -4,87 +4,65 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.bindByTextQueries = void 0;
7
-
7
+ var _reactNative = require("react-native");
8
8
  var React = _interopRequireWildcard(require("react"));
9
-
10
- var _errors = require("../helpers/errors");
11
-
12
9
  var _filterNodeByType = require("../helpers/filterNodeByType");
13
-
10
+ var _componentTree = require("../helpers/component-tree");
14
11
  var _matches = require("../matches");
15
-
16
12
  var _makeQueries = require("./makeQueries");
17
-
18
13
  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
-
20
14
  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; }
21
-
22
- const getChildrenAsText = (children, TextComponent) => {
15
+ const getChildrenAsText = children => {
23
16
  const textContent = [];
24
17
  React.Children.forEach(children, child => {
25
18
  if (typeof child === 'string') {
26
19
  textContent.push(child);
27
20
  return;
28
21
  }
29
-
30
22
  if (typeof child === 'number') {
31
23
  textContent.push(child.toString());
32
24
  return;
33
25
  }
34
-
35
26
  if (child?.props?.children) {
36
27
  // Bail on traversing text children down the tree if current node (child)
37
28
  // has no text. In such situations, react-test-renderer will traverse down
38
29
  // this tree in a separate call and run this query again. As a result, the
39
30
  // query will match the deepest text node that matches requested text.
40
- if ((0, _filterNodeByType.filterNodeByType)(child, TextComponent)) {
31
+ if ((0, _filterNodeByType.filterNodeByType)(child, _reactNative.Text)) {
41
32
  return;
42
33
  }
43
-
44
34
  if ((0, _filterNodeByType.filterNodeByType)(child, React.Fragment)) {
45
- textContent.push(...getChildrenAsText(child.props.children, TextComponent));
35
+ textContent.push(...getChildrenAsText(child.props.children));
46
36
  }
47
37
  }
48
38
  });
49
39
  return textContent;
50
40
  };
51
-
52
41
  const getNodeByText = (node, text, options = {}) => {
53
- try {
54
- const {
55
- Text
56
- } = require('react-native');
57
-
58
- const isTextComponent = (0, _filterNodeByType.filterNodeByType)(node, Text);
59
-
60
- if (isTextComponent) {
61
- const textChildren = getChildrenAsText(node.props.children, Text);
62
-
63
- if (textChildren) {
64
- const textToTest = textChildren.join('');
65
- const {
66
- exact,
67
- normalizer
68
- } = options;
69
- return (0, _matches.matches)(text, textToTest, normalizer, exact);
70
- }
42
+ const isTextComponent = (0, _filterNodeByType.filterNodeByType)(node, _reactNative.Text);
43
+ if (isTextComponent) {
44
+ const textChildren = getChildrenAsText(node.props.children);
45
+ if (textChildren) {
46
+ const textToTest = textChildren.join('');
47
+ const {
48
+ exact,
49
+ normalizer
50
+ } = options;
51
+ return (0, _matches.matches)(text, textToTest, normalizer, exact);
71
52
  }
72
-
73
- return false;
74
- } catch (error) {
75
- throw (0, _errors.createLibraryNotSupportedError)(error);
76
53
  }
54
+ return false;
77
55
  };
78
-
79
56
  const queryAllByText = instance => function queryAllByTextFn(text, options) {
80
- const results = instance.findAll(node => getNodeByText(node, text, options));
57
+ const baseInstance = (0, _componentTree.isHostElementForType)(instance, _reactNative.Text) ? (0, _componentTree.getCompositeParentOfType)(instance, _reactNative.Text) : instance;
58
+ if (!baseInstance) {
59
+ return [];
60
+ }
61
+ const results = baseInstance.findAll(node => getNodeByText(node, text, options));
81
62
  return results;
82
63
  };
83
-
84
64
  const getMultipleError = text => `Found multiple elements with text: ${String(text)}`;
85
-
86
65
  const getMissingError = text => `Unable to find an element with text: ${String(text)}`;
87
-
88
66
  const {
89
67
  getBy,
90
68
  getAllBy,
@@ -93,7 +71,6 @@ const {
93
71
  findBy,
94
72
  findAllBy
95
73
  } = (0, _makeQueries.makeQueries)(queryAllByText, getMissingError, getMultipleError);
96
-
97
74
  const bindByTextQueries = instance => ({
98
75
  getByText: getBy(instance),
99
76
  getAllByText: getAllBy(instance),
@@ -102,6 +79,5 @@ const bindByTextQueries = instance => ({
102
79
  findByText: findBy(instance),
103
80
  findAllByText: findAllBy(instance)
104
81
  });
105
-
106
82
  exports.bindByTextQueries = bindByTextQueries;
107
83
  //# sourceMappingURL=text.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"text.js","names":["getChildrenAsText","children","TextComponent","textContent","React","Children","forEach","child","push","toString","props","filterNodeByType","Fragment","getNodeByText","node","text","options","Text","require","isTextComponent","textChildren","textToTest","join","exact","normalizer","matches","error","createLibraryNotSupportedError","queryAllByText","instance","queryAllByTextFn","results","findAll","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTextQueries","getByText","getAllByText","queryByText","findByText","findAllByText"],"sources":["../../src/queries/text.ts"],"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"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAeA,MAAMA,iBAAiB,GAAG,CACxBC,QADwB,EAExBC,aAFwB,KAGrB;EACH,MAAMC,WAAqB,GAAG,EAA9B;EACAC,KAAK,CAACC,QAAN,CAAeC,OAAf,CAAuBL,QAAvB,EAAkCM,KAAD,IAAW;IAC1C,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;MAC7BJ,WAAW,CAACK,IAAZ,CAAiBD,KAAjB;MACA;IACD;;IAED,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;MAC7BJ,WAAW,CAACK,IAAZ,CAAiBD,KAAK,CAACE,QAAN,EAAjB;MACA;IACD;;IAED,IAAIF,KAAK,EAAEG,KAAP,EAAcT,QAAlB,EAA4B;MAC1B;MACA;MACA;MACA;MACA,IAAI,IAAAU,kCAAA,EAAiBJ,KAAjB,EAAwBL,aAAxB,CAAJ,EAA4C;QAC1C;MACD;;MAED,IAAI,IAAAS,kCAAA,EAAiBJ,KAAjB,EAAwBH,KAAK,CAACQ,QAA9B,CAAJ,EAA6C;QAC3CT,WAAW,CAACK,IAAZ,CACE,GAAGR,iBAAiB,CAACO,KAAK,CAACG,KAAN,CAAYT,QAAb,EAAuBC,aAAvB,CADtB;MAGD;IACF;EACF,CA1BD;EA4BA,OAAOC,WAAP;AACD,CAlCD;;AAoCA,MAAMU,aAAa,GAAG,CACpBC,IADoB,EAEpBC,IAFoB,EAGpBC,OAAyB,GAAG,EAHR,KAIjB;EACH,IAAI;IACF,MAAM;MAAEC;IAAF,IAAWC,OAAO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e,SAAS,EAAER,KAAK,CAACP,QAAD,CADG;EAEnBgB,YAAY,EAAER,QAAQ,CAACR,QAAD,CAFH;EAGnBiB,WAAW,EAAER,OAAO,CAACT,QAAD,CAHD;EAInBD,cAAc,EAAEW,UAAU,CAACV,QAAD,CAJP;EAKnBkB,UAAU,EAAEP,MAAM,CAACX,QAAD,CALC;EAMnBmB,aAAa,EAAEP,SAAS,CAACZ,QAAD;AANL,CAFY,CAA1B"}
1
+ {"version":3,"file":"text.js","names":["getChildrenAsText","children","textContent","React","Children","forEach","child","push","toString","props","filterNodeByType","Text","Fragment","getNodeByText","node","text","options","isTextComponent","textChildren","textToTest","join","exact","normalizer","matches","queryAllByText","instance","queryAllByTextFn","baseInstance","isHostElementForType","getCompositeParentOfType","results","findAll","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTextQueries","getByText","getAllByText","queryByText","findByText","findAllByText"],"sources":["../../src/queries/text.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { Text } from 'react-native';\nimport * as React from 'react';\nimport { filterNodeByType } from '../helpers/filterNodeByType';\nimport {\n isHostElementForType,\n getCompositeParentOfType,\n} from '../helpers/component-tree';\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 = (children: React.ReactChild[]) => {\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, Text)) {\n return;\n }\n\n if (filterNodeByType(child, React.Fragment)) {\n textContent.push(...getChildrenAsText(child.props.children));\n }\n }\n });\n\n return textContent;\n};\n\nconst getNodeByText = (\n node: ReactTestInstance,\n text: TextMatch,\n options: TextMatchOptions = {}\n) => {\n const isTextComponent = filterNodeByType(node, Text);\n if (isTextComponent) {\n const textChildren = getChildrenAsText(node.props.children);\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};\n\nconst queryAllByText = (\n instance: ReactTestInstance\n): ((\n text: TextMatch,\n options?: TextMatchOptions\n) => Array<ReactTestInstance>) =>\n function queryAllByTextFn(text, options) {\n const baseInstance = isHostElementForType(instance, Text)\n ? getCompositeParentOfType(instance, Text)\n : instance;\n\n if (!baseInstance) {\n return [];\n }\n\n const results = baseInstance.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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;AACnC,CAAC,CAAC;AAAC"}
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.bindUnsafeByPropsQueries = void 0;
7
-
8
7
  var _prettyFormat = _interopRequireDefault(require("pretty-format"));
9
-
10
8
  var _errors = require("../helpers/errors");
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  const UNSAFE_getByProps = instance => function getByPropsFn(props) {
15
11
  try {
16
12
  return instance.findByProps(props);
@@ -18,17 +14,13 @@ const UNSAFE_getByProps = instance => function getByPropsFn(props) {
18
14
  throw new _errors.ErrorWithStack((0, _errors.prepareErrorMessage)(error), getByPropsFn);
19
15
  }
20
16
  };
21
-
22
17
  const UNSAFE_getAllByProps = instance => function getAllByPropsFn(props) {
23
18
  const results = instance.findAllByProps(props);
24
-
25
19
  if (results.length === 0) {
26
20
  throw new _errors.ErrorWithStack(`No instances found with props:\n${(0, _prettyFormat.default)(props)}`, getAllByPropsFn);
27
21
  }
28
-
29
22
  return results;
30
23
  };
31
-
32
24
  const UNSAFE_queryByProps = instance => function queryByPropsFn(props) {
33
25
  try {
34
26
  return UNSAFE_getByProps(instance)(props);
@@ -36,15 +28,15 @@ const UNSAFE_queryByProps = instance => function queryByPropsFn(props) {
36
28
  return (0, _errors.createQueryByError)(error, queryByPropsFn);
37
29
  }
38
30
  };
39
-
40
31
  const UNSAFE_queryAllByProps = instance => props => {
41
32
  try {
42
33
  return UNSAFE_getAllByProps(instance)(props);
43
34
  } catch (error) {
44
35
  return [];
45
36
  }
46
- }; // Unsafe aliases
37
+ };
47
38
 
39
+ // Unsafe aliases
48
40
 
49
41
  // TODO: migrate to makeQueries pattern
50
42
  const bindUnsafeByPropsQueries = instance => ({
@@ -53,6 +45,5 @@ const bindUnsafeByPropsQueries = instance => ({
53
45
  UNSAFE_queryByProps: UNSAFE_queryByProps(instance),
54
46
  UNSAFE_queryAllByProps: UNSAFE_queryAllByProps(instance)
55
47
  });
56
-
57
48
  exports.bindUnsafeByPropsQueries = bindUnsafeByPropsQueries;
58
49
  //# sourceMappingURL=unsafeProps.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"unsafeProps.js","names":["UNSAFE_getByProps","instance","getByPropsFn","props","findByProps","error","ErrorWithStack","prepareErrorMessage","UNSAFE_getAllByProps","getAllByPropsFn","results","findAllByProps","length","prettyFormat","UNSAFE_queryByProps","queryByPropsFn","createQueryByError","UNSAFE_queryAllByProps","bindUnsafeByPropsQueries"],"sources":["../../src/queries/unsafeProps.ts"],"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 (\n instance: ReactTestInstance\n ): ((props: { [propName: string]: any }) => Array<ReactTestInstance>) =>\n (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"],"mappings":";;;;;;;AACA;;AACA;;;;AAGA,MAAMA,iBAAiB,GACrBC,QADwB,IAGxB,SAASC,YAAT,CAAsBC,KAAtB,EAA0D;EACxD,IAAI;IACF,OAAOF,QAAQ,CAACG,WAAT,CAAqBD,KAArB,CAAP;EACD,CAFD,CAEE,OAAOE,KAAP,EAAc;IACd,MAAM,IAAIC,sBAAJ,CAAmB,IAAAC,2BAAA,EAAoBF,KAApB,CAAnB,EAA+CH,YAA/C,CAAN;EACD;AACF,CATH;;AAWA,MAAMM,oBAAoB,GACxBP,QAD2B,IAG3B,SAASQ,eAAT,CAAyBN,KAAzB,EAA6D;EAC3D,MAAMO,OAAO,GAAGT,QAAQ,CAACU,cAAT,CAAwBR,KAAxB,CAAhB;;EACA,IAAIO,OAAO,CAACE,MAAR,KAAmB,CAAvB,EAA0B;IACxB,MAAM,IAAIN,sBAAJ,CACH,mCAAkC,IAAAO,qBAAA,EAAaV,KAAb,CAAoB,EADnD,EAEJM,eAFI,CAAN;EAID;;EACD,OAAOC,OAAP;AACD,CAZH;;AAcA,MAAMI,mBAAmB,GACvBb,QAD0B,IAG1B,SAASc,cAAT,CAAwBZ,KAAxB,EAA4D;EAC1D,IAAI;IACF,OAAOH,iBAAiB,CAACC,QAAD,CAAjB,CAA4BE,KAA5B,CAAP;EACD,CAFD,CAEE,OAAOE,KAAP,EAAc;IACd,OAAO,IAAAW,0BAAA,EAAmBX,KAAnB,EAA0BU,cAA1B,CAAP;EACD;AACF,CATH;;AAWA,MAAME,sBAAsB,GAExBhB,QADF,IAGCE,KAAD,IAAwC;EACtC,IAAI;IACF,OAAOK,oBAAoB,CAACP,QAAD,CAApB,CAA+BE,KAA/B,CAAP;EACD,CAFD,CAEE,OAAOE,KAAP,EAAc;IACd,OAAO,EAAP;EACD;AACF,CAVH,C,CAYA;;;AAcA;AACO,MAAMa,wBAAwB,GACnCjB,QADsC,KAEZ;EAC1BD,iBAAiB,EAAEA,iBAAiB,CAACC,QAAD,CADV;EAE1BO,oBAAoB,EAAEA,oBAAoB,CAACP,QAAD,CAFhB;EAG1Ba,mBAAmB,EAAEA,mBAAmB,CAACb,QAAD,CAHd;EAI1BgB,sBAAsB,EAAEA,sBAAsB,CAAChB,QAAD;AAJpB,CAFY,CAAjC"}
1
+ {"version":3,"file":"unsafeProps.js","names":["UNSAFE_getByProps","instance","getByPropsFn","props","findByProps","error","ErrorWithStack","prepareErrorMessage","UNSAFE_getAllByProps","getAllByPropsFn","results","findAllByProps","length","prettyFormat","UNSAFE_queryByProps","queryByPropsFn","createQueryByError","UNSAFE_queryAllByProps","bindUnsafeByPropsQueries"],"sources":["../../src/queries/unsafeProps.ts"],"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 (\n instance: ReactTestInstance\n ): ((props: { [propName: string]: any }) => Array<ReactTestInstance>) =>\n (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"],"mappings":";;;;;;AACA;AACA;AAAwE;AAGxE,MAAMA,iBAAiB,GACrBC,QAA2B,IAE3B,SAASC,YAAY,CAACC,KAAkC,EAAE;EACxD,IAAI;IACF,OAAOF,QAAQ,CA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@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.bindUnsafeByTypeQueries = void 0;
7
-
8
7
  var _errors = require("../helpers/errors");
9
-
10
8
  const UNSAFE_getByType = instance => function getByTypeFn(type) {
11
9
  try {
12
10
  return instance.findByType(type);
@@ -14,17 +12,13 @@ const UNSAFE_getByType = instance => function getByTypeFn(type) {
14
12
  throw new _errors.ErrorWithStack((0, _errors.prepareErrorMessage)(error), getByTypeFn);
15
13
  }
16
14
  };
17
-
18
15
  const UNSAFE_getAllByType = instance => function getAllByTypeFn(type) {
19
16
  const results = instance.findAllByType(type);
20
-
21
17
  if (results.length === 0) {
22
18
  throw new _errors.ErrorWithStack('No instances found', getAllByTypeFn);
23
19
  }
24
-
25
20
  return results;
26
21
  };
27
-
28
22
  const UNSAFE_queryByType = instance => function queryByTypeFn(type) {
29
23
  try {
30
24
  return UNSAFE_getByType(instance)(type);
@@ -32,15 +26,15 @@ const UNSAFE_queryByType = instance => function queryByTypeFn(type) {
32
26
  return (0, _errors.createQueryByError)(error, queryByTypeFn);
33
27
  }
34
28
  };
35
-
36
29
  const UNSAFE_queryAllByType = instance => type => {
37
30
  try {
38
31
  return UNSAFE_getAllByType(instance)(type);
39
32
  } catch (error) {
40
33
  return [];
41
34
  }
42
- }; // Unsafe aliases
35
+ };
43
36
 
37
+ // Unsafe aliases
44
38
 
45
39
  // TODO: migrate to makeQueries pattern
46
40
  const bindUnsafeByTypeQueries = instance => ({
@@ -49,6 +43,5 @@ const bindUnsafeByTypeQueries = instance => ({
49
43
  UNSAFE_queryByType: UNSAFE_queryByType(instance),
50
44
  UNSAFE_queryAllByType: UNSAFE_queryAllByType(instance)
51
45
  });
52
-
53
46
  exports.bindUnsafeByTypeQueries = bindUnsafeByTypeQueries;
54
47
  //# sourceMappingURL=unsafeType.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"unsafeType.js","names":["UNSAFE_getByType","instance","getByTypeFn","type","findByType","error","ErrorWithStack","prepareErrorMessage","UNSAFE_getAllByType","getAllByTypeFn","results","findAllByType","length","UNSAFE_queryByType","queryByTypeFn","createQueryByError","UNSAFE_queryAllByType","bindUnsafeByTypeQueries"],"sources":["../../src/queries/unsafeType.ts"],"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 (\n instance: ReactTestInstance\n ): ((type: React.ComponentType<any>) => Array<ReactTestInstance>) =>\n (type: React.ComponentType<any>) => {\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"],"mappings":";;;;;;;AAEA;;AAGA,MAAMA,gBAAgB,GACpBC,QADuB,IAGvB,SAASC,WAAT,CAAqBC,IAArB,EAAqD;EACnD,IAAI;IACF,OAAOF,QAAQ,CAACG,UAAT,CAAoBD,IAApB,CAAP;EACD,CAFD,CAEE,OAAOE,KAAP,EAAc;IACd,MAAM,IAAIC,sBAAJ,CAAmB,IAAAC,2BAAA,EAAoBF,KAApB,CAAnB,EAA+CH,WAA/C,CAAN;EACD;AACF,CATH;;AAWA,MAAMM,mBAAmB,GACvBP,QAD0B,IAG1B,SAASQ,cAAT,CAAwBN,IAAxB,EAAwD;EACtD,MAAMO,OAAO,GAAGT,QAAQ,CAACU,aAAT,CAAuBR,IAAvB,CAAhB;;EACA,IAAIO,OAAO,CAACE,MAAR,KAAmB,CAAvB,EAA0B;IACxB,MAAM,IAAIN,sBAAJ,CAAmB,oBAAnB,EAAyCG,cAAzC,CAAN;EACD;;EACD,OAAOC,OAAP;AACD,CATH;;AAWA,MAAMG,kBAAkB,GACtBZ,QADyB,IAGzB,SAASa,aAAT,CAAuBX,IAAvB,EAAuD;EACrD,IAAI;IACF,OAAOH,gBAAgB,CAACC,QAAD,CAAhB,CAA2BE,IAA3B,CAAP;EACD,CAFD,CAEE,OAAOE,KAAP,EAAc;IACd,OAAO,IAAAU,0BAAA,EAAmBV,KAAnB,EAA0BS,aAA1B,CAAP;EACD;AACF,CATH;;AAWA,MAAME,qBAAqB,GAEvBf,QADF,IAGCE,IAAD,IAAoC;EAClC,IAAI;IACF,OAAOK,mBAAmB,CAACP,QAAD,CAAnB,CAA8BE,IAA9B,CAAP;EACD,CAFD,CAEE,OAAOE,KAAP,EAAc;IACd,OAAO,EAAP;EACD;AACF,CAVH,C,CAYA;;;AAcA;AACO,MAAMY,uBAAuB,GAClChB,QADqC,KAEZ;EACzBD,gBAAgB,EAAEA,gBAAgB,CAACC,QAAD,CADT;EAEzBO,mBAAmB,EAAEA,mBAAmB,CAACP,QAAD,CAFf;EAGzBY,kBAAkB,EAAEA,kBAAkB,CAACZ,QAAD,CAHb;EAIzBe,qBAAqB,EAAEA,qBAAqB,CAACf,QAAD;AAJnB,CAFY,CAAhC"}
1
+ {"version":3,"file":"unsafeType.js","names":["UNSAFE_getByType","instance","getByTypeFn","type","findByType","error","ErrorWithStack","prepareErrorMessage","UNSAFE_getAllByType","getAllByTypeFn","results","findAllByType","length","UNSAFE_queryByType","queryByTypeFn","createQueryByError","UNSAFE_queryAllByType","bindUnsafeByTypeQueries"],"sources":["../../src/queries/unsafeType.ts"],"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 (\n instance: ReactTestInstance\n ): ((type: React.ComponentType<any>) => Array<ReactTestInstance>) =>\n (type: React.ComponentType<any>) => {\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"],"mappings":";;;;;;AAEA;AAGA,MAAMA,gBAAgB,GACpBC,QAA2B,IAE3B,SAASC,WAAW,CAACC,IAA8B,EAAE;EACnD,IAAI;IACF,OAAOF,QAAQ,CAACG,UAAU,CAACD,IAAI,CAAC;EAClC,CAAC,CAAC,OAAOE,KAAK,EAAE;IACd,MAAM,IAAIC,sBAAc,CAAC,IAAAC,2BAAmB,EAACF,KAAK,CAAC,EAAEH,WAAW,CAAC;EACnE;AACF,CAAC;AAEH,MAAMM,mBAAmB,GACvBP,QAA2B,IAE3B,SAASQ,cAAc,CAACN,IAA8B,EAAE;EACtD,MAAMO,OAAO,GAAGT,QAAQ,CAACU,aAAa,CAACR,IAAI,CAAC;EAC5C,IAAIO,OAAO,CAACE,MAAM,KAAK,CAAC,EAAE;IACxB,MAAM,IAAIN,sBAAc,CAAC,oBAAoB,EAAEG,cAAc,CAAC;EAChE;EACA,OAAOC,OAAO;AAChB,CAAC;AAEH,MAAMG,kBAAkB,GACtBZ,QAA2B,IAE3B,SAASa,aAAa,CAACX,IAA8B,EAAE;EACrD,IAAI;IACF,OAAOH,gBAAgB,CAACC,QAAQ,CAAC,CAACE,IAAI,CAAC;EACzC,CAAC,CAAC,OAAOE,KAAK,EAAE;IACd,OAAO,IAAAU,0BAAkB,EAACV,KAAK,EAAES,aAAa,CAAC;EACjD;AACF,CAAC;AAEH,MAAME,qBAAqB,GAEvBf,QAA2B,IAE5BE,IAA8B,IAAK;EAClC,IAAI;IACF,OAAOK,mBAAmB,CAACP,QAAQ,CAAC,CAACE,IAAI,CAAC;EAC5C,CAAC,CAAC,OAAOE,KAAK,EAAE;IACd,OAAO,EAAE;EACX;AACF,CAAC;;AAEH;;AAcA;AACO,MAAMY,uBAAuB,GAClChB,QAA2B,KACF;EACzBD,gBAAgB,EAAEA,gBAAgB,CAACC,QAAQ,CAAC;EAC5CO,mBAAmB,EAAEA,mBAAmB,CAACP,QAAQ,CAAC;EAClDY,kBAAkB,EAAEA,kBAAkB,CAACZ,QAAQ,CAAC;EAChDe,qBAAqB,EAAEA,qBAAqB,CAACf,QAAQ;AACvD,CAAC,CAAC;AAAC"}
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.checkReactVersionAtLeast = checkReactVersionAtLeast;
7
-
8
7
  var React = _interopRequireWildcard(require("react"));
9
-
10
8
  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); }
11
-
12
9
  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; }
13
-
14
10
  function checkReactVersionAtLeast(major, minor) {
15
11
  if (React.version === undefined) return false;
16
12
  const [actualMajor, actualMinor] = React.version.split('.').map(Number);
@@ -1 +1 @@
1
- {"version":3,"file":"react-versions.js","names":["checkReactVersionAtLeast","major","minor","React","version","undefined","actualMajor","actualMinor","split","map","Number"],"sources":["../src/react-versions.ts"],"sourcesContent":["import * as React from 'react';\n\nexport function checkReactVersionAtLeast(\n major: number,\n minor: number\n): boolean {\n if (React.version === undefined) return false;\n const [actualMajor, actualMinor] = React.version.split('.').map(Number);\n\n return actualMajor > major || (actualMajor === major && actualMinor >= minor);\n}\n"],"mappings":";;;;;;;AAAA;;;;;;AAEO,SAASA,wBAAT,CACLC,KADK,EAELC,KAFK,EAGI;EACT,IAAIC,KAAK,CAACC,OAAN,KAAkBC,SAAtB,EAAiC,OAAO,KAAP;EACjC,MAAM,CAACC,WAAD,EAAcC,WAAd,IAA6BJ,KAAK,CAACC,OAAN,CAAcI,KAAd,CAAoB,GAApB,EAAyBC,GAAzB,CAA6BC,MAA7B,CAAnC;EAEA,OAAOJ,WAAW,GAAGL,KAAd,IAAwBK,WAAW,KAAKL,KAAhB,IAAyBM,WAAW,IAAIL,KAAvE;AACD"}
1
+ {"version":3,"file":"react-versions.js","names":["checkReactVersionAtLeast","major","minor","React","version","undefined","actualMajor","actualMinor","split","map","Number"],"sources":["../src/react-versions.ts"],"sourcesContent":["import * as React from 'react';\n\nexport function checkReactVersionAtLeast(\n major: number,\n minor: number\n): boolean {\n if (React.version === undefined) return false;\n const [actualMajor, actualMinor] = React.version.split('.').map(Number);\n\n return actualMajor > major || (actualMajor === major && actualMinor >= minor);\n}\n"],"mappings":";;;;;;AAAA;AAA+B;AAAA;AAExB,SAASA,wBAAwB,CACtCC,KAAa,EACbC,KAAa,EACJ;EACT,IAAIC,KAAK,CAACC,OAAO,KAAKC,SAAS,EAAE,OAAO,KAAK;EAC7C,MAAM,CAACC,WAAW,EAAEC,WAAW,CAAC,GAAGJ,KAAK,CAACC,OAAO,CAACI,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAACC,MAAM,CAAC;EAEvE,OAAOJ,WAAW,GAAGL,KAAK,IAAKK,WAAW,KAAKL,KAAK,IAAIM,WAAW,IAAIL,KAAM;AAC/E"}