@testing-library/react-native 14.0.0-alpha.6 → 14.0.0-beta.1

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 (214) hide show
  1. package/README.md +30 -30
  2. package/build/config.js +10 -4
  3. package/build/config.js.map +1 -1
  4. package/build/event-builder/base.d.ts +7 -0
  5. package/build/{user-event/event-builder → event-builder}/base.js +1 -1
  6. package/build/event-builder/base.js.map +1 -0
  7. package/build/event-builder/common.d.ts +152 -0
  8. package/build/event-builder/common.js +80 -0
  9. package/build/event-builder/common.js.map +1 -0
  10. package/build/event-builder/index.d.ts +3 -0
  11. package/build/event-builder/index.js +39 -0
  12. package/build/event-builder/index.js.map +1 -0
  13. package/build/event-builder/scroll.d.ts +56 -0
  14. package/build/event-builder/scroll.js +51 -0
  15. package/build/event-builder/scroll.js.map +1 -0
  16. package/build/event-builder/text.d.ts +162 -0
  17. package/build/event-builder/text.js +113 -0
  18. package/build/event-builder/text.js.map +1 -0
  19. package/build/event-handler.d.ts +0 -1
  20. package/build/event-handler.js +0 -1
  21. package/build/event-handler.js.map +1 -1
  22. package/build/fire-event.d.ts +6 -7
  23. package/build/fire-event.js +47 -28
  24. package/build/fire-event.js.map +1 -1
  25. package/build/helpers/accessibility.d.ts +18 -15
  26. package/build/helpers/accessibility.js +64 -47
  27. package/build/helpers/accessibility.js.map +1 -1
  28. package/build/helpers/component-tree.d.ts +9 -9
  29. package/build/helpers/component-tree.js +17 -17
  30. package/build/helpers/component-tree.js.map +1 -1
  31. package/build/helpers/errors.d.ts +1 -3
  32. package/build/helpers/errors.js +3 -36
  33. package/build/helpers/errors.js.map +1 -1
  34. package/build/helpers/find-all.d.ts +2 -2
  35. package/build/helpers/find-all.js +1 -1
  36. package/build/helpers/find-all.js.map +1 -1
  37. package/build/helpers/format-element.d.ts +5 -5
  38. package/build/helpers/format-element.js +9 -9
  39. package/build/helpers/format-element.js.map +1 -1
  40. package/build/helpers/host-component-names.d.ts +13 -13
  41. package/build/helpers/host-component-names.js +18 -18
  42. package/build/helpers/host-component-names.js.map +1 -1
  43. package/build/helpers/matchers/match-accessibility-state.d.ts +2 -2
  44. package/build/helpers/matchers/match-accessibility-state.js +6 -6
  45. package/build/helpers/matchers/match-accessibility-state.js.map +1 -1
  46. package/build/helpers/matchers/match-accessibility-value.d.ts +2 -2
  47. package/build/helpers/matchers/match-accessibility-value.js +2 -2
  48. package/build/helpers/matchers/match-accessibility-value.js.map +1 -1
  49. package/build/helpers/matchers/match-label-text.d.ts +2 -2
  50. package/build/helpers/matchers/match-label-text.js +2 -2
  51. package/build/helpers/matchers/match-label-text.js.map +1 -1
  52. package/build/helpers/matchers/match-text-content.d.ts +5 -5
  53. package/build/helpers/matchers/match-text-content.js +5 -5
  54. package/build/helpers/matchers/match-text-content.js.map +1 -1
  55. package/build/helpers/pointer-events.d.ts +2 -2
  56. package/build/helpers/pointer-events.js +4 -4
  57. package/build/helpers/pointer-events.js.map +1 -1
  58. package/build/helpers/text-content.d.ts +2 -2
  59. package/build/helpers/text-content.js +5 -5
  60. package/build/helpers/text-content.js.map +1 -1
  61. package/build/helpers/text-input.d.ts +3 -3
  62. package/build/helpers/text-input.js +6 -6
  63. package/build/helpers/text-input.js.map +1 -1
  64. package/build/helpers/validate-options.d.ts +9 -0
  65. package/build/helpers/validate-options.js +32 -0
  66. package/build/helpers/validate-options.js.map +1 -0
  67. package/build/matchers/to-be-busy.d.ts +2 -2
  68. package/build/matchers/to-be-busy.js +5 -5
  69. package/build/matchers/to-be-busy.js.map +1 -1
  70. package/build/matchers/to-be-checked.d.ts +2 -2
  71. package/build/matchers/to-be-checked.js +9 -9
  72. package/build/matchers/to-be-checked.js.map +1 -1
  73. package/build/matchers/to-be-disabled.d.ts +3 -3
  74. package/build/matchers/to-be-disabled.js +10 -10
  75. package/build/matchers/to-be-disabled.js.map +1 -1
  76. package/build/matchers/to-be-empty-element.d.ts +2 -2
  77. package/build/matchers/to-be-empty-element.js +4 -4
  78. package/build/matchers/to-be-empty-element.js.map +1 -1
  79. package/build/matchers/to-be-expanded.d.ts +3 -3
  80. package/build/matchers/to-be-expanded.js +10 -10
  81. package/build/matchers/to-be-expanded.js.map +1 -1
  82. package/build/matchers/to-be-on-the-screen.d.ts +2 -2
  83. package/build/matchers/to-be-on-the-screen.js +7 -7
  84. package/build/matchers/to-be-on-the-screen.js.map +1 -1
  85. package/build/matchers/to-be-partially-checked.d.ts +2 -2
  86. package/build/matchers/to-be-partially-checked.js +8 -8
  87. package/build/matchers/to-be-partially-checked.js.map +1 -1
  88. package/build/matchers/to-be-selected.d.ts +2 -2
  89. package/build/matchers/to-be-selected.js +4 -4
  90. package/build/matchers/to-be-selected.js.map +1 -1
  91. package/build/matchers/to-be-visible.d.ts +2 -2
  92. package/build/matchers/to-be-visible.js +12 -12
  93. package/build/matchers/to-be-visible.js.map +1 -1
  94. package/build/matchers/to-contain-element.d.ts +2 -2
  95. package/build/matchers/to-contain-element.js +6 -6
  96. package/build/matchers/to-contain-element.js.map +1 -1
  97. package/build/matchers/to-have-accessibility-value.d.ts +2 -2
  98. package/build/matchers/to-have-accessibility-value.js +6 -6
  99. package/build/matchers/to-have-accessibility-value.js.map +1 -1
  100. package/build/matchers/to-have-accessible-name.d.ts +2 -2
  101. package/build/matchers/to-have-accessible-name.js +5 -10
  102. package/build/matchers/to-have-accessible-name.js.map +1 -1
  103. package/build/matchers/to-have-display-value.d.ts +2 -2
  104. package/build/matchers/to-have-display-value.js +6 -6
  105. package/build/matchers/to-have-display-value.js.map +1 -1
  106. package/build/matchers/to-have-prop.d.ts +2 -2
  107. package/build/matchers/to-have-prop.js +6 -6
  108. package/build/matchers/to-have-prop.js.map +1 -1
  109. package/build/matchers/to-have-style.d.ts +2 -2
  110. package/build/matchers/to-have-style.js +5 -5
  111. package/build/matchers/to-have-style.js.map +1 -1
  112. package/build/matchers/to-have-text-content.d.ts +2 -2
  113. package/build/matchers/to-have-text-content.js +4 -4
  114. package/build/matchers/to-have-text-content.js.map +1 -1
  115. package/build/matchers/types.d.ts +20 -20
  116. package/build/matchers/types.js.map +1 -1
  117. package/build/matchers/utils.d.ts +4 -4
  118. package/build/matchers/utils.js +6 -6
  119. package/build/matchers/utils.js.map +1 -1
  120. package/build/native-state.d.ts +3 -3
  121. package/build/native-state.js +2 -2
  122. package/build/native-state.js.map +1 -1
  123. package/build/queries/display-value.d.ts +2 -2
  124. package/build/queries/display-value.js +12 -12
  125. package/build/queries/display-value.js.map +1 -1
  126. package/build/queries/hint-text.d.ts +2 -2
  127. package/build/queries/hint-text.js +11 -11
  128. package/build/queries/hint-text.js.map +1 -1
  129. package/build/queries/label-text.d.ts +2 -2
  130. package/build/queries/label-text.js +9 -9
  131. package/build/queries/label-text.js.map +1 -1
  132. package/build/queries/make-queries.d.ts +8 -8
  133. package/build/queries/make-queries.js +11 -11
  134. package/build/queries/make-queries.js.map +1 -1
  135. package/build/queries/placeholder-text.d.ts +2 -2
  136. package/build/queries/placeholder-text.js +11 -11
  137. package/build/queries/placeholder-text.js.map +1 -1
  138. package/build/queries/role.d.ts +2 -2
  139. package/build/queries/role.js +17 -27
  140. package/build/queries/role.js.map +1 -1
  141. package/build/queries/test-id.d.ts +2 -2
  142. package/build/queries/test-id.js +11 -11
  143. package/build/queries/test-id.js.map +1 -1
  144. package/build/queries/text.d.ts +2 -2
  145. package/build/queries/text.js +9 -9
  146. package/build/queries/text.js.map +1 -1
  147. package/build/render-hook.js +7 -1
  148. package/build/render-hook.js.map +1 -1
  149. package/build/render.d.ts +4 -5
  150. package/build/render.js +22 -6
  151. package/build/render.js.map +1 -1
  152. package/build/screen.js.map +1 -1
  153. package/build/test-utils/react-version-gates.d.ts +1 -0
  154. package/build/test-utils/react-version-gates.js +28 -0
  155. package/build/test-utils/react-version-gates.js.map +1 -0
  156. package/build/test-utils/timers.d.ts +2 -0
  157. package/build/test-utils/timers.js +20 -0
  158. package/build/test-utils/timers.js.map +1 -0
  159. package/build/types.d.ts +7 -0
  160. package/build/types.js.map +1 -1
  161. package/build/user-event/clear.d.ts +2 -2
  162. package/build/user-event/clear.js +13 -13
  163. package/build/user-event/clear.js.map +1 -1
  164. package/build/user-event/index.d.ts +7 -7
  165. package/build/user-event/index.js +6 -6
  166. package/build/user-event/index.js.map +1 -1
  167. package/build/user-event/paste.d.ts +2 -2
  168. package/build/user-event/paste.js +18 -18
  169. package/build/user-event/paste.js.map +1 -1
  170. package/build/user-event/press/press.d.ts +3 -3
  171. package/build/user-event/press/press.js +35 -35
  172. package/build/user-event/press/press.js.map +1 -1
  173. package/build/user-event/scroll/scroll-to.d.ts +2 -2
  174. package/build/user-event/scroll/scroll-to.js +20 -20
  175. package/build/user-event/scroll/scroll-to.js.map +1 -1
  176. package/build/user-event/setup/setup.d.ts +11 -11
  177. package/build/user-event/setup/setup.js +17 -3
  178. package/build/user-event/setup/setup.js.map +1 -1
  179. package/build/user-event/type/type.d.ts +3 -3
  180. package/build/user-event/type/type.js +27 -28
  181. package/build/user-event/type/type.js.map +1 -1
  182. package/build/user-event/utils/dispatch-event.d.ts +3 -3
  183. package/build/user-event/utils/dispatch-event.js +4 -4
  184. package/build/user-event/utils/dispatch-event.js.map +1 -1
  185. package/build/user-event/utils/index.d.ts +0 -1
  186. package/build/user-event/utils/index.js +0 -11
  187. package/build/user-event/utils/index.js.map +1 -1
  188. package/build/wait-for.js +8 -13
  189. package/build/wait-for.js.map +1 -1
  190. package/build/within.d.ts +3 -3
  191. package/build/within.js +10 -10
  192. package/build/within.js.map +1 -1
  193. package/package.json +38 -27
  194. package/build/react-versions.d.ts +0 -1
  195. package/build/react-versions.js +0 -14
  196. package/build/react-versions.js.map +0 -1
  197. package/build/tsconfig.release.tsbuildinfo +0 -1
  198. package/build/user-event/event-builder/base.d.ts +0 -3
  199. package/build/user-event/event-builder/base.js.map +0 -1
  200. package/build/user-event/event-builder/common.d.ts +0 -150
  201. package/build/user-event/event-builder/common.js +0 -77
  202. package/build/user-event/event-builder/common.js.map +0 -1
  203. package/build/user-event/event-builder/index.d.ts +0 -306
  204. package/build/user-event/event-builder/index.js +0 -15
  205. package/build/user-event/event-builder/index.js.map +0 -1
  206. package/build/user-event/event-builder/scroll-view.d.ts +0 -57
  207. package/build/user-event/event-builder/scroll-view.js +0 -53
  208. package/build/user-event/event-builder/scroll-view.js.map +0 -1
  209. package/build/user-event/event-builder/text-input.d.ts +0 -159
  210. package/build/user-event/event-builder/text-input.js +0 -105
  211. package/build/user-event/event-builder/text-input.js.map +0 -1
  212. package/build/user-event/utils/text-range.d.ts +0 -4
  213. package/build/user-event/utils/text-range.js +0 -6
  214. package/build/user-event/utils/text-range.js.map +0 -1
@@ -10,33 +10,23 @@ var _matchAccessibilityState = require("../helpers/matchers/match-accessibility-
10
10
  var _matchAccessibilityValue = require("../helpers/matchers/match-accessibility-value");
11
11
  var _matchStringProp = require("../helpers/matchers/match-string-prop");
12
12
  var _matches = require("../matches");
13
- var _within = require("../within");
14
13
  var _makeQueries = require("./make-queries");
15
- const matchAccessibleNameIfNeeded = (node, name) => {
14
+ const matchAccessibleNameIfNeeded = (instance, name) => {
16
15
  if (name == null) return true;
17
-
18
- // TODO: rewrite computeAccessibleName for real world a11y compliance
19
- const accessibleName = (0, _accessibility.computeAccessibleName)(node);
20
- if ((0, _matches.matches)(name, accessibleName)) {
21
- return true;
22
- }
23
- const {
24
- queryAllByText,
25
- queryAllByLabelText
26
- } = (0, _within.getQueriesForElement)(node);
27
- return queryAllByText(name).length > 0 || queryAllByLabelText(name).length > 0;
16
+ const accessibleName = (0, _accessibility.computeAccessibleName)(instance);
17
+ return (0, _matches.matches)(name, accessibleName);
28
18
  };
29
- const matchAccessibleStateIfNeeded = (node, options) => {
30
- return options != null ? (0, _matchAccessibilityState.matchAccessibilityState)(node, options) : true;
19
+ const matchAccessibleStateIfNeeded = (instance, options) => {
20
+ return options != null ? (0, _matchAccessibilityState.matchAccessibilityState)(instance, options) : true;
31
21
  };
32
- const matchAccessibilityValueIfNeeded = (node, value) => {
33
- return value != null ? (0, _matchAccessibilityValue.matchAccessibilityValue)(node, value) : true;
22
+ const matchAccessibilityValueIfNeeded = (instance, value) => {
23
+ return value != null ? (0, _matchAccessibilityValue.matchAccessibilityValue)(instance, value) : true;
34
24
  };
35
- const queryAllByRole = element => function queryAllByRoleFn(role, options) {
25
+ const queryAllByRole = instance => function queryAllByRoleFn(role, options) {
36
26
  const normalizedRole = typeof role === 'string' ? (0, _accessibility.normalizeRole)(role) : role;
37
- return (0, _findAll.findAll)(element, node =>
27
+ return (0, _findAll.findAll)(instance, item =>
38
28
  // run the cheapest checks first, and early exit to avoid unneeded computations
39
- (0, _accessibility.isAccessibilityElement)(node) && (0, _matchStringProp.matchStringProp)((0, _accessibility.getRole)(node), normalizedRole) && matchAccessibleStateIfNeeded(node, options) && matchAccessibilityValueIfNeeded(node, options?.value) && matchAccessibleNameIfNeeded(node, options?.name), options);
29
+ (0, _accessibility.isAccessibilityElement)(item) && (0, _matchStringProp.matchStringProp)((0, _accessibility.getRole)(item), normalizedRole) && matchAccessibleStateIfNeeded(item, options) && matchAccessibilityValueIfNeeded(item, options?.value) && matchAccessibleNameIfNeeded(item, options?.name), options);
40
30
  };
41
31
  const formatQueryParams = (role, options = {}) => {
42
32
  const params = [`role: ${String(role)}`];
@@ -65,13 +55,13 @@ const {
65
55
  findBy,
66
56
  findAllBy
67
57
  } = (0, _makeQueries.makeQueries)(queryAllByRole, getMissingError, getMultipleError);
68
- const bindByRoleQueries = element => ({
69
- getByRole: getBy(element),
70
- getAllByRole: getAllBy(element),
71
- queryByRole: queryBy(element),
72
- queryAllByRole: queryAllBy(element),
73
- findByRole: findBy(element),
74
- findAllByRole: findAllBy(element)
58
+ const bindByRoleQueries = instance => ({
59
+ getByRole: getBy(instance),
60
+ getAllByRole: getAllBy(instance),
61
+ queryByRole: queryBy(instance),
62
+ queryAllByRole: queryAllBy(instance),
63
+ findByRole: findBy(instance),
64
+ findAllByRole: findAllBy(instance)
75
65
  });
76
66
  exports.bindByRoleQueries = bindByRoleQueries;
77
67
  //# sourceMappingURL=role.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"role.js","names":["_accessibility","require","_findAll","_matchAccessibilityState","_matchAccessibilityValue","_matchStringProp","_matches","_within","_makeQueries","matchAccessibleNameIfNeeded","node","name","accessibleName","computeAccessibleName","matches","queryAllByText","queryAllByLabelText","getQueriesForElement","length","matchAccessibleStateIfNeeded","options","matchAccessibilityState","matchAccessibilityValueIfNeeded","value","matchAccessibilityValue","queryAllByRole","element","queryAllByRoleFn","role","normalizedRole","normalizeRole","findAll","isAccessibilityElement","matchStringProp","getRole","formatQueryParams","params","String","push","accessibilityStateKeys","forEach","stateKey","undefined","accessibilityValueKeys","valueKey","join","getMultipleError","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByRoleQueries","getByRole","getAllByRole","queryByRole","findByRole","findAllByRole","exports"],"sources":["../../src/queries/role.ts"],"sourcesContent":["import type { AccessibilityRole, Role } from 'react-native';\nimport type { HostElement } from 'test-renderer';\n\nimport {\n accessibilityStateKeys,\n accessibilityValueKeys,\n computeAccessibleName,\n getRole,\n isAccessibilityElement,\n normalizeRole,\n} from '../helpers/accessibility';\nimport { findAll } from '../helpers/find-all';\nimport type { AccessibilityStateMatcher } from '../helpers/matchers/match-accessibility-state';\nimport { matchAccessibilityState } from '../helpers/matchers/match-accessibility-state';\nimport type { AccessibilityValueMatcher } from '../helpers/matchers/match-accessibility-value';\nimport { matchAccessibilityValue } from '../helpers/matchers/match-accessibility-value';\nimport { matchStringProp } from '../helpers/matchers/match-string-prop';\nimport { matches, type TextMatch } from '../matches';\nimport type { StringWithAutocomplete } from '../types';\nimport { getQueriesForElement } from '../within';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './make-queries';\nimport { makeQueries } from './make-queries';\nimport type { CommonQueryOptions } from './options';\n\nexport type ByRoleMatcher = StringWithAutocomplete<AccessibilityRole | Role> | RegExp;\n\nexport type ByRoleOptions = CommonQueryOptions &\n AccessibilityStateMatcher & {\n name?: TextMatch;\n value?: AccessibilityValueMatcher;\n };\n\nconst matchAccessibleNameIfNeeded = (node: HostElement, name?: TextMatch) => {\n if (name == null) return true;\n\n // TODO: rewrite computeAccessibleName for real world a11y compliance\n const accessibleName = computeAccessibleName(node);\n if (matches(name, accessibleName)) {\n return true;\n }\n\n const { queryAllByText, queryAllByLabelText } = getQueriesForElement(node);\n return queryAllByText(name).length > 0 || queryAllByLabelText(name).length > 0;\n};\n\nconst matchAccessibleStateIfNeeded = (node: HostElement, options?: ByRoleOptions) => {\n return options != null ? matchAccessibilityState(node, options) : true;\n};\n\nconst matchAccessibilityValueIfNeeded = (node: HostElement, value?: AccessibilityValueMatcher) => {\n return value != null ? matchAccessibilityValue(node, value) : true;\n};\n\nconst queryAllByRole = (element: HostElement): QueryAllByQuery<ByRoleMatcher, ByRoleOptions> =>\n function queryAllByRoleFn(role, options) {\n const normalizedRole = typeof role === 'string' ? normalizeRole(role) : role;\n return findAll(\n element,\n (node) =>\n // run the cheapest checks first, and early exit to avoid unneeded computations\n isAccessibilityElement(node) &&\n matchStringProp(getRole(node), normalizedRole) &&\n matchAccessibleStateIfNeeded(node, options) &&\n matchAccessibilityValueIfNeeded(node, options?.value) &&\n matchAccessibleNameIfNeeded(node, options?.name),\n options,\n );\n };\n\nconst formatQueryParams = (role: TextMatch, options: ByRoleOptions = {}) => {\n const params = [`role: ${String(role)}`];\n\n if (options.name) {\n params.push(`name: ${String(options.name)}`);\n }\n\n accessibilityStateKeys.forEach((stateKey) => {\n if (options[stateKey] !== undefined) {\n params.push(`${stateKey} state: ${options[stateKey]}`);\n }\n });\n\n accessibilityValueKeys.forEach((valueKey) => {\n if (options?.value?.[valueKey] !== undefined) {\n params.push(`${valueKey} value: ${options?.value?.[valueKey]}`);\n }\n });\n\n return params.join(', ');\n};\n\nconst getMultipleError = (role: TextMatch, options?: ByRoleOptions) =>\n `Found multiple elements with ${formatQueryParams(role, options)}`;\n\nconst getMissingError = (role: TextMatch, options?: ByRoleOptions) =>\n `Unable to find an element with ${formatQueryParams(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<ByRoleMatcher, ByRoleOptions>;\n getAllByRole: GetAllByQuery<ByRoleMatcher, ByRoleOptions>;\n queryByRole: QueryByQuery<ByRoleMatcher, ByRoleOptions>;\n queryAllByRole: QueryAllByQuery<ByRoleMatcher, ByRoleOptions>;\n findByRole: FindByQuery<ByRoleMatcher, ByRoleOptions>;\n findAllByRole: FindAllByQuery<ByRoleMatcher, ByRoleOptions>;\n};\n\nexport const bindByRoleQueries = (element: HostElement): ByRoleQueries => ({\n getByRole: getBy(element),\n getAllByRole: getAllBy(element),\n queryByRole: queryBy(element),\n queryAllByRole: queryAllBy(element),\n findByRole: findBy(element),\n findAllByRole: findAllBy(element),\n});\n"],"mappings":";;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AAQA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,wBAAA,GAAAF,OAAA;AAEA,IAAAG,wBAAA,GAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AAEA,IAAAM,OAAA,GAAAN,OAAA;AASA,IAAAO,YAAA,GAAAP,OAAA;AAWA,MAAMQ,2BAA2B,GAAGA,CAACC,IAAiB,EAAEC,IAAgB,KAAK;EAC3E,IAAIA,IAAI,IAAI,IAAI,EAAE,OAAO,IAAI;;EAE7B;EACA,MAAMC,cAAc,GAAG,IAAAC,oCAAqB,EAACH,IAAI,CAAC;EAClD,IAAI,IAAAI,gBAAO,EAACH,IAAI,EAAEC,cAAc,CAAC,EAAE;IACjC,OAAO,IAAI;EACb;EAEA,MAAM;IAAEG,cAAc;IAAEC;EAAoB,CAAC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AAER,OAAO,CAACxB,OAAO,CAAC;EAC7BD,cAAc,EAAE0B,UAAU,CAACzB,OAAO,CAAC;EACnCiC,UAAU,EAAEP,MAAM,CAAC1B,OAAO,CAAC;EAC3BkC,aAAa,EAAEP,SAAS,CAAC3B,OAAO;AAClC,CAAC,CAAC;AAACmC,OAAA,CAAAN,iBAAA,GAAAA,iBAAA","ignoreList":[]}
1
+ {"version":3,"file":"role.js","names":["_accessibility","require","_findAll","_matchAccessibilityState","_matchAccessibilityValue","_matchStringProp","_matches","_makeQueries","matchAccessibleNameIfNeeded","instance","name","accessibleName","computeAccessibleName","matches","matchAccessibleStateIfNeeded","options","matchAccessibilityState","matchAccessibilityValueIfNeeded","value","matchAccessibilityValue","queryAllByRole","queryAllByRoleFn","role","normalizedRole","normalizeRole","findAll","item","isAccessibilityElement","matchStringProp","getRole","formatQueryParams","params","String","push","accessibilityStateKeys","forEach","stateKey","undefined","accessibilityValueKeys","valueKey","join","getMultipleError","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByRoleQueries","getByRole","getAllByRole","queryByRole","findByRole","findAllByRole","exports"],"sources":["../../src/queries/role.ts"],"sourcesContent":["import type { AccessibilityRole, Role } from 'react-native';\nimport type { TestInstance } from 'test-renderer';\n\nimport {\n accessibilityStateKeys,\n accessibilityValueKeys,\n computeAccessibleName,\n getRole,\n isAccessibilityElement,\n normalizeRole,\n} from '../helpers/accessibility';\nimport { findAll } from '../helpers/find-all';\nimport type { AccessibilityStateMatcher } from '../helpers/matchers/match-accessibility-state';\nimport { matchAccessibilityState } from '../helpers/matchers/match-accessibility-state';\nimport type { AccessibilityValueMatcher } from '../helpers/matchers/match-accessibility-value';\nimport { matchAccessibilityValue } from '../helpers/matchers/match-accessibility-value';\nimport { matchStringProp } from '../helpers/matchers/match-string-prop';\nimport { matches, type TextMatch } from '../matches';\nimport type { StringWithAutocomplete } from '../types';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './make-queries';\nimport { makeQueries } from './make-queries';\nimport type { CommonQueryOptions } from './options';\n\nexport type ByRoleMatcher = StringWithAutocomplete<AccessibilityRole | Role> | RegExp;\n\nexport type ByRoleOptions = CommonQueryOptions &\n AccessibilityStateMatcher & {\n name?: TextMatch;\n value?: AccessibilityValueMatcher;\n };\n\nconst matchAccessibleNameIfNeeded = (instance: TestInstance, name?: TextMatch) => {\n if (name == null) return true;\n\n const accessibleName = computeAccessibleName(instance);\n return matches(name, accessibleName);\n};\n\nconst matchAccessibleStateIfNeeded = (instance: TestInstance, options?: ByRoleOptions) => {\n return options != null ? matchAccessibilityState(instance, options) : true;\n};\n\nconst matchAccessibilityValueIfNeeded = (\n instance: TestInstance,\n value?: AccessibilityValueMatcher,\n) => {\n return value != null ? matchAccessibilityValue(instance, value) : true;\n};\n\nconst queryAllByRole = (instance: TestInstance): QueryAllByQuery<ByRoleMatcher, ByRoleOptions> =>\n function queryAllByRoleFn(role, options) {\n const normalizedRole = typeof role === 'string' ? normalizeRole(role) : role;\n return findAll(\n instance,\n (item) =>\n // run the cheapest checks first, and early exit to avoid unneeded computations\n isAccessibilityElement(item) &&\n matchStringProp(getRole(item), normalizedRole) &&\n matchAccessibleStateIfNeeded(item, options) &&\n matchAccessibilityValueIfNeeded(item, options?.value) &&\n matchAccessibleNameIfNeeded(item, options?.name),\n options,\n );\n };\n\nconst formatQueryParams = (role: TextMatch, options: ByRoleOptions = {}) => {\n const params = [`role: ${String(role)}`];\n\n if (options.name) {\n params.push(`name: ${String(options.name)}`);\n }\n\n accessibilityStateKeys.forEach((stateKey) => {\n if (options[stateKey] !== undefined) {\n params.push(`${stateKey} state: ${options[stateKey]}`);\n }\n });\n\n accessibilityValueKeys.forEach((valueKey) => {\n if (options?.value?.[valueKey] !== undefined) {\n params.push(`${valueKey} value: ${options?.value?.[valueKey]}`);\n }\n });\n\n return params.join(', ');\n};\n\nconst getMultipleError = (role: TextMatch, options?: ByRoleOptions) =>\n `Found multiple elements with ${formatQueryParams(role, options)}`;\n\nconst getMissingError = (role: TextMatch, options?: ByRoleOptions) =>\n `Unable to find an element with ${formatQueryParams(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<ByRoleMatcher, ByRoleOptions>;\n getAllByRole: GetAllByQuery<ByRoleMatcher, ByRoleOptions>;\n queryByRole: QueryByQuery<ByRoleMatcher, ByRoleOptions>;\n queryAllByRole: QueryAllByQuery<ByRoleMatcher, ByRoleOptions>;\n findByRole: FindByQuery<ByRoleMatcher, ByRoleOptions>;\n findAllByRole: FindAllByQuery<ByRoleMatcher, ByRoleOptions>;\n};\n\nexport const bindByRoleQueries = (instance: TestInstance): 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":";;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AAQA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,wBAAA,GAAAF,OAAA;AAEA,IAAAG,wBAAA,GAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AAUA,IAAAM,YAAA,GAAAN,OAAA;AAWA,MAAMO,2BAA2B,GAAGA,CAACC,QAAsB,EAAEC,IAAgB,KAAK;EAChF,IAAIA,IAAI,IAAI,IAAI,EAAE,OAAO,IAAI;EAE7B,MAAMC,cAAc,GAAG,IAAAC,oCAAqB,EAACH,QAAQ,CAAC;EACtD,OAAO,IAAAI,gBAAO,EAACH,IAAI,EAAEC,cAAc,CAAC;AACtC,CAAC;AAED,MAAMG,4BAA4B,GAAGA,CAACL,QAAsB,EAAEM,OAAuB,KAAK;E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A,iBAAA","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import type { HostElement } from 'test-renderer';
1
+ import type { TestInstance } from 'test-renderer';
2
2
  import type { TextMatch, TextMatchOptions } from '../matches';
3
3
  import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './make-queries';
4
4
  import type { CommonQueryOptions } from './options';
@@ -11,5 +11,5 @@ export type ByTestIdQueries = {
11
11
  findByTestId: FindByQuery<TextMatch, ByTestIdOptions>;
12
12
  findAllByTestId: FindAllByQuery<TextMatch, ByTestIdOptions>;
13
13
  };
14
- export declare const bindByTestIdQueries: (element: HostElement) => ByTestIdQueries;
14
+ export declare const bindByTestIdQueries: (instance: TestInstance) => ByTestIdQueries;
15
15
  export {};
@@ -7,15 +7,15 @@ exports.bindByTestIdQueries = void 0;
7
7
  var _findAll = require("../helpers/find-all");
8
8
  var _matches = require("../matches");
9
9
  var _makeQueries = require("./make-queries");
10
- const matchTestId = (node, testId, options = {}) => {
10
+ const matchTestId = (instance, testId, options = {}) => {
11
11
  const {
12
12
  exact,
13
13
  normalizer
14
14
  } = options;
15
- return (0, _matches.matches)(testId, node.props.testID, normalizer, exact);
15
+ return (0, _matches.matches)(testId, instance.props.testID, normalizer, exact);
16
16
  };
17
- const queryAllByTestId = element => function queryAllByTestIdFn(testId, queryOptions) {
18
- return (0, _findAll.findAll)(element, node => matchTestId(node, testId, queryOptions), queryOptions);
17
+ const queryAllByTestId = instance => function queryAllByTestIdFn(testId, queryOptions) {
18
+ return (0, _findAll.findAll)(instance, item => matchTestId(item, testId, queryOptions), queryOptions);
19
19
  };
20
20
  const getMultipleError = testId => `Found multiple elements with testID: ${String(testId)}`;
21
21
  const getMissingError = testId => `Unable to find an element with testID: ${String(testId)}`;
@@ -27,13 +27,13 @@ const {
27
27
  findBy,
28
28
  findAllBy
29
29
  } = (0, _makeQueries.makeQueries)(queryAllByTestId, getMissingError, getMultipleError);
30
- const bindByTestIdQueries = element => ({
31
- getByTestId: getBy(element),
32
- getAllByTestId: getAllBy(element),
33
- queryByTestId: queryBy(element),
34
- queryAllByTestId: queryAllBy(element),
35
- findByTestId: findBy(element),
36
- findAllByTestId: findAllBy(element)
30
+ const bindByTestIdQueries = instance => ({
31
+ getByTestId: getBy(instance),
32
+ getAllByTestId: getAllBy(instance),
33
+ queryByTestId: queryBy(instance),
34
+ queryAllByTestId: queryAllBy(instance),
35
+ findByTestId: findBy(instance),
36
+ findAllByTestId: findAllBy(instance)
37
37
  });
38
38
  exports.bindByTestIdQueries = bindByTestIdQueries;
39
39
  //# sourceMappingURL=test-id.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"test-id.js","names":["_findAll","require","_matches","_makeQueries","matchTestId","node","testId","options","exact","normalizer","matches","props","testID","queryAllByTestId","element","queryAllByTestIdFn","queryOptions","findAll","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTestIdQueries","getByTestId","getAllByTestId","queryByTestId","findByTestId","findAllByTestId","exports"],"sources":["../../src/queries/test-id.ts"],"sourcesContent":["import type { HostElement } from 'test-renderer';\n\nimport { findAll } from '../helpers/find-all';\nimport type { TextMatch, TextMatchOptions } from '../matches';\nimport { matches } from '../matches';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './make-queries';\nimport { makeQueries } from './make-queries';\nimport type { CommonQueryOptions } from './options';\n\ntype ByTestIdOptions = CommonQueryOptions & TextMatchOptions;\n\nconst matchTestId = (node: HostElement, testId: TextMatch, options: TextMatchOptions = {}) => {\n const { exact, normalizer } = options;\n return matches(testId, node.props.testID, normalizer, exact);\n};\n\nconst queryAllByTestId = (element: HostElement): QueryAllByQuery<TextMatch, ByTestIdOptions> =>\n function queryAllByTestIdFn(testId, queryOptions) {\n return findAll(element, (node) => matchTestId(node, testId, queryOptions), queryOptions);\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, ByTestIdOptions>;\n getAllByTestId: GetAllByQuery<TextMatch, ByTestIdOptions>;\n queryByTestId: QueryByQuery<TextMatch, ByTestIdOptions>;\n queryAllByTestId: QueryAllByQuery<TextMatch, ByTestIdOptions>;\n findByTestId: FindByQuery<TextMatch, ByTestIdOptions>;\n findAllByTestId: FindAllByQuery<TextMatch, ByTestIdOptions>;\n};\n\nexport const bindByTestIdQueries = (element: HostElement): ByTestIdQueries => ({\n getByTestId: getBy(element),\n getAllByTestId: getAllBy(element),\n queryByTestId: queryBy(element),\n queryAllByTestId: queryAllBy(element),\n findByTestId: findBy(element),\n findAllByTestId: findAllBy(element),\n});\n"],"mappings":";;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AASA,IAAAE,YAAA,GAAAF,OAAA;AAKA,MAAMG,WAAW,GAAGA,CAACC,IAAiB,EAAEC,MAAiB,EAAEC,OAAyB,GAAG,CAAC,CAAC,KAAK;EAC5F,MAAM;IAAEC,KAAK;IAAEC;EAAW,CAAC,GAAGF,OAAO;EACrC,OAAO,IAAAG,gBAAO,EAACJ,MAAM,EAAED,IAAI,CAACM,KAAK,CAACC,MAAM,EAAEH,UAAU,EAAED,KAAK,CAAC;AAC9D,CAAC;AAED,MAAMK,gBAAgB,GAAIC,OAAoB,IAC5C,SAASC,kBAAkBA,CAACT,MAAM,EAAEU,YAAY,EAAE;EAChD,OAAO,IAAAC,gBAAO,EAACH,OAAO,EAAGT,IAAI,IAAKD,WAAW,CAACC,IAAI,EAAEC,MAAM,EAAEU,YAAY,CAAC,EAAEA,YAAY,CAAC;AAC1F,CAAC;AAEH,MAAME,gBAAgB,GAAIZ,MAAiB,IACzC,wCAAwCa,MAAM,CAACb,MAAM,CAAC,EAAE;AAC1D,MAAMc,eAAe,GAAId,MAAiB,IACxC,0CAA0Ca,MAAM,CAACb,MAAM,CAAC,EAAE;AAE5D,MAAM;EAAEe,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7Ed,gBAAgB,EAChBO,eAAe,EACfF,gBACF,CAAC;AAWM,MAAMU,mBAAmB,GAAId,OAAoB,KAAuB;EAC7Ee,WAAW,EAAER,KAAK,CAACP,OAAO,CAAC;EAC3BgB,cAAc,EAAER,QAAQ,CAACR,OAAO,CAAC;EACjCiB,aAAa,EAAER,OAAO,CAACT,OAAO,CAAC;EAC/BD,gBAAgB,EAAEW,UAAU,CAACV,OAAO,CAAC;EACrCkB,YAAY,EAAEP,MAAM,CAACX,OAAO,CAAC;EAC7BmB,eAAe,EAAEP,SAAS,CAACZ,OAAO;AACpC,CAAC,CAAC;AAACoB,OAAA,CAAAN,mBAAA,GAAAA,mBAAA","ignoreList":[]}
1
+ {"version":3,"file":"test-id.js","names":["_findAll","require","_matches","_makeQueries","matchTestId","instance","testId","options","exact","normalizer","matches","props","testID","queryAllByTestId","queryAllByTestIdFn","queryOptions","findAll","item","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTestIdQueries","getByTestId","getAllByTestId","queryByTestId","findByTestId","findAllByTestId","exports"],"sources":["../../src/queries/test-id.ts"],"sourcesContent":["import type { TestInstance } from 'test-renderer';\n\nimport { findAll } from '../helpers/find-all';\nimport type { TextMatch, TextMatchOptions } from '../matches';\nimport { matches } from '../matches';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './make-queries';\nimport { makeQueries } from './make-queries';\nimport type { CommonQueryOptions } from './options';\n\ntype ByTestIdOptions = CommonQueryOptions & TextMatchOptions;\n\nconst matchTestId = (instance: TestInstance, testId: TextMatch, options: TextMatchOptions = {}) => {\n const { exact, normalizer } = options;\n return matches(testId, instance.props.testID, normalizer, exact);\n};\n\nconst queryAllByTestId = (instance: TestInstance): QueryAllByQuery<TextMatch, ByTestIdOptions> =>\n function queryAllByTestIdFn(testId, queryOptions) {\n return findAll(instance, (item) => matchTestId(item, testId, queryOptions), queryOptions);\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, ByTestIdOptions>;\n getAllByTestId: GetAllByQuery<TextMatch, ByTestIdOptions>;\n queryByTestId: QueryByQuery<TextMatch, ByTestIdOptions>;\n queryAllByTestId: QueryAllByQuery<TextMatch, ByTestIdOptions>;\n findByTestId: FindByQuery<TextMatch, ByTestIdOptions>;\n findAllByTestId: FindAllByQuery<TextMatch, ByTestIdOptions>;\n};\n\nexport const bindByTestIdQueries = (instance: TestInstance): 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":";;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AASA,IAAAE,YAAA,GAAAF,OAAA;AAKA,MAAMG,WAAW,GAAGA,CAACC,QAAsB,EAAEC,MAAiB,EAAEC,OAAyB,GAAG,CAAC,CAAC,KAAK;EACjG,MAAM;IAAEC,KAAK;IAAEC;EAAW,CAAC,GAAGF,OAAO;EACrC,OAAO,IAAAG,gBAAO,EAACJ,MAAM,EAAED,QAAQ,CAACM,KAAK,CAACC,MAAM,EAAEH,UAAU,EAAED,KAAK,CAAC;AAClE,CAAC;AAED,MAAMK,gBAAgB,GAAIR,QAAsB,IAC9C,SAASS,kBAAkBA,CAACR,MAAM,EAAES,YAAY,EAAE;EAChD,OAAO,IAAAC,gBAAO,EAACX,QAAQ,EAAGY,IAAI,IAAKb,WAAW,CAACa,IAAI,EAAEX,MAAM,EAAES,YAAY,CAAC,EAAEA,YAAY,CAAC;AAC3F,CAAC;AAEH,MAAMG,gBAAgB,GAAIZ,MAAiB,IACzC,wCAAwCa,MAAM,CAACb,MAAM,CAAC,EAAE;AAC1D,MAAMc,eAAe,GAAId,MAAiB,IACxC,0CAA0Ca,MAAM,CAACb,MAAM,CAAC,EAAE;AAE5D,MAAM;EAAEe,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7Ed,gBAAgB,EAChBO,eAAe,EACfF,gBACF,CAAC;AAWM,MAAMU,mBAAmB,GAAIvB,QAAsB,KAAuB;EAC/EwB,WAAW,EAAER,KAAK,CAAChB,QAAQ,CAAC;EAC5ByB,cAAc,EAAER,QAAQ,CAACjB,QAAQ,CAAC;EAClC0B,aAAa,EAAER,OAAO,CAAClB,QAAQ,CAAC;EAChCQ,gBAAgB,EAAEW,UAAU,CAACnB,QAAQ,CAAC;EACtC2B,YAAY,EAAEP,MAAM,CAACpB,QAAQ,CAAC;EAC9B4B,eAAe,EAAEP,SAAS,CAACrB,QAAQ;AACrC,CAAC,CAAC;AAAC6B,OAAA,CAAAN,mBAAA,GAAAA,mBAAA","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import type { HostElement } from 'test-renderer';
1
+ import type { TestInstance } from 'test-renderer';
2
2
  import type { TextMatch, TextMatchOptions } from '../matches';
3
3
  import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './make-queries';
4
4
  import type { CommonQueryOptions } from './options';
@@ -11,5 +11,5 @@ export type ByTextQueries = {
11
11
  findByText: FindByQuery<TextMatch, ByTextOptions>;
12
12
  findAllByText: FindAllByQuery<TextMatch, ByTextOptions>;
13
13
  };
14
- export declare const bindByTextQueries: (element: HostElement) => ByTextQueries;
14
+ export declare const bindByTextQueries: (instance: TestInstance) => ByTextQueries;
15
15
  export {};
@@ -8,8 +8,8 @@ var _findAll = require("../helpers/find-all");
8
8
  var _hostComponentNames = require("../helpers/host-component-names");
9
9
  var _matchTextContent = require("../helpers/matchers/match-text-content");
10
10
  var _makeQueries = require("./make-queries");
11
- const queryAllByText = element => function queryAllByTextFn(text, options = {}) {
12
- return (0, _findAll.findAll)(element, node => (0, _hostComponentNames.isHostText)(node) && (0, _matchTextContent.matchTextContent)(node, text, options), {
11
+ const queryAllByText = instance => function queryAllByTextFn(text, options = {}) {
12
+ return (0, _findAll.findAll)(instance, item => (0, _hostComponentNames.isHostText)(item) && (0, _matchTextContent.matchTextContent)(item, text, options), {
13
13
  ...options,
14
14
  matchDeepestOnly: true
15
15
  });
@@ -24,13 +24,13 @@ const {
24
24
  findBy,
25
25
  findAllBy
26
26
  } = (0, _makeQueries.makeQueries)(queryAllByText, getMissingError, getMultipleError);
27
- const bindByTextQueries = element => ({
28
- getByText: getBy(element),
29
- getAllByText: getAllBy(element),
30
- queryByText: queryBy(element),
31
- queryAllByText: queryAllBy(element),
32
- findByText: findBy(element),
33
- findAllByText: findAllBy(element)
27
+ const bindByTextQueries = instance => ({
28
+ getByText: getBy(instance),
29
+ getAllByText: getAllBy(instance),
30
+ queryByText: queryBy(instance),
31
+ queryAllByText: queryAllBy(instance),
32
+ findByText: findBy(instance),
33
+ findAllByText: findAllBy(instance)
34
34
  });
35
35
  exports.bindByTextQueries = bindByTextQueries;
36
36
  //# sourceMappingURL=text.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"text.js","names":["_findAll","require","_hostComponentNames","_matchTextContent","_makeQueries","queryAllByText","element","queryAllByTextFn","text","options","findAll","node","isHostText","matchTextContent","matchDeepestOnly","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTextQueries","getByText","getAllByText","queryByText","findByText","findAllByText","exports"],"sources":["../../src/queries/text.ts"],"sourcesContent":["import type { HostElement } from 'test-renderer';\n\nimport { findAll } from '../helpers/find-all';\nimport { isHostText } from '../helpers/host-component-names';\nimport { matchTextContent } from '../helpers/matchers/match-text-content';\nimport type { TextMatch, TextMatchOptions } from '../matches';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './make-queries';\nimport { makeQueries } from './make-queries';\nimport type { CommonQueryOptions } from './options';\n\ntype ByTextOptions = CommonQueryOptions & TextMatchOptions;\n\nconst queryAllByText = (element: HostElement): QueryAllByQuery<TextMatch, ByTextOptions> =>\n function queryAllByTextFn(text, options = {}) {\n return findAll(element, (node) => isHostText(node) && matchTextContent(node, text, options), {\n ...options,\n matchDeepestOnly: true,\n });\n };\n\nconst getMultipleError = (text: TextMatch) => `Found multiple elements with text: ${String(text)}`;\n\nconst getMissingError = (text: TextMatch) => `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, ByTextOptions>;\n getAllByText: GetAllByQuery<TextMatch, ByTextOptions>;\n queryByText: QueryByQuery<TextMatch, ByTextOptions>;\n queryAllByText: QueryAllByQuery<TextMatch, ByTextOptions>;\n findByText: FindByQuery<TextMatch, ByTextOptions>;\n findAllByText: FindAllByQuery<TextMatch, ByTextOptions>;\n};\n\nexport const bindByTextQueries = (element: HostElement): ByTextQueries => ({\n getByText: getBy(element),\n getAllByText: getAllBy(element),\n queryByText: queryBy(element),\n queryAllByText: queryAllBy(element),\n findByText: findBy(element),\n findAllByText: findAllBy(element),\n});\n"],"mappings":";;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AAUA,IAAAG,YAAA,GAAAH,OAAA;AAKA,MAAMI,cAAc,GAAIC,OAAoB,IAC1C,SAASC,gBAAgBA,CAACC,IAAI,EAAEC,OAAO,GAAG,CAAC,CAAC,EAAE;EAC5C,OAAO,IAAAC,gBAAO,EAACJ,OAAO,EAAGK,IAAI,IAAK,IAAAC,8BAAU,EAACD,IAAI,CAAC,IAAI,IAAAE,kCAAgB,EAACF,IAAI,EAAEH,IAAI,EAAEC,OAAO,CAAC,EAAE;IAC3F,GAAGA,OAAO;IACVK,gBAAgB,EAAE;EACpB,CAAC,CAAC;AACJ,CAAC;AAEH,MAAMC,gBAAgB,GAAIP,IAAe,IAAK,sCAAsCQ,MAAM,CAACR,IAAI,CAAC,EAAE;AAElG,MAAMS,eAAe,GAAIT,IAAe,IAAK,wCAAwCQ,MAAM,CAACR,IAAI,CAAC,EAAE;AAEnG,MAAM;EAAEU,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7EnB,cAAc,EACdY,eAAe,EACfF,gBACF,CAAC;AAWM,MAAMU,iBAAiB,GAAInB,OAAoB,KAAqB;EACzEoB,SAAS,EAAER,KAAK,CAACZ,OAAO,CAAC;EACzBqB,YAAY,EAAER,QAAQ,CAACb,OAAO,CAAC;EAC/BsB,WAAW,EAAER,OAAO,CAACd,OAAO,CAAC;EAC7BD,cAAc,EAAEgB,UAAU,CAACf,OAAO,CAAC;EACnCuB,UAAU,EAAEP,MAAM,CAAChB,OAAO,CAAC;EAC3BwB,aAAa,EAAEP,SAAS,CAACjB,OAAO;AAClC,CAAC,CAAC;AAACyB,OAAA,CAAAN,iBAAA,GAAAA,iBAAA","ignoreList":[]}
1
+ {"version":3,"file":"text.js","names":["_findAll","require","_hostComponentNames","_matchTextContent","_makeQueries","queryAllByText","instance","queryAllByTextFn","text","options","findAll","item","isHostText","matchTextContent","matchDeepestOnly","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTextQueries","getByText","getAllByText","queryByText","findByText","findAllByText","exports"],"sources":["../../src/queries/text.ts"],"sourcesContent":["import type { TestInstance } from 'test-renderer';\n\nimport { findAll } from '../helpers/find-all';\nimport { isHostText } from '../helpers/host-component-names';\nimport { matchTextContent } from '../helpers/matchers/match-text-content';\nimport type { TextMatch, TextMatchOptions } from '../matches';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './make-queries';\nimport { makeQueries } from './make-queries';\nimport type { CommonQueryOptions } from './options';\n\ntype ByTextOptions = CommonQueryOptions & TextMatchOptions;\n\nconst queryAllByText = (instance: TestInstance): QueryAllByQuery<TextMatch, ByTextOptions> =>\n function queryAllByTextFn(text, options = {}) {\n return findAll(instance, (item) => isHostText(item) && matchTextContent(item, text, options), {\n ...options,\n matchDeepestOnly: true,\n });\n };\n\nconst getMultipleError = (text: TextMatch) => `Found multiple elements with text: ${String(text)}`;\n\nconst getMissingError = (text: TextMatch) => `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, ByTextOptions>;\n getAllByText: GetAllByQuery<TextMatch, ByTextOptions>;\n queryByText: QueryByQuery<TextMatch, ByTextOptions>;\n queryAllByText: QueryAllByQuery<TextMatch, ByTextOptions>;\n findByText: FindByQuery<TextMatch, ByTextOptions>;\n findAllByText: FindAllByQuery<TextMatch, ByTextOptions>;\n};\n\nexport const bindByTextQueries = (instance: TestInstance): 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":";;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AAUA,IAAAG,YAAA,GAAAH,OAAA;AAKA,MAAMI,cAAc,GAAIC,QAAsB,IAC5C,SAASC,gBAAgBA,CAACC,IAAI,EAAEC,OAAO,GAAG,CAAC,CAAC,EAAE;EAC5C,OAAO,IAAAC,gBAAO,EAACJ,QAAQ,EAAGK,IAAI,IAAK,IAAAC,8BAAU,EAACD,IAAI,CAAC,IAAI,IAAAE,kCAAgB,EAACF,IAAI,EAAEH,IAAI,EAAEC,OAAO,CAAC,EAAE;IAC5F,GAAGA,OAAO;IACVK,gBAAgB,EAAE;EACpB,CAAC,CAAC;AACJ,CAAC;AAEH,MAAMC,gBAAgB,GAAIP,IAAe,IAAK,sCAAsCQ,MAAM,CAACR,IAAI,CAAC,EAAE;AAElG,MAAMS,eAAe,GAAIT,IAAe,IAAK,wCAAwCQ,MAAM,CAACR,IAAI,CAAC,EAAE;AAEnG,MAAM;EAAEU,KAAK;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAU,CAAC,GAAG,IAAAC,wBAAW,EAC7EnB,cAAc,EACdY,eAAe,EACfF,gBACF,CAAC;AAWM,MAAMU,iBAAiB,GAAInB,QAAsB,KAAqB;EAC3EoB,SAAS,EAAER,KAAK,CAACZ,QAAQ,CAAC;EAC1BqB,YAAY,EAAER,QAAQ,CAACb,QAAQ,CAAC;EAChCsB,WAAW,EAAER,OAAO,CAACd,QAAQ,CAAC;EAC9BD,cAAc,EAAEgB,UAAU,CAACf,QAAQ,CAAC;EACpCuB,UAAU,EAAEP,MAAM,CAAChB,QAAQ,CAAC;EAC5BwB,aAAa,EAAEP,SAAS,CAACjB,QAAQ;AACnC,CAAC,CAAC;AAACyB,OAAA,CAAAN,iBAAA,GAAAA,iBAAA","ignoreList":[]}
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.renderHook = renderHook;
7
7
  var React = _interopRequireWildcard(require("react"));
8
+ var _validateOptions = require("./helpers/validate-options");
8
9
  var _render = require("./render");
9
10
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
10
11
  async function renderHook(hookToRender, options) {
@@ -20,8 +21,13 @@ async function renderHook(hookToRender, options) {
20
21
  }
21
22
  const {
22
23
  initialProps,
23
- ...renderOptions
24
+ wrapper,
25
+ ...rest
24
26
  } = options ?? {};
27
+ (0, _validateOptions.validateOptions)('renderHook', rest, renderHook);
28
+ const renderOptions = wrapper ? {
29
+ wrapper
30
+ } : {};
25
31
  const {
26
32
  rerender: rerenderComponent,
27
33
  unmount
@@ -1 +1 @@
1
- {"version":3,"file":"render-hook.js","names":["React","_interopRequireWildcard","require","_render","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","renderHook","hookToRender","options","result","createRef","HookContainer","hookProps","renderResult","useEffect","current","initialProps","renderOptions","rerender","rerenderComponent","unmount","render","createElement"],"sources":["../src/render-hook.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { render } from './render';\nimport type { RefObject } from './types';\n\nexport type RenderHookResult<Result, Props> = {\n result: RefObject<Result>;\n rerender: (props: Props) => Promise<void>;\n unmount: () => Promise<void>;\n};\n\nexport type RenderHookOptions<Props> = {\n /**\n * The initial props to pass to the hook.\n */\n initialProps?: Props;\n\n /**\n * Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating\n * reusable custom render functions for common data providers.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wrapper?: React.ComponentType<any>;\n};\n\nexport async function renderHook<Result, Props>(\n hookToRender: (props: Props) => Result,\n options?: RenderHookOptions<NoInfer<Props>>,\n): Promise<RenderHookResult<Result, Props>> {\n const result = React.createRef<Result>() as RefObject<Result>;\n\n function HookContainer({ hookProps }: { hookProps: Props }) {\n const renderResult = hookToRender(hookProps);\n React.useEffect(() => {\n result.current = renderResult;\n });\n\n return null;\n }\n\n const { initialProps, ...renderOptions } = options ?? {};\n const { rerender: rerenderComponent, unmount } = await render(\n // @ts-expect-error since option can be undefined, initialProps can be undefined when it shouldn't be\n <HookContainer hookProps={initialProps} />,\n renderOptions,\n );\n\n return {\n result: result,\n rerender: (hookProps: Props) => rerenderComponent(<HookContainer hookProps={hookProps} />),\n unmount,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAAkC,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,G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,MAAM;IACdS,QAAQ,EAAGN,SAAgB,IAAKO,iBAAiB,cAACpC,KAAA,CAAAuC,aAAA,CAACX,aAAa;MAACC,SAAS,EAAEA;IAAU,CAAE,CAAC,CAAC;IAC1FQ;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"render-hook.js","names":["React","_interopRequireWildcard","require","_validateOptions","_render","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","renderHook","hookToRender","options","result","createRef","HookContainer","hookProps","renderResult","useEffect","current","initialProps","wrapper","rest","validateOptions","renderOptions","rerender","rerenderComponent","unmount","render","createElement"],"sources":["../src/render-hook.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { validateOptions } from './helpers/validate-options';\nimport { render } from './render';\nimport type { RefObject } from './types';\n\nexport type RenderHookResult<Result, Props> = {\n result: RefObject<Result>;\n rerender: (props: Props) => Promise<void>;\n unmount: () => Promise<void>;\n};\n\nexport type RenderHookOptions<Props> = {\n /**\n * The initial props to pass to the hook.\n */\n initialProps?: Props;\n\n /**\n * Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating\n * reusable custom render functions for common data providers.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wrapper?: React.ComponentType<any>;\n};\n\nexport async function renderHook<Result, Props>(\n hookToRender: (props: Props) => Result,\n options?: RenderHookOptions<NoInfer<Props>>,\n): Promise<RenderHookResult<Result, Props>> {\n const result = React.createRef<Result>() as RefObject<Result>;\n\n function HookContainer({ hookProps }: { hookProps: Props }) {\n const renderResult = hookToRender(hookProps);\n React.useEffect(() => {\n result.current = renderResult;\n });\n\n return null;\n }\n\n const { initialProps, wrapper, ...rest } = options ?? {};\n validateOptions('renderHook', rest, renderHook);\n const renderOptions = wrapper ? { wrapper } : {};\n const { rerender: rerenderComponent, unmount } = await render(\n // @ts-expect-error since option can be undefined, initialProps can be undefined when it shouldn't be\n <HookContainer hookProps={initial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EACD;EAC1C,MAAMC,MAAM,gBAAG3B,KAAK,CAAC4B,SAAS,CAAS,CAAsB;EAE7D,SAASC,aAAaA,CAAC;IAAEC;EAAgC,CAAC,EAAE;IAC1D,MAAMC,YAAY,GAAGN,YAAY,CAACK,SAAS,CAAC;IAC5C9B,KAAK,CAACgC,SAAS,CAAC,MAAM;MACpBL,MAAM,CAACM,OAAO,GAAGF,YAAY;IAC/B,CAAC,CAAC;IAEF,OAAO,IAAI;EACb;EAEA,MAAM;IAAEG,YAAY;IAAEC,OAAO;IAAE,GAAGC;EAAK,CAAC,GAAGV,OAAO,IAAI,CAAC,CAAC;EACxD,IAAAW,gCAAe,EAAC,YAAY,EAAED,IAAI,EAAEZ,UAAU,CAAC;EAC/C,MAAMc,aAAa,GAAGH,OAAO,GAAG;IAAEA;EAAQ,CAAC,GAAG,CAAC,CAAC;EAChD,MAAM;IAAEI,QAAQ,EAAEC,iBAAiB;IAAEC;EAAQ,CAAC,GAAG,MAAM,IAAAC,cAAM;EAAA;EAC3D;EACA1C,KAAA,CAAA2C,aAAA,CAACd,aAAa;IAACC,SAAS,EAAEI;EAAa,CAAE,CAAC,EAC1CI,aACF,CAAC;EAED,OAAO;IACLX,MAAM,EAAEA,MAAM;IACdY,QAAQ,EAAGT,SAAgB,IAAKU,iBAAiB,cAACxC,KAAA,CAAA2C,aAAA,CAACd,aAAa;MAACC,SAAS,EAAEA;IAAU,CAAE,CAAC,CAAC;IAC1FW;EACF,CAAC;AACH","ignoreList":[]}
package/build/render.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { type HostElement, type JsonElement } from 'test-renderer';
2
+ import { type JsonElement, type TestInstance } from 'test-renderer';
3
3
  import type { DebugOptions } from './helpers/debug';
4
4
  export interface RenderOptions {
5
5
  /**
@@ -7,11 +7,10 @@ export interface RenderOptions {
7
7
  * reusable custom render functions for common data providers.
8
8
  */
9
9
  wrapper?: React.ComponentType<any>;
10
- createNodeMock?: (element: React.ReactElement) => object;
11
10
  }
12
11
  export type RenderResult = Awaited<ReturnType<typeof render>>;
13
12
  /**
14
- * Renders test component deeply using React Test Renderer and exposes helpers
13
+ * Renders test component deeply using Test Renderer and exposes helpers
15
14
  * to assert on the output.
16
15
  */
17
16
  export declare function render<T>(element: React.ReactElement<T>, options?: RenderOptions): Promise<{
@@ -19,8 +18,8 @@ export declare function render<T>(element: React.ReactElement<T>, options?: Rend
19
18
  unmount: () => Promise<void>;
20
19
  toJSON: () => JsonElement | null;
21
20
  debug: DebugFunction;
22
- container: HostElement;
23
- root: HostElement | null;
21
+ container: TestInstance;
22
+ root: TestInstance | null;
24
23
  getByRole: import("./queries/make-queries").GetByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
25
24
  getAllByRole: import("./queries/make-queries").GetAllByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
26
25
  queryByRole: import("./queries/make-queries").QueryByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
package/build/render.js CHANGED
@@ -11,22 +11,29 @@ var _cleanup = require("./cleanup");
11
11
  var _config = require("./config");
12
12
  var _debug = require("./helpers/debug");
13
13
  var _hostComponentNames = require("./helpers/host-component-names");
14
+ var _validateOptions = require("./helpers/validate-options");
14
15
  var _screen = require("./screen");
15
16
  var _within = require("./within");
16
17
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
17
18
  /**
18
- * Renders test component deeply using React Test Renderer and exposes helpers
19
+ * Renders test component deeply using Test Renderer and exposes helpers
19
20
  * to assert on the output.
20
21
  */
21
22
  async function render(element, options = {}) {
22
23
  const {
23
24
  wrapper: Wrapper,
24
- createNodeMock
25
+ ...rest
25
26
  } = options || {};
27
+ (0, _validateOptions.validateOptions)('render', rest, render);
26
28
  const rendererOptions = {
27
29
  textComponentTypes: _hostComponentNames.HOST_TEXT_NAMES,
28
30
  publicTextComponentTypes: ['Text'],
29
- createNodeMock
31
+ transformHiddenInstanceProps: ({
32
+ props
33
+ }) => ({
34
+ ...props,
35
+ style: withHiddenStyle(props.style)
36
+ })
30
37
  };
31
38
  const wrap = element => Wrapper ? /*#__PURE__*/React.createElement(Wrapper, null, element) : element;
32
39
  const renderer = (0, _testRenderer.createRoot)(rendererOptions);
@@ -46,18 +53,17 @@ async function render(element, options = {}) {
46
53
  };
47
54
  const toJSON = () => {
48
55
  const json = renderer.container.toJSON();
49
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
50
56
  if (json?.children.length === 0) {
51
57
  return null;
52
58
  }
53
- if (json?.children?.length === 1 && typeof json.children[0] !== 'string') {
59
+ if (json?.children.length === 1 && typeof json.children[0] !== 'string') {
54
60
  return json.children[0];
55
61
  }
56
62
  return json;
57
63
  };
58
64
  (0, _cleanup.addToCleanupQueue)(unmount);
59
65
  const result = {
60
- ...(0, _within.getQueriesForElement)(renderer.container),
66
+ ...(0, _within.getQueriesForInstance)(renderer.container),
61
67
  rerender,
62
68
  unmount,
63
69
  toJSON,
@@ -93,4 +99,14 @@ function makeDebug(renderer) {
93
99
  }
94
100
  return debugImpl;
95
101
  }
102
+ function withHiddenStyle(style) {
103
+ if (style == null) {
104
+ return {
105
+ display: 'none'
106
+ };
107
+ }
108
+ return [style, {
109
+ display: 'none'
110
+ }];
111
+ }
96
112
  //# sourceMappingURL=render.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"render.js","names":["React","_interopRequireWildcard","require","_testRenderer","_act","_cleanup","_config","_debug","_hostComponentNames","_screen","_within","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","render","element","options","wrapper","Wrapper","createNodeMock","rendererOptions","textComponentTypes","HOST_TEXT_NAMES","publicTextComponentTypes","wrap","createElement","renderer","createRoot","act","container","rerender","component","unmount","toJSON","json","children","length","addToCleanupQueue","result","getQueriesForElement","debug","makeDebug","root","firstChild","Error","setRenderResult","debugImpl","defaultDebugOptions","getConfig","debugOptions"],"sources":["../src/render.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n createRoot,\n type HostElement,\n type JsonElement,\n type Root,\n type RootOptions,\n} from 'test-renderer';\n\nimport { act } from './act';\nimport { addToCleanupQueue } from './cleanup';\nimport { getConfig } from './config';\nimport type { DebugOptions } from './helpers/debug';\nimport { debug } from './helpers/debug';\nimport { HOST_TEXT_NAMES } from './helpers/host-component-names';\nimport { setRenderResult } from './screen';\nimport { getQueriesForElement } from './within';\n\nexport interface RenderOptions {\n /**\n * Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating\n * reusable custom render functions for common data providers.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wrapper?: React.ComponentType<any>;\n\n createNodeMock?: (element: React.ReactElement) => object;\n}\n\nexport type RenderResult = Awaited<ReturnType<typeof render>>;\n\n/**\n * Renders test component deeply using React Test Renderer and exposes helpers\n * to assert on the output.\n */\nexport async function render<T>(element: React.ReactElement<T>, options: RenderOptions = {}) {\n const { wrapper: Wrapper, createNodeMock } = options || {};\n\n const rendererOptions: RootOptions = {\n textComponentTypes: HOST_TEXT_NAMES,\n publicTextComponentTypes: ['Text'],\n createNodeMock,\n };\n\n const wrap = (element: React.ReactElement) => (Wrapper ? <Wrapper>{element}</Wrapper> : element);\n const renderer = createRoot(rendererOptions);\n\n await act(() => {\n renderer.render(wrap(element));\n });\n\n const container = renderer.container;\n\n const rerender = async (component: React.ReactElement) => {\n await act(() => {\n renderer.render(wrap(component));\n });\n };\n\n const unmount = async () => {\n await act(() => {\n renderer.unmount();\n });\n };\n\n const toJSON = (): JsonElement | null => {\n const json = renderer.container.toJSON();\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (json?.children!.length === 0) {\n return null;\n }\n\n if (json?.children?.length === 1 && typeof json.children[0] !== 'string') {\n return json.children[0];\n }\n\n return json;\n };\n\n addToCleanupQueue(unmount);\n\n const result = {\n ...getQueriesForElement(renderer.container),\n rerender,\n unmount,\n toJSON,\n debug: makeDebug(renderer),\n get container(): HostElement {\n return renderer.container;\n },\n get root(): HostElement | null {\n const firstChild = container.children[0];\n if (typeof firstChild === 'string') {\n /* istanbul ignore next */\n throw new Error(\n 'Invariant Violation: Root element must be a host element. Detected attempt to render a string within the root element.',\n );\n }\n\n return firstChild;\n },\n };\n\n setRenderResult(result);\n\n return result;\n}\n\nexport type DebugFunction = (options?: DebugOptions) => void;\n\nfunction makeDebug(renderer: Root): DebugFunction {\n function debugImpl(options?: DebugOptions) {\n const { defaultDebugOptions } = getConfig();\n const debugOptions = { ...defaultDebugOptions, ...options };\n const json = renderer.container.toJSON();\n if (json) {\n return debug(json, debugOptions);\n }\n }\n return debugImpl;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAQA,IAAAE,IAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,mBAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AAAgD,SAAAD,wBAAAU,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAZ,uBAAA,YAAAA,CAAAU,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAA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Ia,IAAIA,CAAA,EAAuB;MAC7B,MAAMC,UAAU,GAAGd,SAAS,CAACM,QAAQ,CAAC,CAAC,CAAC;MACxC,IAAI,OAAOQ,UAAU,KAAK,QAAQ,EAAE;QAClC;QACA,MAAM,IAAIC,KAAK,CACb,wHACF,CAAC;MACH;MAEA,OAAOD,UAAU;IACnB;EACF,CAAC;EAED,IAAAE,uBAAe,EAACP,MAAM,CAAC;EAEvB,OAAOA,MAAM;AACf;AAIA,SAASG,SAASA,CAACf,QAAc,EAAiB;EAChD,SAASoB,SAASA,CAAC9B,OAAsB,EAAE;IACzC,MAAM;MAAE+B;IAAoB,CAAC,GAAG,IAAAC,iBAAS,EAAC,CAAC;IAC3C,MAAMC,YAAY,GAAG;MAAE,GAAGF,mBAAmB;MAAE,GAAG/B;IAAQ,CAAC;IAC3D,MAAMkB,IAAI,GAAGR,QAAQ,CAACG,SAAS,CAACI,MAAM,CAAC,CAAC;IACxC,IAAIC,IAAI,EAAE;MACR,OAAO,IAAAM,YAAK,EAACN,IAAI,EAAEe,YAAY,CAAC;IAClC;EACF;EACA,OAAOH,SAAS;AAClB","ignoreList":[]}
1
+ {"version":3,"file":"render.js","names":["React","_interopRequireWildcard","require","_testRenderer","_act","_cleanup","_config","_debug","_hostComponentNames","_validateOptions","_screen","_within","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","render","element","options","wrapper","Wrapper","rest","validateOptions","rendererOptions","textComponentTypes","HOST_TEXT_NAMES","publicTextComponentTypes","transformHiddenInstanceProps","props","style","withHiddenStyle","wrap","createElement","renderer","createRoot","act","container","rerender","component","unmount","toJSON","json","children","length","addToCleanupQueue","result","getQueriesForInstance","debug","makeDebug","root","firstChild","Error","setRenderResult","debugImpl","defaultDebugOptions","getConfig","debugOptions","display"],"sources":["../src/render.tsx"],"sourcesContent":["import * as React from 'react';\nimport type { StyleProp } from 'react-native';\nimport {\n createRoot,\n type JsonElement,\n type Root,\n type RootOptions,\n type TestInstance,\n} from 'test-renderer';\n\nimport { act } from './act';\nimport { addToCleanupQueue } from './cleanup';\nimport { getConfig } from './config';\nimport type { DebugOptions } from './helpers/debug';\nimport { debug } from './helpers/debug';\nimport { HOST_TEXT_NAMES } from './helpers/host-component-names';\nimport { validateOptions } from './helpers/validate-options';\nimport { setRenderResult } from './screen';\nimport { getQueriesForInstance } from './within';\n\nexport interface RenderOptions {\n /**\n * Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating\n * reusable custom render functions for common data providers.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wrapper?: React.ComponentType<any>;\n}\n\nexport type RenderResult = Awaited<ReturnType<typeof render>>;\n\n/**\n * Renders test component deeply using Test Renderer and exposes helpers\n * to assert on the output.\n */\nexport async function render<T>(element: React.ReactElement<T>, options: RenderOptions = {}) {\n const { wrapper: Wrapper, ...rest } = options || {};\n validateOptions('render', rest, render);\n\n const rendererOptions: RootOptions = {\n textComponentTypes: HOST_TEXT_NAMES,\n publicTextComponentTypes: ['Text'],\n transformHiddenInstanceProps: ({ props }) => ({\n ...props,\n style: withHiddenStyle(props.style as StyleProp<StyleLike>),\n }),\n };\n\n const wrap = (element: React.ReactElement) => (Wrapper ? <Wrapper>{element}</Wrapper> : element);\n const renderer = createRoot(rendererOptions);\n\n await act(() => {\n renderer.render(wrap(element));\n });\n\n const container = renderer.container;\n\n const rerender = async (component: React.ReactElement) => {\n await act(() => {\n renderer.render(wrap(component));\n });\n };\n\n const unmount = async () => {\n await act(() => {\n renderer.unmount();\n });\n };\n\n const toJSON = (): JsonElement | null => {\n const json = renderer.container.toJSON();\n if (json?.children.length === 0) {\n return null;\n }\n\n if (json?.children.length === 1 && typeof json.children[0] !== 'string') {\n return json.children[0];\n }\n\n return json;\n };\n\n addToCleanupQueue(unmount);\n\n const result = {\n ...getQueriesForInstance(renderer.container),\n rerender,\n unmount,\n toJSON,\n debug: makeDebug(renderer),\n get container(): TestInstance {\n return renderer.container;\n },\n get root(): TestInstance | null {\n const firstChild = container.children[0];\n if (typeof firstChild === 'string') {\n /* istanbul ignore next */\n throw new Error(\n 'Invariant Violation: Root element must be a host element. Detected attempt to render a string within the root element.',\n );\n }\n\n return firstChild;\n },\n };\n\n setRenderResult(result);\n\n return result;\n}\n\nexport type DebugFunction = (options?: DebugOptions) => void;\n\nfunction makeDebug(renderer: Root): DebugFunction {\n function debugImpl(options?: DebugOptions) {\n const { defaultDebugOptions } = getConfig();\n const debugOptions = { ...defaultDebugOptions, ...options };\n const json = renderer.container.toJSON();\n if (json) {\n return debug(json, debugOptions);\n }\n }\n return debugImpl;\n}\n\ntype StyleLike = Record<string, unknown>;\n\nfunction withHiddenStyle(style: StyleProp<StyleLike>): StyleProp<StyleLike> {\n if (style == null) {\n return { display: 'none' };\n }\n\n return [style, { display: 'none' }];\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAQA,IAAAE,IAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,mBAAA,GAAAN,OAAA;AACA,IAAAO,gBAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AACA,IAAAS,OAAA,GAAAT,OAAA;AAAiD,SAAAD,wBAAAW,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAb,uBAAA,YAAAA,CAAAW,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,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,SAAS;IAC3B,CAAC;IACD,IAAIa,IAAIA,CAAA,EAAwB;MAC9B,MAAMC,UAAU,GAAGd,SAAS,CAACM,QAAQ,CAAC,CAAC,CAAC;MACxC,IAAI,OAAOQ,UAAU,KAAK,QAAQ,EAAE;QAClC;QACA,MAAM,IAAIC,KAAK,CACb,wHACF,CAAC;MACH;MAEA,OAAOD,UAAU;IACnB;EACF,CAAC;EAED,IAAAE,uBAAe,EAACP,MAAM,CAAC;EAEvB,OAAOA,MAAM;AACf;AAIA,SAASG,SAASA,CAACf,QAAc,EAAiB;EAChD,SAASoB,SAASA,CAACnC,OAAsB,EAAE;IACzC,MAAM;MAAEoC;IAAoB,CAAC,GAAG,IAAAC,iBAAS,EAAC,CAAC;IAC3C,MAAMC,YAAY,GAAG;MAAE,GAAGF,mBAAmB;MAAE,GAAGpC;IAAQ,CAAC;IAC3D,MAAMuB,IAAI,GAAGR,QAAQ,CAACG,SAAS,CAACI,MAAM,CAAC,CAAC;IACxC,IAAIC,IAAI,EAAE;MACR,OAAO,IAAAM,YAAK,EAACN,IAAI,EAAEe,YAAY,CAAC;IAClC;EACF;EACA,OAAOH,SAAS;AAClB;AAIA,SAASvB,eAAeA,CAACD,KAA2B,EAAwB;EAC1E,IAAIA,KAAK,IAAI,IAAI,EAAE;IACjB,OAAO;MAAE4B,OAAO,EAAE;IAAO,CAAC;EAC5B;EAEA,OAAO,CAAC5B,KAAK,EAAE;IAAE4B,OAAO,EAAE;EAAO,CAAC,CAAC;AACrC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"screen.js","names":["SCREEN_ERROR","notImplemented","Error","defaultScreen","isDetached","container","root","debug","rerender","unmount","toJSON","getByLabelText","getAllByLabelText","queryByLabelText","queryAllByLabelText","findByLabelText","findAllByLabelText","getByHintText","getAllByHintText","queryByHintText","queryAllByHintText","findByHintText","findAllByHintText","getByA11yHint","getAllByA11yHint","queryByA11yHint","queryAllByA11yHint","findByA11yHint","findAllByA11yHint","getByAccessibilityHint","getAllByAccessibilityHint","queryByAccessibilityHint","queryAllByAccessibilityHint","findByAccessibilityHint","findAllByAccessibilityHint","getByRole","getAllByRole","queryByRole","queryAllByRole","findByRole","findAllByRole","getByPlaceholderText","getAllByPlaceholderText","queryByPlaceholderText","queryAllByPlaceholderText","findByPlaceholderText","findAllByPlaceholderText","getByDisplayValue","getAllByDisplayValue","queryByDisplayValue","queryAllByDisplayValue","findByDisplayValue","findAllByDisplayValue","getByTestId","getAllByTestId","queryByTestId","queryAllByTestId","findByTestId","findAllByTestId","getByText","getAllByText","queryByText","queryAllByText","findByText","findAllByText","screen","exports","setRenderResult","renderResult","clearRenderResult"],"sources":["../src/screen.ts"],"sourcesContent":["import type { HostElement } from 'test-renderer';\n\nimport type { RenderResult } from './render';\n\nconst SCREEN_ERROR = '`render` function has not been called';\n\nconst notImplemented = () => {\n throw new Error(SCREEN_ERROR);\n};\n\ninterface Screen extends RenderResult {\n isDetached?: boolean;\n}\n\nconst defaultScreen: Screen = {\n isDetached: true,\n get container(): HostElement {\n throw new Error(SCREEN_ERROR);\n },\n get root(): HostElement | null {\n throw new Error(SCREEN_ERROR);\n },\n debug: notImplemented,\n rerender: notImplemented,\n unmount: notImplemented,\n toJSON: notImplemented,\n getByLabelText: notImplemented,\n getAllByLabelText: notImplemented,\n queryByLabelText: notImplemented,\n queryAllByLabelText: notImplemented,\n findByLabelText: notImplemented,\n findAllByLabelText: notImplemented,\n getByHintText: notImplemented,\n getAllByHintText: notImplemented,\n queryByHintText: notImplemented,\n queryAllByHintText: notImplemented,\n findByHintText: notImplemented,\n findAllByHintText: notImplemented,\n getByA11yHint: notImplemented,\n getAllByA11yHint: notImplemented,\n queryByA11yHint: notImplemented,\n queryAllByA11yHint: notImplemented,\n findByA11yHint: notImplemented,\n findAllByA11yHint: notImplemented,\n getByAccessibilityHint: notImplemented,\n getAllByAccessibilityHint: notImplemented,\n queryByAccessibilityHint: notImplemented,\n queryAllByAccessibilityHint: notImplemented,\n findByAccessibilityHint: notImplemented,\n findAllByAccessibilityHint: notImplemented,\n getByRole: notImplemented,\n getAllByRole: notImplemented,\n queryByRole: notImplemented,\n queryAllByRole: notImplemented,\n findByRole: notImplemented,\n findAllByRole: notImplemented,\n getByPlaceholderText: notImplemented,\n getAllByPlaceholderText: notImplemented,\n queryByPlaceholderText: notImplemented,\n queryAllByPlaceholderText: notImplemented,\n findByPlaceholderText: notImplemented,\n findAllByPlaceholderText: notImplemented,\n getByDisplayValue: notImplemented,\n getAllByDisplayValue: notImplemented,\n queryByDisplayValue: notImplemented,\n queryAllByDisplayValue: notImplemented,\n findByDisplayValue: notImplemented,\n findAllByDisplayValue: notImplemented,\n getByTestId: notImplemented,\n getAllByTestId: notImplemented,\n queryByTestId: notImplemented,\n queryAllByTestId: notImplemented,\n findByTestId: notImplemented,\n findAllByTestId: notImplemented,\n getByText: notImplemented,\n getAllByText: notImplemented,\n queryByText: notImplemented,\n queryAllByText: notImplemented,\n findByText: notImplemented,\n findAllByText: notImplemented,\n};\n\nexport let screen: Screen = defaultScreen;\n\nexport function setRenderResult(renderResult: RenderResult) {\n screen = renderResult;\n}\n\nexport function clearRenderResult() {\n screen = defaultScreen;\n}\n"],"mappings":";;;;;;;;AAIA,MAAMA,YAAY,GAAG,uCAAuC;AAE5D,MAAMC,cAAc,GAAGA,CAAA,KAAM;EAC3B,MAAM,IAAIC,KAAK,CAACF,YAAY,CAAC;AAC/B,CAAC;AAMD,MAAMG,aAAqB,GAAG;EAC5BC,UAAU,EAAE,IAAI;EAChB,IAAIC,SAASA,CAAA,EAAgB;IAC3B,MAAM,IAAIH,KAAK,CAACF,YAAY,CAAC;EAC/B,CAAC;EACD,IAAIM,IAAIA,CAAA,EAAuB;IAC7B,MAAM,IAAIJ,KAAK,CAACF,YAAY,CAAC;EAC/B,CAAC;EACDO,KAAK,EAAEN,cAAc;EACrBO,QAAQ,EAAEP,cAAc;EACxBQ,OAAO,EAAER,cAAc;EACvBS,MAAM,EAAET,cAAc;EACtBU,cAA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c;EAClCmD,qBAAqB,EAAEnD,cAAc;EACrCoD,WAAW,EAAEpD,cAAc;EAC3BqD,cAAc,EAAErD,cAAc;EAC9BsD,aAAa,EAAEtD,cAAc;EAC7BuD,gBAAgB,EAAEvD,cAAc;EAChCwD,YAAY,EAAExD,cAAc;EAC5ByD,eAAe,EAAEzD,cAAc;EAC/B0D,SAAS,EAAE1D,cAAc;EACzB2D,YAAY,EAAE3D,cAAc;EAC5B4D,WAAW,EAAE5D,cAAc;EAC3B6D,cAAc,EAAE7D,cAAc;EAC9B8D,UAAU,EAAE9D,cAAc;EAC1B+D,aAAa,EAAE/D;AACjB,CAAC;AAEM,IAAIgE,MAAc,GAAAC,OAAA,CAAAD,MAAA,GAAG9D,aAAa;AAElC,SAASgE,eAAeA,CAACC,YAA0B,EAAE;EAC1DF,OAAA,CAAAD,MAAA,GAAAA,MAAM,GAAGG,YAAY;AACvB;AAEO,SAASC,iBAAiBA,CAAA,EAAG;EAClCH,OAAA,CAAAD,MAAA,GAAAA,MAAM,GAAG9D,aAAa;AACxB","ignoreList":[]}
1
+ {"version":3,"file":"screen.js","names":["SCREEN_ERROR","notImplemented","Error","defaultScreen","isDetached","container","root","debug","rerender","unmount","toJSON","getByLabelText","getAllByLabelText","queryByLabelText","queryAllByLabelText","findByLabelText","findAllByLabelText","getByHintText","getAllByHintText","queryByHintText","queryAllByHintText","findByHintText","findAllByHintText","getByA11yHint","getAllByA11yHint","queryByA11yHint","queryAllByA11yHint","findByA11yHint","findAllByA11yHint","getByAccessibilityHint","getAllByAccessibilityHint","queryByAccessibilityHint","queryAllByAccessibilityHint","findByAccessibilityHint","findAllByAccessibilityHint","getByRole","getAllByRole","queryByRole","queryAllByRole","findByRole","findAllByRole","getByPlaceholderText","getAllByPlaceholderText","queryByPlaceholderText","queryAllByPlaceholderText","findByPlaceholderText","findAllByPlaceholderText","getByDisplayValue","getAllByDisplayValue","queryByDisplayValue","queryAllByDisplayValue","findByDisplayValue","findAllByDisplayValue","getByTestId","getAllByTestId","queryByTestId","queryAllByTestId","findByTestId","findAllByTestId","getByText","getAllByText","queryByText","queryAllByText","findByText","findAllByText","screen","exports","setRenderResult","renderResult","clearRenderResult"],"sources":["../src/screen.ts"],"sourcesContent":["import type { TestInstance } from 'test-renderer';\n\nimport type { RenderResult } from './render';\n\nconst SCREEN_ERROR = '`render` function has not been called';\n\nconst notImplemented = () => {\n throw new Error(SCREEN_ERROR);\n};\n\ninterface Screen extends RenderResult {\n isDetached?: boolean;\n}\n\nconst defaultScreen: Screen = {\n isDetached: true,\n get container(): TestInstance {\n throw new Error(SCREEN_ERROR);\n },\n get root(): TestInstance | null {\n throw new Error(SCREEN_ERROR);\n },\n debug: notImplemented,\n rerender: notImplemented,\n unmount: notImplemented,\n toJSON: notImplemented,\n getByLabelText: notImplemented,\n getAllByLabelText: notImplemented,\n queryByLabelText: notImplemented,\n queryAllByLabelText: notImplemented,\n findByLabelText: notImplemented,\n findAllByLabelText: notImplemented,\n getByHintText: notImplemented,\n getAllByHintText: notImplemented,\n queryByHintText: notImplemented,\n queryAllByHintText: notImplemented,\n findByHintText: notImplemented,\n findAllByHintText: notImplemented,\n getByA11yHint: notImplemented,\n getAllByA11yHint: notImplemented,\n queryByA11yHint: notImplemented,\n queryAllByA11yHint: notImplemented,\n findByA11yHint: notImplemented,\n findAllByA11yHint: notImplemented,\n getByAccessibilityHint: notImplemented,\n getAllByAccessibilityHint: notImplemented,\n queryByAccessibilityHint: notImplemented,\n queryAllByAccessibilityHint: notImplemented,\n findByAccessibilityHint: notImplemented,\n findAllByAccessibilityHint: notImplemented,\n getByRole: notImplemented,\n getAllByRole: notImplemented,\n queryByRole: notImplemented,\n queryAllByRole: notImplemented,\n findByRole: notImplemented,\n findAllByRole: notImplemented,\n getByPlaceholderText: notImplemented,\n getAllByPlaceholderText: notImplemented,\n queryByPlaceholderText: notImplemented,\n queryAllByPlaceholderText: notImplemented,\n findByPlaceholderText: notImplemented,\n findAllByPlaceholderText: notImplemented,\n getByDisplayValue: notImplemented,\n getAllByDisplayValue: notImplemented,\n queryByDisplayValue: notImplemented,\n queryAllByDisplayValue: notImplemented,\n findByDisplayValue: notImplemented,\n findAllByDisplayValue: notImplemented,\n getByTestId: notImplemented,\n getAllByTestId: notImplemented,\n queryByTestId: notImplemented,\n queryAllByTestId: notImplemented,\n findByTestId: notImplemented,\n findAllByTestId: notImplemented,\n getByText: notImplemented,\n getAllByText: notImplemented,\n queryByText: notImplemented,\n queryAllByText: notImplemented,\n findByText: notImplemented,\n findAllByText: notImplemented,\n};\n\nexport let screen: Screen = defaultScreen;\n\nexport function setRenderResult(renderResult: RenderResult) {\n screen = renderResult;\n}\n\nexport function clearRenderResult() {\n screen = defaultScreen;\n}\n"],"mappings":";;;;;;;;AAIA,MAAMA,YAAY,GAAG,uCAAuC;AAE5D,MAAMC,cAAc,GAAGA,CAAA,KAAM;EAC3B,MAAM,IAAIC,KAAK,CAACF,YAAY,CAAC;AAC/B,CAAC;AAMD,MAAMG,aAAqB,GAAG;EAC5BC,UAAU,EAAE,IAAI;EAChB,IAAIC,SAASA,CAAA,EAAiB;IAC5B,MAAM,IAAIH,KAAK,CAACF,YAAY,CAAC;EAC/B,CAAC;EACD,IAAIM,IAAIA,CAAA,EAAwB;IAC9B,MAAM,IAAIJ,KAAK,CAACF,YAAY,CAAC;EAC/B,CAAC;EACDO,KAAK,EAAEN,cAAc;EACrBO,QAAQ,EAAEP,cAAc;EACxBQ,OAAO,EAAER,cAAc;EACvBS,MAAM,EAAET,cAAc;EACtBU,cAAc,EAAEV,cAAc;EAC9BW,iBAAiB,EAAEX,cAAc;EACjCY,gBAAgB,EAAEZ,cAAc;EAChCa,mBAAmB,EAAEb,cAAc;EACnCc,eAAe,EAAEd,cAAc;EAC/Be,kBAAkB,EAAEf,cAAc;EAClCgB,aAAa,EAAEhB,cAAc;EAC7BiB,gBAAgB,EAAEjB,cAAc;EAChCkB,eAAe,EAAElB,cAAc;EAC/BmB,kBAAkB,EAAEnB,cAAc;EACl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EAAE5D,cAAc;EAC3B6D,cAAc,EAAE7D,cAAc;EAC9B8D,UAAU,EAAE9D,cAAc;EAC1B+D,aAAa,EAAE/D;AACjB,CAAC;AAEM,IAAIgE,MAAc,GAAAC,OAAA,CAAAD,MAAA,GAAG9D,aAAa;AAElC,SAASgE,eAAeA,CAACC,YAA0B,EAAE;EAC1DF,OAAA,CAAAD,MAAA,GAAAA,MAAM,GAAGG,YAAY;AACvB;AAEO,SAASC,iBAAiBA,CAAA,EAAG;EAClCH,OAAA,CAAAD,MAAA,GAAAA,MAAM,GAAG9D,aAAa;AACxB","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export declare const testGateReact19_2: jest.It;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.testGateReact19_2 = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
10
+ const testRendererVersion = require('test-renderer/package.json').version;
11
+ function isVersionAtLeast(versionString, targetMajor, targetMinor, targetPatch) {
12
+ const match = /^(\d+)\.(\d+)\.(\d+)/.exec(versionString);
13
+ if (!match) {
14
+ return false;
15
+ }
16
+ const major = Number(match[1]);
17
+ const minor = Number(match[2]);
18
+ const patch = Number(match[3]);
19
+ if (major !== targetMajor) {
20
+ return major > targetMajor;
21
+ }
22
+ if (minor !== targetMinor) {
23
+ return minor > targetMinor;
24
+ }
25
+ return patch >= targetPatch;
26
+ }
27
+ const testGateReact19_2 = exports.testGateReact19_2 = isVersionAtLeast(_react.default.version, 19, 2, 0) && isVersionAtLeast(testRendererVersion, 1, 2, 0) ? test : test.skip;
28
+ //# sourceMappingURL=react-version-gates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-version-gates.js","names":["_react","_interopRequireDefault","require","e","__esModule","default","testRendererVersion","version","isVersionAtLeast","versionString","targetMajor","targetMinor","targetPatch","match","exec","major","Number","minor","patch","testGateReact19_2","exports","React","test","skip"],"sources":["../../src/test-utils/react-version-gates.ts"],"sourcesContent":["import React from 'react';\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nconst testRendererVersion = require('test-renderer/package.json').version;\n\nfunction isVersionAtLeast(\n versionString: string,\n targetMajor: number,\n targetMinor: number,\n targetPatch: number,\n): boolean {\n const match = /^(\\d+)\\.(\\d+)\\.(\\d+)/.exec(versionString);\n\n if (!match) {\n return false;\n }\n\n const major = Number(match[1]);\n const minor = Number(match[2]);\n const patch = Number(match[3]);\n\n if (major !== targetMajor) {\n return major > targetMajor;\n }\n\n if (minor !== targetMinor) {\n return minor > targetMinor;\n }\n\n return patch >= targetPatch;\n}\n\nexport const testGateReact19_2 =\n isVersionAtLeast(React.version, 19, 2, 0) && isVersionAtLeast(testRendererVersion, 1, 2, 0)\n ? test\n : test.skip;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA0B,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAC1B;AACA,MAAMG,mBAAmB,GAAGJ,OAAO,CAAC,4BAA4B,CAAC,CAACK,OAAO;AAEzE,SAASC,gBAAgBA,CACvBC,aAAqB,EACrBC,WAAmB,EACnBC,WAAmB,EACnBC,WAAmB,EACV;EACT,MAAMC,KAAK,GAAG,sBAAsB,CAACC,IAAI,CAACL,aAAa,CAAC;EAExD,IAAI,CAACI,KAAK,EAAE;IACV,OAAO,KAAK;EACd;EAEA,MAAME,KAAK,GAAGC,MAAM,CAACH,KAAK,CAAC,CAAC,CAAC,CAAC;EAC9B,MAAMI,KAAK,GAAGD,MAAM,CAACH,KAAK,CAAC,CAAC,CAAC,CAAC;EAC9B,MAAMK,KAAK,GAAGF,MAAM,CAACH,KAAK,CAAC,CAAC,CAAC,CAAC;EAE9B,IAAIE,KAAK,KAAKL,WAAW,EAAE;IACzB,OAAOK,KAAK,GAAGL,WAAW;EAC5B;EAEA,IAAIO,KAAK,KAAKN,WAAW,EAAE;IACzB,OAAOM,KAAK,GAAGN,WAAW;EAC5B;EAEA,OAAOO,KAAK,IAAIN,WAAW;AAC7B;AAEO,MAAMO,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAC5BX,gBAAgB,CAACa,cAAK,CAACd,OAAO,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,IAAIC,gBAAgB,CAACF,mBAAmB,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GACvFgB,IAAI,GACJA,IAAI,CAACC,IAAI","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export type TimerType = 'real' | 'fake' | 'fake-legacy';
2
+ export declare function setupTimeType(type: TimerType): void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setupTimeType = setupTimeType;
7
+ function setupTimeType(type) {
8
+ if (type === 'fake-legacy') {
9
+ jest.useFakeTimers({
10
+ legacyFakeTimers: true
11
+ });
12
+ } else if (type === 'fake') {
13
+ jest.useFakeTimers({
14
+ legacyFakeTimers: false
15
+ });
16
+ } else {
17
+ jest.useRealTimers();
18
+ }
19
+ }
20
+ //# sourceMappingURL=timers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timers.js","names":["setupTimeType","type","jest","useFakeTimers","legacyFakeTimers","useRealTimers"],"sources":["../../src/test-utils/timers.ts"],"sourcesContent":["export type TimerType = 'real' | 'fake' | 'fake-legacy';\n\nexport function setupTimeType(type: TimerType): void {\n if (type === 'fake-legacy') {\n jest.useFakeTimers({ legacyFakeTimers: true });\n } else if (type === 'fake') {\n jest.useFakeTimers({ legacyFakeTimers: false });\n } else {\n jest.useRealTimers();\n }\n}\n"],"mappings":";;;;;;AAEO,SAASA,aAAaA,CAACC,IAAe,EAAQ;EACnD,IAAIA,IAAI,KAAK,aAAa,EAAE;IAC1BC,IAAI,CAACC,aAAa,CAAC;MAAEC,gBAAgB,EAAE;IAAK,CAAC,CAAC;EAChD,CAAC,MAAM,IAAIH,IAAI,KAAK,MAAM,EAAE;IAC1BC,IAAI,CAACC,aAAa,CAAC;MAAEC,gBAAgB,EAAE;IAAM,CAAC,CAAC;EACjD,CAAC,MAAM;IACLF,IAAI,CAACG,aAAa,CAAC,CAAC;EACtB;AACF","ignoreList":[]}
package/build/types.d.ts CHANGED
@@ -16,4 +16,11 @@ export interface Size {
16
16
  height: number;
17
17
  width: number;
18
18
  }
19
+ /**
20
+ * Range of text in a text input.
21
+ */
22
+ export interface TextRange {
23
+ start: number;
24
+ end: number;
25
+ }
19
26
  export type StringWithAutocomplete<T> = T | (string & {});
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/** `RefObject` type from React 19. */\nexport type RefObject<T> = {\n current: T;\n};\n\n/**\n * Location of an element.\n */\nexport interface Point {\n y: number;\n x: number;\n}\n\n/**\n * Size of an element.\n */\nexport interface Size {\n height: number;\n width: number;\n}\n\n// TS autocomplete trick\n// Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939\nexport type StringWithAutocomplete<T> = T | (string & {});\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/** `RefObject` type from React 19. */\nexport type RefObject<T> = {\n current: T;\n};\n\n/**\n * Location of an element.\n */\nexport interface Point {\n y: number;\n x: number;\n}\n\n/**\n * Size of an element.\n */\nexport interface Size {\n height: number;\n width: number;\n}\n\n/**\n * Range of text in a text input.\n */\nexport interface TextRange {\n start: number;\n end: number;\n}\n\n// TS autocomplete trick\n// Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939\nexport type StringWithAutocomplete<T> = T | (string & {});\n"],"mappings":"","ignoreList":[]}
@@ -1,3 +1,3 @@
1
- import type { HostElement } from 'test-renderer';
1
+ import type { TestInstance } from 'test-renderer';
2
2
  import type { UserEventInstance } from './setup';
3
- export declare function clear(this: UserEventInstance, element: HostElement): Promise<void>;
3
+ export declare function clear(this: UserEventInstance, instance: TestInstance): Promise<void>;