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

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 (126) hide show
  1. package/README.md +7 -11
  2. package/build/act.d.ts +2 -4
  3. package/build/act.js +4 -5
  4. package/build/act.js.map +1 -1
  5. package/build/cleanup.d.ts +3 -1
  6. package/build/cleanup.js +8 -0
  7. package/build/cleanup.js.map +1 -1
  8. package/build/event-handler.d.ts +2 -2
  9. package/build/event-handler.js +10 -10
  10. package/build/event-handler.js.map +1 -1
  11. package/build/fire-event.d.ts +8 -1
  12. package/build/fire-event.js +44 -28
  13. package/build/fire-event.js.map +1 -1
  14. package/build/helpers/accessibility.js +5 -2
  15. package/build/helpers/accessibility.js.map +1 -1
  16. package/build/helpers/component-tree.d.ts +8 -8
  17. package/build/helpers/component-tree.js +19 -16
  18. package/build/helpers/component-tree.js.map +1 -1
  19. package/build/helpers/debug.d.ts +1 -1
  20. package/build/helpers/debug.js +6 -7
  21. package/build/helpers/debug.js.map +1 -1
  22. package/build/helpers/find-all.js +7 -27
  23. package/build/helpers/find-all.js.map +1 -1
  24. package/build/helpers/format-element.d.ts +3 -3
  25. package/build/helpers/format-element.js +9 -9
  26. package/build/helpers/format-element.js.map +1 -1
  27. package/build/helpers/host-component-names.d.ts +0 -1
  28. package/build/helpers/host-component-names.js +7 -9
  29. package/build/helpers/host-component-names.js.map +1 -1
  30. package/build/helpers/logger.d.ts +22 -0
  31. package/build/helpers/logger.js +13 -8
  32. package/build/helpers/logger.js.map +1 -1
  33. package/build/helpers/pointer-events.js +9 -5
  34. package/build/helpers/pointer-events.js.map +1 -1
  35. package/build/helpers/wrap-async.d.ts +0 -1
  36. package/build/helpers/wrap-async.js +0 -1
  37. package/build/helpers/wrap-async.js.map +1 -1
  38. package/build/index.d.ts +0 -1
  39. package/build/index.flow.js +5 -4
  40. package/build/index.js +1 -12
  41. package/build/index.js.map +1 -1
  42. package/build/matchers/to-be-empty-element.js +6 -3
  43. package/build/matchers/to-be-empty-element.js.map +1 -1
  44. package/build/matchers/to-be-visible.js +3 -3
  45. package/build/matchers/to-be-visible.js.map +1 -1
  46. package/build/matchers/to-contain-element.js +1 -2
  47. package/build/matchers/to-contain-element.js.map +1 -1
  48. package/build/matchers/to-have-style.js +1 -1
  49. package/build/matchers/to-have-style.js.map +1 -1
  50. package/build/matchers/utils.js +3 -2
  51. package/build/matchers/utils.js.map +1 -1
  52. package/build/pure.d.ts +7 -5
  53. package/build/pure.js +30 -4
  54. package/build/pure.js.map +1 -1
  55. package/build/queries/display-value.d.ts +1 -1
  56. package/build/queries/display-value.js +9 -9
  57. package/build/queries/display-value.js.map +1 -1
  58. package/build/queries/hint-text.d.ts +1 -1
  59. package/build/queries/hint-text.js +9 -9
  60. package/build/queries/hint-text.js.map +1 -1
  61. package/build/queries/label-text.d.ts +1 -1
  62. package/build/queries/label-text.js +9 -9
  63. package/build/queries/label-text.js.map +1 -1
  64. package/build/queries/make-queries.d.ts +2 -2
  65. package/build/queries/make-queries.js +11 -11
  66. package/build/queries/make-queries.js.map +1 -1
  67. package/build/queries/placeholder-text.d.ts +1 -1
  68. package/build/queries/placeholder-text.js +9 -9
  69. package/build/queries/placeholder-text.js.map +1 -1
  70. package/build/queries/role.d.ts +2 -2
  71. package/build/queries/role.js +16 -9
  72. package/build/queries/role.js.map +1 -1
  73. package/build/queries/test-id.d.ts +1 -1
  74. package/build/queries/test-id.js +9 -9
  75. package/build/queries/test-id.js.map +1 -1
  76. package/build/queries/text.d.ts +1 -1
  77. package/build/queries/text.js +9 -9
  78. package/build/queries/text.js.map +1 -1
  79. package/build/react-versions.js +1 -2
  80. package/build/react-versions.js.map +1 -1
  81. package/build/render-act.d.ts +3 -0
  82. package/build/render-act.js +29 -0
  83. package/build/render-act.js.map +1 -0
  84. package/build/render-async.d.ts +83 -0
  85. package/build/render-async.js +96 -0
  86. package/build/render-async.js.map +1 -0
  87. package/build/render-hook.d.ts +9 -7
  88. package/build/render-hook.js +44 -14
  89. package/build/render-hook.js.map +1 -1
  90. package/build/render.d.ts +86 -17
  91. package/build/render.js +44 -27
  92. package/build/render.js.map +1 -1
  93. package/build/screen.js +7 -7
  94. package/build/screen.js.map +1 -1
  95. package/build/test-utils/console.d.ts +1 -0
  96. package/build/test-utils/console.js +17 -0
  97. package/build/test-utils/console.js.map +1 -0
  98. package/build/test-utils/json.d.ts +6 -0
  99. package/build/test-utils/json.js +33 -0
  100. package/build/test-utils/json.js.map +1 -0
  101. package/build/tsconfig.release.tsbuildinfo +1 -1
  102. package/build/types.d.ts +4 -0
  103. package/build/types.js.map +1 -1
  104. package/build/user-event/clear.js +4 -4
  105. package/build/user-event/clear.js.map +1 -1
  106. package/build/user-event/paste.js +8 -8
  107. package/build/user-event/paste.js.map +1 -1
  108. package/build/user-event/press/press.js +17 -10
  109. package/build/user-event/press/press.js.map +1 -1
  110. package/build/user-event/scroll/scroll-to.js +7 -7
  111. package/build/user-event/scroll/scroll-to.js.map +1 -1
  112. package/build/user-event/type/type.js +11 -11
  113. package/build/user-event/type/type.js.map +1 -1
  114. package/build/user-event/utils/dispatch-event.d.ts +1 -1
  115. package/build/user-event/utils/dispatch-event.js +4 -4
  116. package/build/user-event/utils/dispatch-event.js.map +1 -1
  117. package/build/wait-for.js +3 -1
  118. package/build/wait-for.js.map +1 -1
  119. package/build/within.d.ts +19 -19
  120. package/build/within.js +8 -8
  121. package/build/within.js.map +1 -1
  122. package/package.json +37 -35
  123. package/typings/index.flow.js +5 -4
  124. package/build/test-utils/index.d.ts +0 -1
  125. package/build/test-utils/index.js +0 -17
  126. package/build/test-utils/index.js.map +0 -1
package/build/render.js CHANGED
@@ -3,45 +3,46 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.render = render;
6
+ exports.default = render;
7
+ exports.renderInternal = renderInternal;
7
8
  var React = _interopRequireWildcard(require("react"));
8
- var _universalTestRenderer = require("universal-test-renderer");
9
9
  var _act = _interopRequireDefault(require("./act"));
10
10
  var _cleanup = require("./cleanup");
11
11
  var _config = require("./config");
12
12
  var _debug = require("./helpers/debug");
13
- var _hostComponentNames = require("./helpers/host-component-names");
13
+ var _renderAct = require("./render-act");
14
14
  var _screen = require("./screen");
15
15
  var _within = require("./within");
16
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
18
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
- const createRootOptions = {
20
- textComponents: _hostComponentNames.HOST_TEXT_NAMES
21
- };
22
-
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); }
23
18
  /**
24
19
  * Renders test component deeply using React Test Renderer and exposes helpers
25
20
  * to assert on the output.
26
21
  */
27
- function render(element, options = {}) {
22
+ function render(component, options = {}) {
23
+ return renderInternal(component, options);
24
+ }
25
+ function renderInternal(component, options) {
28
26
  const {
29
27
  wrapper: Wrapper
30
28
  } = options || {};
29
+
30
+ // TODO allow passing some options
31
+ const rendererOptions = {};
31
32
  const wrap = element => Wrapper ? /*#__PURE__*/React.createElement(Wrapper, null, element) : element;
32
- const renderer = (0, _universalTestRenderer.createRoot)({
33
- ...createRootOptions,
34
- createNodeMock: options?.createNodeMock
35
- });
36
- void (0, _act.default)(() => {
37
- renderer.render(wrap(element));
38
- });
33
+ const renderer = (0, _renderAct.renderWithAct)(wrap(component), rendererOptions);
39
34
  return buildRenderResult(renderer, wrap);
40
35
  }
41
36
  function buildRenderResult(renderer, wrap) {
42
- const update = element => {
37
+ const rerender = component => {
43
38
  void (0, _act.default)(() => {
44
- renderer.render(wrap(element));
39
+ renderer.render(wrap(component));
40
+ });
41
+ };
42
+ const rerenderAsync = async component => {
43
+ // eslint-disable-next-line require-await
44
+ await (0, _act.default)(async () => {
45
+ renderer.render(wrap(component));
45
46
  });
46
47
  };
47
48
  const unmount = () => {
@@ -49,18 +50,34 @@ function buildRenderResult(renderer, wrap) {
49
50
  renderer.unmount();
50
51
  });
51
52
  };
52
- (0, _cleanup.addToCleanupQueue)(unmount);
53
+ const unmountAsync = async () => {
54
+ // eslint-disable-next-line require-await
55
+ await (0, _act.default)(async () => {
56
+ renderer.unmount();
57
+ });
58
+ };
59
+ (0, _cleanup.addToCleanupQueue)(unmountAsync);
53
60
  const result = {
54
61
  ...(0, _within.getQueriesForElement)(renderer.container),
55
- update,
62
+ rerender,
63
+ rerenderAsync,
64
+ update: rerender,
65
+ // alias for 'rerender'
66
+ updateAsync: rerenderAsync,
67
+ // alias for `rerenderAsync`
56
68
  unmount,
57
- rerender: update,
58
- // alias for `update`
59
- toJSON: () => renderer.root?.toJSON(),
69
+ unmountAsync,
70
+ toJSON: () => renderer.container.toJSON(),
60
71
  debug: makeDebug(renderer),
61
- container: renderer.container,
72
+ get container() {
73
+ return renderer.container;
74
+ },
62
75
  get root() {
63
- return renderer.root;
76
+ const firstChild = renderer.container.children[0];
77
+ if (typeof firstChild === 'string') {
78
+ throw new Error('Invariant Violation: Root element must be a host element. Detected attempt to render a string within the root element.');
79
+ }
80
+ return firstChild;
64
81
  }
65
82
  };
66
83
  (0, _screen.setRenderResult)(result);
@@ -75,7 +92,7 @@ function makeDebug(renderer) {
75
92
  ...defaultDebugOptions,
76
93
  ...options
77
94
  };
78
- const json = renderer.root?.toJSON();
95
+ const json = renderer.container.toJSON();
79
96
  if (json) {
80
97
  return (0, _debug.debug)(json, debugOptions);
81
98
  }
@@ -1 +1 @@
1
- {"version":3,"file":"render.js","names":["React","_interopRequireWildcard","require","_universalTestRenderer","_act","_interopRequireDefault","_cleanup","_config","_debug","_hostComponentNames","_screen","_within","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","createRootOptions","textComponents","HOST_TEXT_NAMES","render","element","options","wrapper","Wrapper","wrap","createElement","renderer","createRoot","createNodeMock","act","buildRenderResult","update","unmount","addToCleanupQueue","result","getQueriesForElement","container","rerender","toJSON","root","debug","makeDebug","setRenderResult","debugImpl","defaultDebugOptions","getConfig","debugOptions","json"],"sources":["../src/render.tsx"],"sourcesContent":["import * as React from 'react';\nimport type { HostElement, Root, RootOptions } from 'universal-test-renderer';\nimport { createRoot } from 'universal-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 createNodeMock?: (element: React.ReactElement) => object;\n}\n\nexport type RenderResult = ReturnType<typeof render>;\n\nconst createRootOptions: RootOptions = {\n textComponents: HOST_TEXT_NAMES,\n};\n\n/**\n * Renders test component deeply using React Test Renderer and exposes helpers\n * to assert on the output.\n */\nexport function render<T>(element: React.ReactElement<T>, options: RenderOptions = {}) {\n const { wrapper: Wrapper } = options || {};\n\n const wrap = (element: React.ReactElement) => (Wrapper ? <Wrapper>{element}</Wrapper> : element);\n const renderer = createRoot({\n ...createRootOptions,\n createNodeMock: options?.createNodeMock,\n });\n void act(() => {\n renderer.render(wrap(element));\n });\n\n return buildRenderResult(renderer, wrap);\n}\n\nfunction buildRenderResult(\n renderer: Root,\n wrap: (element: React.ReactElement) => React.JSX.Element,\n) {\n const update = (element: React.ReactElement) => {\n void act(() => {\n renderer.render(wrap(element));\n });\n };\n\n const unmount = () => {\n void act(() => {\n renderer.unmount();\n });\n };\n\n addToCleanupQueue(unmount);\n\n const result = {\n ...getQueriesForElement(renderer.container),\n update,\n unmount,\n rerender: update, // alias for `update`\n toJSON: () => renderer.root?.toJSON(),\n debug: makeDebug(renderer),\n container: renderer.container,\n get root(): HostElement | null {\n return renderer.root;\n },\n };\n\n setRenderResult(result);\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.root?.toJSON();\n if (json) {\n return debug(json, debugOptions);\n }\n }\n\n return debugImpl;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,sBAAA,GAAAD,OAAA;AAEA,IAAAE,IAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,mBAAA,GAAAP,OAAA;AACA,IA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,KAAMZ,QAAQ,CAACa,IAAI,EAAED,MAAM,CAAC,CAAC;IACrCE,KAAK,EAAEC,SAAS,CAACf,QAAQ,CAAC;IAC1BU,SAAS,EAAEV,QAAQ,CAACU,SAAS;IAC7B,IAAIG,IAAIA,CAAA,EAAuB;MAC7B,OAAOb,QAAQ,CAACa,IAAI;IACtB;EACF,CAAC;EAED,IAAAG,uBAAe,EAACR,MAAM,CAAC;EACvB,OAAOA,MAAM;AACf;AAIA,SAASO,SAASA,CAACf,QAAc,EAAiB;EAChD,SAASiB,SAASA,CAACtB,OAAsB,EAAE;IACzC,MAAM;MAAEuB;IAAoB,CAAC,GAAG,IAAAC,iBAAS,EAAC,CAAC;IAC3C,MAAMC,YAAY,GAAG;MAAE,GAAGF,mBAAmB;MAAE,GAAGvB;IAAQ,CAAC;IAC3D,MAAM0B,IAAI,GAAGrB,QAAQ,CAACa,IAAI,EAAED,MAAM,CAAC,CAAC;IACpC,IAAIS,IAAI,EAAE;MACR,OAAO,IAAAP,YAAK,EAACO,IAAI,EAAED,YAAY,CAAC;IAClC;EACF;EAEA,OAAOH,SAAS;AAClB","ignoreList":[]}
1
+ {"version":3,"file":"render.js","names":["React","_interopRequireWildcard","require","_act","_interopRequireDefault","_cleanup","_config","_debug","_renderAct","_screen","_within","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","render","component","options","renderInternal","wrapper","Wrapper","rendererOptions","wrap","element","createElement","renderer","renderWithAct","buildRenderResult","rerender","act","rerenderAsync","unmount","unmountAsync","addToCleanupQueue","result","getQueriesForElement","container","update","updateAsync","toJSON","debug","makeDebug","root","firstChild","children","Error","setRenderResult","debugImpl","defaultDebugOptions","getConfig","debugOptions","json"],"sources":["../src/render.tsx"],"sourcesContent":["import * as React from 'react';\nimport type { HostElement, Root, RootOptions } from 'universal-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 { renderWithAct } from './render-act';\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) => unknown;\n}\n\nexport type RenderResult = 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 default function render<T>(component: React.ReactElement<T>, options: RenderOptions = {}) {\n return renderInternal(component, options);\n}\n\nexport function renderInternal<T>(component: React.ReactElement<T>, options?: RenderOptions) {\n const { wrapper: Wrapper } = options || {};\n\n // TODO allow passing some options\n const rendererOptions: RootOptions = {};\n\n const wrap = (element: React.ReactElement) => (Wrapper ? <Wrapper>{element}</Wrapper> : element);\n const renderer = renderWithAct(wrap(component), rendererOptions);\n return buildRenderResult(renderer, wrap);\n}\n\nfunction buildRenderResult(\n renderer: Root,\n wrap: (element: React.ReactElement) => React.JSX.Element,\n) {\n const rerender = (component: React.ReactElement) => {\n void act(() => {\n renderer.render(wrap(component));\n });\n };\n const rerenderAsync = async (component: React.ReactElement) => {\n // eslint-disable-next-line require-await\n await act(async () => {\n renderer.render(wrap(component));\n });\n };\n\n const unmount = () => {\n void act(() => {\n renderer.unmount();\n });\n };\n const unmountAsync = async () => {\n // eslint-disable-next-line require-await\n await act(async () => {\n renderer.unmount();\n });\n };\n\n addToCleanupQueue(unmountAsync);\n\n const result = {\n ...getQueriesForElement(renderer.container),\n rerender,\n rerenderAsync,\n update: rerender, // alias for 'rerender'\n updateAsync: rerenderAsync, // alias for `rerenderAsync`\n unmount,\n unmountAsync,\n toJSON: () => renderer.container.toJSON(),\n debug: makeDebug(renderer),\n get container(): HostElement {\n return renderer.container;\n },\n get root(): HostElement | null {\n const firstChild = renderer.container.children[0];\n if (typeof firstChild === 'string') {\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;AAGA,IAAAC,IAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AAAgD,SAAAE,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAV,wBAAAU,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAd,uBAAA,YAAAA,CAAAU,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA,EAAAF,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAS,CAAA,MAAAF,CAAA,GAAAJ,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAE,CAAA,CAAAI,GAAA,CAAAX,CAAA,UAAAO,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AAU;IACnB;EACF,CAAC;EAED,IAAAG,uBAAe,EAACZ,MAAM,CAAC;EAEvB,OAAOA,MAAM;AACf;AAIA,SAASO,SAASA,CAAChB,QAAc,EAAiB;EAChD,SAASsB,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,MAAMkC,IAAI,GAAG1B,QAAQ,CAACW,SAAS,CAACG,MAAM,CAAC,CAAC;IACxC,IAAIY,IAAI,EAAE;MACR,OAAO,IAAAX,YAAK,EAACW,IAAI,EAAED,YAAY,CAAC;IAClC;EACF;EACA,OAAOH,SAAS;AAClB","ignoreList":[]}
package/build/screen.js CHANGED
@@ -10,21 +10,21 @@ const SCREEN_ERROR = '`render` method has not been called';
10
10
  const notImplemented = () => {
11
11
  throw new Error(SCREEN_ERROR);
12
12
  };
13
- const notImplementedDebug = () => {
14
- throw new Error(SCREEN_ERROR);
15
- };
16
13
  const defaultScreen = {
17
14
  isDetached: true,
18
- get root() {
15
+ get container() {
19
16
  throw new Error(SCREEN_ERROR);
20
17
  },
21
- get container() {
18
+ get root() {
22
19
  throw new Error(SCREEN_ERROR);
23
20
  },
24
- debug: notImplementedDebug,
21
+ debug: notImplemented,
22
+ rerender: notImplemented,
23
+ rerenderAsync: notImplemented,
25
24
  update: notImplemented,
25
+ updateAsync: notImplemented,
26
26
  unmount: notImplemented,
27
- rerender: notImplemented,
27
+ unmountAsync: notImplemented,
28
28
  toJSON: notImplemented,
29
29
  getByLabelText: notImplemented,
30
30
  getAllByLabelText: notImplemented,
@@ -1 +1 @@
1
- {"version":3,"file":"screen.js","names":["SCREEN_ERROR","notImplemented","Error","notImplementedDebug","defaultScreen","isDetached","root","container","debug","update","unmount","rerender","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 'universal-test-renderer';\n\nimport type { RenderResult } from './render';\n\nconst SCREEN_ERROR = '`render` method has not been called';\n\nconst notImplemented = () => {\n throw new Error(SCREEN_ERROR);\n};\n\nconst notImplementedDebug = () => {\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 root(): HostElement | null {\n throw new Error(SCREEN_ERROR);\n },\n get container(): HostElement {\n throw new Error(SCREEN_ERROR);\n },\n debug: notImplementedDebug,\n update: notImplemented,\n unmount: notImplemented,\n rerender: 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,qCAAqC;AAE1D,MAAMC,cAAc,GAAGA,CAAA,KAAM;EAC3B,MAAM,IAAIC,KAAK,CAACF,YAAY,CAAC;AAC/B,CAAC;AAED,MAAMG,mBAAmB,GAAGA,CAAA,KAAM;EAChC,MAAM,IAAID,KAAK,CAACF,YAAY,CAAC;AAC/B,CAAC;AAMD,MAAMI,aAAqB,GAAG;EAC5BC,UAAU,EAAE,IAA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0C,oBAAoB,EAAE1C,cAAc;EACpC2C,uBAAuB,EAAE3C,cAAc;EACvC4C,sBAAsB,EAAE5C,cAAc;EACtC6C,yBAAyB,EAAE7C,cAAc;EACzC8C,qBAAqB,EAAE9C,cAAc;EACrC+C,wBAAwB,EAAE/C,cAAc;EACxCgD,iBAAiB,EAAEhD,cAAc;EACjCiD,oBAAoB,EAAEjD,cAAc;EACpCkD,mBAAmB,EAAElD,cAAc;EACnCmD,sBAAsB,EAAEnD,cAAc;EACtCoD,kBAAkB,EAAEpD,cAAc;EAClCqD,qBAAqB,EAAErD,cAAc;EACrCsD,WAAW,EAAEtD,cAAc;EAC3BuD,cAAc,EAAEvD,cAAc;EAC9BwD,aAAa,EAAExD,cAAc;EAC7ByD,gBAAgB,EAAEzD,cAAc;EAChC0D,YAAY,EAAE1D,cAAc;EAC5B2D,eAAe,EAAE3D,cAAc;EAC/B4D,SAAS,EAAE5D,cAAc;EACzB6D,YAAY,EAAE7D,cAAc;EAC5B8D,WAAW,EAAE9D,cAAc;EAC3B+D,cAAc,EAAE/D,cAAc;EAC9BgE,UAAU,EAAEhE,cAAc;EAC1BiE,aAAa,EAAEjE;AACjB,CAAC;AAEM,IAAIkE,MAAc,GAAAC,OAAA,CAAAD,MAAA,GAAG/D,aAAa;AAElC,SAASiE,eAAeA,CAACC,YAA0B,EAAE;EAC1DF,OAAA,CAAAD,MAAA,GAAAA,MAAM,GAAGG,YAAY;AACvB;AAEO,SAASC,iBAAiBA,CAAA,EAAG;EAClCH,OAAA,CAAAD,MAAA,GAAAA,MAAM,GAAG/D,aAAa;AACxB","ignoreList":[]}
1
+ {"version":3,"file":"screen.js","names":["SCREEN_ERROR","notImplemented","Error","defaultScreen","isDetached","container","root","debug","rerender","rerenderAsync","update","updateAsync","unmount","unmountAsync","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 'universal-test-renderer';\n\nimport type { RenderResult } from './render';\n\nconst SCREEN_ERROR = '`render` method 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 rerenderAsync: notImplemented,\n update: notImplemented,\n updateAsync: notImplemented,\n unmount: notImplemented,\n unmountAsync: 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,qCAAqC;AAE1D,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,CAAC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B,EAAE9C,cAAc;EACtC+C,yBAAyB,EAAE/C,cAAc;EACzCgD,qBAAqB,EAAEhD,cAAc;EACrCiD,wBAAwB,EAAEjD,cAAc;EACxCkD,iBAAiB,EAAElD,cAAc;EACjCmD,oBAAoB,EAAEnD,cAAc;EACpCoD,mBAAmB,EAAEpD,cAAc;EACnCqD,sBAAsB,EAAErD,cAAc;EACtCsD,kBAAkB,EAAEtD,cAAc;EAClCuD,qBAAqB,EAAEvD,cAAc;EACrCwD,WAAW,EAAExD,cAAc;EAC3ByD,cAAc,EAAEzD,cAAc;EAC9B0D,aAAa,EAAE1D,cAAc;EAC7B2D,gBAAgB,EAAE3D,cAAc;EAChC4D,YAAY,EAAE5D,cAAc;EAC5B6D,eAAe,EAAE7D,cAAc;EAC/B8D,SAAS,EAAE9D,cAAc;EACzB+D,YAAY,EAAE/D,cAAc;EAC5BgE,WAAW,EAAEhE,cAAc;EAC3BiE,cAAc,EAAEjE,cAAc;EAC9BkE,UAAU,EAAElE,cAAc;EAC1BmE,aAAa,EAAEnE;AACjB,CAAC;AAEM,IAAIoE,MAAc,GAAAC,OAAA,CAAAD,MAAA,GAAGlE,aAAa;AAElC,SAASoE,eAAeA,CAACC,YAA0B,EAAE;EAC1DF,OAAA,CAAAD,MAAA,GAAAA,MAAM,GAAGG,YAAY;AACvB;AAEO,SAASC,iBAAiBA,CAAA,EAAG;EAClCH,OAAA,CAAAD,MAAA,GAAAA,MAAM,GAAGlE,aAAa;AACxB","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export declare function excludeConsoleMessage(logFn: (...args: unknown[]) => void, excludeMessage: string): (...args: unknown[]) => void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.excludeConsoleMessage = excludeConsoleMessage;
7
+ var _util = require("util");
8
+ function excludeConsoleMessage(logFn, excludeMessage) {
9
+ return (...args) => {
10
+ const message = (0, _util.format)(...args);
11
+ if (message.includes(excludeMessage)) {
12
+ return;
13
+ }
14
+ logFn(...args);
15
+ };
16
+ }
17
+ //# sourceMappingURL=console.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.js","names":["_util","require","excludeConsoleMessage","logFn","excludeMessage","args","message","format","includes"],"sources":["../../src/test-utils/console.ts"],"sourcesContent":["import { format } from 'util';\n\nexport function excludeConsoleMessage(logFn: (...args: unknown[]) => void, excludeMessage: string) {\n return (...args: unknown[]) => {\n const message = format(...args);\n if (message.includes(excludeMessage)) {\n return;\n }\n\n logFn(...args);\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAEO,SAASC,qBAAqBA,CAACC,KAAmC,EAAEC,cAAsB,EAAE;EACjG,OAAO,CAAC,GAAGC,IAAe,KAAK;IAC7B,MAAMC,OAAO,GAAG,IAAAC,YAAM,EAAC,GAAGF,IAAI,CAAC;IAC/B,IAAIC,OAAO,CAACE,QAAQ,CAACJ,cAAc,CAAC,EAAE;MACpC;IACF;IAEAD,KAAK,CAAC,GAAGE,IAAI,CAAC;EAChB,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ import type { JsonNode } from 'universal-test-renderer';
2
+ type JsonPropsMapper = {
3
+ [key: string]: unknown;
4
+ };
5
+ export declare function mapJsonProps<T extends JsonNode | JsonNode[] | null>(node: T, mapper: JsonPropsMapper): T;
6
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.mapJsonProps = mapJsonProps;
7
+ function mapJsonProps(node, mapper) {
8
+ if (Array.isArray(node)) {
9
+ return node.map(e => mapJsonProps(e, mapper));
10
+ }
11
+ if (!node || typeof node === 'string') {
12
+ return node;
13
+ }
14
+ const resultProps = {
15
+ ...node.props
16
+ };
17
+ Object.keys(mapper).forEach(key => {
18
+ if (key in node.props) {
19
+ resultProps[key] = mapper[key];
20
+ }
21
+ });
22
+
23
+ // @ts-expect-error: TODO fix type
24
+ const resultElement = {
25
+ ...node,
26
+ props: resultProps
27
+ };
28
+ Object.defineProperty(resultElement, '$$typeof', {
29
+ value: Symbol.for('react.test.json')
30
+ });
31
+ return resultElement;
32
+ }
33
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","names":["mapJsonProps","node","mapper","Array","isArray","map","e","resultProps","props","Object","keys","forEach","key","resultElement","defineProperty","value","Symbol","for"],"sources":["../../src/test-utils/json.ts"],"sourcesContent":["import type { JsonNode } from 'universal-test-renderer';\n\ntype JsonPropsMapper = {\n [key: string]: unknown;\n};\n\nexport function mapJsonProps<T extends JsonNode | JsonNode[] | null>(\n node: T,\n mapper: JsonPropsMapper,\n): T {\n if (Array.isArray(node)) {\n return node.map((e) => mapJsonProps(e, mapper)) as T;\n }\n\n if (!node || typeof node === 'string') {\n return node;\n }\n\n const resultProps: Record<string, unknown> = { ...node.props };\n Object.keys(mapper).forEach((key) => {\n if (key in node.props) {\n resultProps[key] = mapper[key];\n }\n });\n\n // @ts-expect-error: TODO fix type\n const resultElement = { ...node, props: resultProps };\n Object.defineProperty(resultElement, '$$typeof', {\n value: Symbol.for('react.test.json'),\n });\n\n return resultElement;\n}\n"],"mappings":";;;;;;AAMO,SAASA,YAAYA,CAC1BC,IAAO,EACPC,MAAuB,EACpB;EACH,IAAIC,KAAK,CAACC,OAAO,CAACH,IAAI,CAAC,EAAE;IACvB,OAAOA,IAAI,CAACI,GAAG,CAAEC,CAAC,IAAKN,YAAY,CAACM,CAAC,EAAEJ,MAAM,CAAC,CAAC;EACjD;EAEA,IAAI,CAACD,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IACrC,OAAOA,IAAI;EACb;EAEA,MAAMM,WAAoC,GAAG;IAAE,GAAGN,IAAI,CAACO;EAAM,CAAC;EAC9DC,MAAM,CAACC,IAAI,CAACR,MAAM,CAAC,CAACS,OAAO,CAAEC,GAAG,IAAK;IACnC,IAAIA,GAAG,IAAIX,IAAI,CAACO,KAAK,EAAE;MACrBD,WAAW,CAACK,GAAG,CAAC,GAAGV,MAAM,CAACU,GAAG,CAAC;IAChC;EACF,CAAC,CAAC;;EAEF;EACA,MAAMC,aAAa,GAAG;IAAE,GAAGZ,IAAI;IAAEO,KAAK,EAAED;EAAY,CAAC;EACrDE,MAAM,CAACK,cAAc,CAACD,aAAa,EAAE,UAAU,EAAE;IAC/CE,KAAK,EAAEC,MAAM,CAACC,GAAG,CAAC,iBAAiB;EACrC,CAAC,CAAC;EAEF,OAAOJ,aAAa;AACtB","ignoreList":[]}
@@ -1 +1 @@
1
- {"root":["../src/act.ts","../src/cleanup.ts","../src/config.ts","../src/event-handler.ts","../src/fire-event.ts","../src/flush-micro-tasks.ts","../src/index.ts","../src/matches.ts","../src/native-state.ts","../src/pure.ts","../src/react-versions.ts","../src/render-hook.tsx","../src/render.tsx","../src/screen.ts","../src/types.ts","../src/wait-for-element-to-be-removed.ts","../src/wait-for.ts","../src/within.ts","../src/helpers/accessibility.ts","../src/helpers/component-tree.ts","../src/helpers/debug.ts","../src/helpers/errors.ts","../src/helpers/find-all.ts","../src/helpers/format-element.ts","../src/helpers/host-component-names.ts","../src/helpers/logger.ts","../src/helpers/map-props.ts","../src/helpers/object.ts","../src/helpers/pointer-events.ts","../src/helpers/text-content.ts","../src/helpers/text-input.ts","../src/helpers/timers.ts","../src/helpers/wrap-async.ts","../src/helpers/matchers/match-accessibility-state.ts","../src/helpers/matchers/match-accessibility-value.ts","../src/helpers/matchers/match-array-prop.ts","../src/helpers/matchers/match-label-text.ts","../src/helpers/matchers/match-object-prop.ts","../src/helpers/matchers/match-string-prop.ts","../src/helpers/matchers/match-text-content.ts","../src/matchers/extend-expect.ts","../src/matchers/index.ts","../src/matchers/to-be-busy.ts","../src/matchers/to-be-checked.ts","../src/matchers/to-be-disabled.ts","../src/matchers/to-be-empty-element.ts","../src/matchers/to-be-expanded.ts","../src/matchers/to-be-on-the-screen.ts","../src/matchers/to-be-partially-checked.ts","../src/matchers/to-be-selected.ts","../src/matchers/to-be-visible.ts","../src/matchers/to-contain-element.ts","../src/matchers/to-have-accessibility-value.ts","../src/matchers/to-have-accessible-name.ts","../src/matchers/to-have-display-value.ts","../src/matchers/to-have-prop.ts","../src/matchers/to-have-style.ts","../src/matchers/to-have-text-content.ts","../src/matchers/types.ts","../src/matchers/utils.ts","../src/queries/display-value.ts","../src/queries/hint-text.ts","../src/queries/label-text.ts","../src/queries/make-queries.ts","../src/queries/options.ts","../src/queries/placeholder-text.ts","../src/queries/role.ts","../src/queries/test-id.ts","../src/queries/text.ts","../src/test-utils/events.ts","../src/test-utils/index.ts","../src/user-event/clear.ts","../src/user-event/index.ts","../src/user-event/paste.ts","../src/user-event/event-builder/base.ts","../src/user-event/event-builder/common.ts","../src/user-event/event-builder/index.ts","../src/user-event/event-builder/scroll-view.ts","../src/user-event/event-builder/text-input.ts","../src/user-event/press/index.ts","../src/user-event/press/press.ts","../src/user-event/scroll/index.ts","../src/user-event/scroll/scroll-to.ts","../src/user-event/scroll/utils.ts","../src/user-event/setup/index.ts","../src/user-event/setup/setup.ts","../src/user-event/type/index.ts","../src/user-event/type/parse-keys.ts","../src/user-event/type/type.ts","../src/user-event/utils/content-size.ts","../src/user-event/utils/dispatch-event.ts","../src/user-event/utils/index.ts","../src/user-event/utils/text-range.ts","../src/user-event/utils/wait.ts"],"version":"5.8.2"}
1
+ {"root":["../src/act.ts","../src/cleanup.ts","../src/config.ts","../src/event-handler.ts","../src/fire-event.ts","../src/flush-micro-tasks.ts","../src/index.ts","../src/matches.ts","../src/native-state.ts","../src/pure.ts","../src/react-versions.ts","../src/render-act.ts","../src/render-async.tsx","../src/render-hook.tsx","../src/render.tsx","../src/screen.ts","../src/types.ts","../src/wait-for-element-to-be-removed.ts","../src/wait-for.ts","../src/within.ts","../src/helpers/accessibility.ts","../src/helpers/component-tree.ts","../src/helpers/debug.ts","../src/helpers/errors.ts","../src/helpers/find-all.ts","../src/helpers/format-element.ts","../src/helpers/host-component-names.ts","../src/helpers/logger.ts","../src/helpers/map-props.ts","../src/helpers/object.ts","../src/helpers/pointer-events.ts","../src/helpers/text-content.ts","../src/helpers/text-input.ts","../src/helpers/timers.ts","../src/helpers/wrap-async.ts","../src/helpers/matchers/match-accessibility-state.ts","../src/helpers/matchers/match-accessibility-value.ts","../src/helpers/matchers/match-array-prop.ts","../src/helpers/matchers/match-label-text.ts","../src/helpers/matchers/match-object-prop.ts","../src/helpers/matchers/match-string-prop.ts","../src/helpers/matchers/match-text-content.ts","../src/matchers/extend-expect.ts","../src/matchers/index.ts","../src/matchers/to-be-busy.ts","../src/matchers/to-be-checked.ts","../src/matchers/to-be-disabled.ts","../src/matchers/to-be-empty-element.ts","../src/matchers/to-be-expanded.ts","../src/matchers/to-be-on-the-screen.ts","../src/matchers/to-be-partially-checked.ts","../src/matchers/to-be-selected.ts","../src/matchers/to-be-visible.ts","../src/matchers/to-contain-element.ts","../src/matchers/to-have-accessibility-value.ts","../src/matchers/to-have-accessible-name.ts","../src/matchers/to-have-display-value.ts","../src/matchers/to-have-prop.ts","../src/matchers/to-have-style.ts","../src/matchers/to-have-text-content.ts","../src/matchers/types.ts","../src/matchers/utils.ts","../src/queries/display-value.ts","../src/queries/hint-text.ts","../src/queries/label-text.ts","../src/queries/make-queries.ts","../src/queries/options.ts","../src/queries/placeholder-text.ts","../src/queries/role.ts","../src/queries/test-id.ts","../src/queries/text.ts","../src/test-utils/console.ts","../src/test-utils/events.ts","../src/test-utils/json.ts","../src/user-event/clear.ts","../src/user-event/index.ts","../src/user-event/paste.ts","../src/user-event/event-builder/base.ts","../src/user-event/event-builder/common.ts","../src/user-event/event-builder/index.ts","../src/user-event/event-builder/scroll-view.ts","../src/user-event/event-builder/text-input.ts","../src/user-event/press/index.ts","../src/user-event/press/press.ts","../src/user-event/scroll/index.ts","../src/user-event/scroll/scroll-to.ts","../src/user-event/scroll/utils.ts","../src/user-event/setup/index.ts","../src/user-event/setup/setup.ts","../src/user-event/type/index.ts","../src/user-event/type/parse-keys.ts","../src/user-event/type/type.ts","../src/user-event/utils/content-size.ts","../src/user-event/utils/dispatch-event.ts","../src/user-event/utils/index.ts","../src/user-event/utils/text-range.ts","../src/user-event/utils/wait.ts"],"version":"5.9.3"}
package/build/types.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /** `RefObject` type from React 19. */
2
+ export type RefObject<T> = {
3
+ current: T;
4
+ };
1
5
  /**
2
6
  * Location of an element.
3
7
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\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// TS autocomplete trick\n// Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939\nexport type StringWithAutocomplete<T> = T | (string & {});\n"],"mappings":"","ignoreList":[]}
@@ -20,7 +20,7 @@ async function clear(element) {
20
20
  }
21
21
 
22
22
  // 1. Enter element
23
- (0, _utils.dispatchEvent)(element, 'focus', _eventBuilder.EventBuilder.Common.focus());
23
+ await (0, _utils.dispatchEvent)(element, 'focus', _eventBuilder.EventBuilder.Common.focus());
24
24
 
25
25
  // 2. Select all
26
26
  const textToClear = (0, _textInput.getTextInputValue)(element);
@@ -28,7 +28,7 @@ async function clear(element) {
28
28
  start: 0,
29
29
  end: textToClear.length
30
30
  };
31
- (0, _utils.dispatchEvent)(element, 'selectionChange', _eventBuilder.EventBuilder.TextInput.selectionChange(selectionRange));
31
+ await (0, _utils.dispatchEvent)(element, 'selectionChange', _eventBuilder.EventBuilder.TextInput.selectionChange(selectionRange));
32
32
 
33
33
  // 3. Press backspace with selected text
34
34
  const emptyText = '';
@@ -40,7 +40,7 @@ async function clear(element) {
40
40
 
41
41
  // 4. Exit element
42
42
  await (0, _utils.wait)(this.config);
43
- (0, _utils.dispatchEvent)(element, 'endEditing', _eventBuilder.EventBuilder.TextInput.endEditing(emptyText));
44
- (0, _utils.dispatchEvent)(element, 'blur', _eventBuilder.EventBuilder.Common.blur());
43
+ await (0, _utils.dispatchEvent)(element, 'endEditing', _eventBuilder.EventBuilder.TextInput.endEditing(emptyText));
44
+ await (0, _utils.dispatchEvent)(element, 'blur', _eventBuilder.EventBuilder.Common.blur());
45
45
  }
46
46
  //# sourceMappingURL=clear.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"clear.js","names":["_errors","require","_hostComponentNames","_pointerEvents","_textInput","_eventBuilder","_type","_utils","clear","element","isHostTextInput","ErrorWithStack","type","isEditableTextInput","isPointerEventEnabled","dispatchEvent","EventBuilder","Common","focus","textToClear","getTextInputValue","selectionRange","start","end","length","TextInput","selectionChange","emptyText","emitTypingEvents","config","key","text","wait","endEditing","blur"],"sources":["../../src/user-event/clear.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\n\nimport { ErrorWithStack } from '../helpers/errors';\nimport { isHostTextInput } from '../helpers/host-component-names';\nimport { isPointerEventEnabled } from '../helpers/pointer-events';\nimport { getTextInputValue, isEditableTextInput } from '../helpers/text-input';\nimport { EventBuilder } from './event-builder';\nimport type { UserEventInstance } from './setup';\nimport { emitTypingEvents } from './type/type';\nimport { dispatchEvent, wait } from './utils';\n\nexport async function clear(this: UserEventInstance, element: HostElement): Promise<void> {\n if (!isHostTextInput(element)) {\n throw new ErrorWithStack(\n `clear() only supports host \"TextInput\" elements. Passed element has type: \"${element.type}\".`,\n clear,\n );\n }\n\n if (!isEditableTextInput(element) || !isPointerEventEnabled(element)) {\n return;\n }\n\n // 1. Enter element\n dispatchEvent(element, 'focus', EventBuilder.Common.focus());\n\n // 2. Select all\n const textToClear = getTextInputValue(element);\n const selectionRange = {\n start: 0,\n end: textToClear.length,\n };\n dispatchEvent(element, 'selectionChange', EventBuilder.TextInput.selectionChange(selectionRange));\n\n // 3. Press backspace with selected text\n const emptyText = '';\n await emitTypingEvents(element, {\n config: this.config,\n key: 'Backspace',\n text: emptyText,\n });\n\n // 4. Exit element\n await wait(this.config);\n dispatchEvent(element, 'endEditing', EventBuilder.TextInput.endEditing(emptyText));\n dispatchEvent(element, 'blur', EventBuilder.Common.blur());\n}\n"],"mappings":";;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAEA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAEO,eAAeO,KAAKA,CAA0BC,OAAoB,EAAiB;EACxF,IAAI,CAAC,IAAAC,mCAAe,EAACD,OAAO,CAAC,EAAE;IAC7B,MAAM,IAAIE,sBAAc,CACtB,8EAA8EF,OAAO,CAACG,IAAI,IAAI,EAC9FJ,KACF,CAAC;EACH;EAEA,IAAI,CAAC,IAAAK,8BAAmB,EAACJ,OAAO,CAAC,IAAI,CAAC,IAAAK,oCAAqB,EAACL,OAAO,CAAC,EAAE;IACpE;EACF;;EAEA;EACA,IAAAM,oBAAa,EAACN,OAAO,EAAE,OAAO,EAAEO,0BAAY,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,CAAC;;EAE5D;EACA,MAAMC,WAAW,GAAG,IAAAC,4BAAiB,EAACX,OAAO,CAAC;EAC9C,MAAMY,cAAc,GAAG;IACrBC,KAAK,EAAE,CAAC;IACRC,GAAG,EAAEJ,WAAW,CAACK;EACnB,CAAC;EACD,IAAAT,oBAAa,EAACN,OAAO,EAAE,iBAAiB,EAAEO,0BAAY,CAACS,SAAS,CAACC,eAAe,CAACL,cAAc,CAAC,CAAC;;EAEjG;EACA,MAAMM,SAAS,GAAG,EAAE;EACpB,MAAM,IAAAC,sBAAgB,EAACnB,OAAO,EAAE;IAC9BoB,MAAM,EAAE,IAAI,CAACA,MAAM;IACnBC,GAAG,EAAE,WAAW;IAChBC,IAAI,EAAEJ;EACR,CAAC,CAAC;;EAEF;EACA,MAAM,IAAAK,WAAI,EAAC,IAAI,CAACH,MAAM,CAAC;EACvB,IAAAd,oBAAa,EAACN,OAAO,EAAE,YAAY,EAAEO,0BAAY,CAACS,SAAS,CAACQ,UAAU,CAACN,SAAS,CAAC,CAAC;EAClF,IAAAZ,oBAAa,EAACN,OAAO,EAAE,MAAM,EAAEO,0BAAY,CAACC,MAAM,CAACiB,IAAI,CAAC,CAAC,CAAC;AAC5D","ignoreList":[]}
1
+ {"version":3,"file":"clear.js","names":["_errors","require","_hostComponentNames","_pointerEvents","_textInput","_eventBuilder","_type","_utils","clear","element","isHostTextInput","ErrorWithStack","type","isEditableTextInput","isPointerEventEnabled","dispatchEvent","EventBuilder","Common","focus","textToClear","getTextInputValue","selectionRange","start","end","length","TextInput","selectionChange","emptyText","emitTypingEvents","config","key","text","wait","endEditing","blur"],"sources":["../../src/user-event/clear.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\n\nimport { ErrorWithStack } from '../helpers/errors';\nimport { isHostTextInput } from '../helpers/host-component-names';\nimport { isPointerEventEnabled } from '../helpers/pointer-events';\nimport { getTextInputValue, isEditableTextInput } from '../helpers/text-input';\nimport { EventBuilder } from './event-builder';\nimport type { UserEventInstance } from './setup';\nimport { emitTypingEvents } from './type/type';\nimport { dispatchEvent, wait } from './utils';\n\nexport async function clear(this: UserEventInstance, element: HostElement): Promise<void> {\n if (!isHostTextInput(element)) {\n throw new ErrorWithStack(\n `clear() only supports host \"TextInput\" elements. Passed element has type: \"${element.type}\".`,\n clear,\n );\n }\n\n if (!isEditableTextInput(element) || !isPointerEventEnabled(element)) {\n return;\n }\n\n // 1. Enter element\n await dispatchEvent(element, 'focus', EventBuilder.Common.focus());\n\n // 2. Select all\n const textToClear = getTextInputValue(element);\n const selectionRange = {\n start: 0,\n end: textToClear.length,\n };\n await dispatchEvent(\n element,\n 'selectionChange',\n EventBuilder.TextInput.selectionChange(selectionRange),\n );\n\n // 3. Press backspace with selected text\n const emptyText = '';\n await emitTypingEvents(element, {\n config: this.config,\n key: 'Backspace',\n text: emptyText,\n });\n\n // 4. Exit element\n await wait(this.config);\n await dispatchEvent(element, 'endEditing', EventBuilder.TextInput.endEditing(emptyText));\n await dispatchEvent(element, 'blur', EventBuilder.Common.blur());\n}\n"],"mappings":";;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAEA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAEO,eAAeO,KAAKA,CAA0BC,OAAoB,EAAiB;EACxF,IAAI,CAAC,IAAAC,mCAAe,EAACD,OAAO,CAAC,EAAE;IAC7B,MAAM,IAAIE,sBAAc,CACtB,8EAA8EF,OAAO,CAACG,IAAI,IAAI,EAC9FJ,KACF,CAAC;EACH;EAEA,IAAI,CAAC,IAAAK,8BAAmB,EAACJ,OAAO,CAAC,IAAI,CAAC,IAAAK,oCAAqB,EAACL,OAAO,CAAC,EAAE;IACpE;EACF;;EAEA;EACA,MAAM,IAAAM,oBAAa,EAACN,OAAO,EAAE,OAAO,EAAEO,0BAAY,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,CAAC;;EAElE;EACA,MAAMC,WAAW,GAAG,IAAAC,4BAAiB,EAACX,OAAO,CAAC;EAC9C,MAAMY,cAAc,GAAG;IACrBC,KAAK,EAAE,CAAC;IACRC,GAAG,EAAEJ,WAAW,CAACK;EACnB,CAAC;EACD,MAAM,IAAAT,oBAAa,EACjBN,OAAO,EACP,iBAAiB,EACjBO,0BAAY,CAACS,SAAS,CAACC,eAAe,CAACL,cAAc,CACvD,CAAC;;EAED;EACA,MAAMM,SAAS,GAAG,EAAE;EACpB,MAAM,IAAAC,sBAAgB,EAACnB,OAAO,EAAE;IAC9BoB,MAAM,EAAE,IAAI,CAACA,MAAM;IACnBC,GAAG,EAAE,WAAW;IAChBC,IAAI,EAAEJ;EACR,CAAC,CAAC;;EAEF;EACA,MAAM,IAAAK,WAAI,EAAC,IAAI,CAACH,MAAM,CAAC;EACvB,MAAM,IAAAd,oBAAa,EAACN,OAAO,EAAE,YAAY,EAAEO,0BAAY,CAACS,SAAS,CAACQ,UAAU,CAACN,SAAS,CAAC,CAAC;EACxF,MAAM,IAAAZ,oBAAa,EAACN,OAAO,EAAE,MAAM,EAAEO,0BAAY,CAACC,MAAM,CAACiB,IAAI,CAAC,CAAC,CAAC;AAClE","ignoreList":[]}
@@ -20,7 +20,7 @@ async function paste(element, text) {
20
20
  }
21
21
 
22
22
  // 1. Enter element
23
- (0, _utils.dispatchEvent)(element, 'focus', _eventBuilder.EventBuilder.Common.focus());
23
+ await (0, _utils.dispatchEvent)(element, 'focus', _eventBuilder.EventBuilder.Common.focus());
24
24
 
25
25
  // 2. Select all
26
26
  const textToClear = (0, _textInput.getTextInputValue)(element);
@@ -28,29 +28,29 @@ async function paste(element, text) {
28
28
  start: 0,
29
29
  end: textToClear.length
30
30
  };
31
- (0, _utils.dispatchEvent)(element, 'selectionChange', _eventBuilder.EventBuilder.TextInput.selectionChange(rangeToClear));
31
+ await (0, _utils.dispatchEvent)(element, 'selectionChange', _eventBuilder.EventBuilder.TextInput.selectionChange(rangeToClear));
32
32
 
33
33
  // 3. Paste the text
34
34
  _nativeState.nativeState.valueForElement.set(element, text);
35
- (0, _utils.dispatchEvent)(element, 'change', _eventBuilder.EventBuilder.TextInput.change(text));
36
- (0, _utils.dispatchEvent)(element, 'changeText', text);
35
+ await (0, _utils.dispatchEvent)(element, 'change', _eventBuilder.EventBuilder.TextInput.change(text));
36
+ await (0, _utils.dispatchEvent)(element, 'changeText', text);
37
37
  const rangeAfter = {
38
38
  start: text.length,
39
39
  end: text.length
40
40
  };
41
- (0, _utils.dispatchEvent)(element, 'selectionChange', _eventBuilder.EventBuilder.TextInput.selectionChange(rangeAfter));
41
+ await (0, _utils.dispatchEvent)(element, 'selectionChange', _eventBuilder.EventBuilder.TextInput.selectionChange(rangeAfter));
42
42
 
43
43
  // According to the docs only multiline TextInput emits contentSizeChange event
44
44
  // @see: https://reactnative.dev/docs/textinput#oncontentsizechange
45
45
  const isMultiline = element.props.multiline === true;
46
46
  if (isMultiline) {
47
47
  const contentSize = (0, _utils.getTextContentSize)(text);
48
- (0, _utils.dispatchEvent)(element, 'contentSizeChange', _eventBuilder.EventBuilder.TextInput.contentSizeChange(contentSize));
48
+ await (0, _utils.dispatchEvent)(element, 'contentSizeChange', _eventBuilder.EventBuilder.TextInput.contentSizeChange(contentSize));
49
49
  }
50
50
 
51
51
  // 4. Exit element
52
52
  await (0, _utils.wait)(this.config);
53
- (0, _utils.dispatchEvent)(element, 'endEditing', _eventBuilder.EventBuilder.TextInput.endEditing(text));
54
- (0, _utils.dispatchEvent)(element, 'blur', _eventBuilder.EventBuilder.Common.blur());
53
+ await (0, _utils.dispatchEvent)(element, 'endEditing', _eventBuilder.EventBuilder.TextInput.endEditing(text));
54
+ await (0, _utils.dispatchEvent)(element, 'blur', _eventBuilder.EventBuilder.Common.blur());
55
55
  }
56
56
  //# sourceMappingURL=paste.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"paste.js","names":["_errors","require","_hostComponentNames","_pointerEvents","_textInput","_nativeState","_eventBuilder","_utils","paste","element","text","isHostTextInput","ErrorWithStack","type","isEditableTextInput","isPointerEventEnabled","dispatchEvent","EventBuilder","Common","focus","textToClear","getTextInputValue","rangeToClear","start","end","length","TextInput","selectionChange","nativeState","valueForElement","set","change","rangeAfter","isMultiline","props","multiline","contentSize","getTextContentSize","contentSizeChange","wait","config","endEditing","blur"],"sources":["../../src/user-event/paste.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\n\nimport { ErrorWithStack } from '../helpers/errors';\nimport { isHostTextInput } from '../helpers/host-component-names';\nimport { isPointerEventEnabled } from '../helpers/pointer-events';\nimport { getTextInputValue, isEditableTextInput } from '../helpers/text-input';\nimport { nativeState } from '../native-state';\nimport { EventBuilder } from './event-builder';\nimport type { UserEventInstance } from './setup';\nimport { dispatchEvent, getTextContentSize, wait } from './utils';\n\nexport async function paste(\n this: UserEventInstance,\n element: HostElement,\n text: string,\n): Promise<void> {\n if (!isHostTextInput(element)) {\n throw new ErrorWithStack(\n `paste() only supports host \"TextInput\" elements. Passed element has type: \"${element.type}\".`,\n paste,\n );\n }\n\n if (!isEditableTextInput(element) || !isPointerEventEnabled(element)) {\n return;\n }\n\n // 1. Enter element\n dispatchEvent(element, 'focus', EventBuilder.Common.focus());\n\n // 2. Select all\n const textToClear = getTextInputValue(element);\n const rangeToClear = { start: 0, end: textToClear.length };\n dispatchEvent(element, 'selectionChange', EventBuilder.TextInput.selectionChange(rangeToClear));\n\n // 3. Paste the text\n nativeState.valueForElement.set(element, text);\n dispatchEvent(element, 'change', EventBuilder.TextInput.change(text));\n dispatchEvent(element, 'changeText', text);\n\n const rangeAfter = { start: text.length, end: text.length };\n dispatchEvent(element, 'selectionChange', EventBuilder.TextInput.selectionChange(rangeAfter));\n\n // According to the docs only multiline TextInput emits contentSizeChange event\n // @see: https://reactnative.dev/docs/textinput#oncontentsizechange\n const isMultiline = element.props.multiline === true;\n if (isMultiline) {\n const contentSize = getTextContentSize(text);\n dispatchEvent(\n element,\n 'contentSizeChange',\n EventBuilder.TextInput.contentSizeChange(contentSize),\n );\n }\n\n // 4. Exit element\n await wait(this.config);\n dispatchEvent(element, 'endEditing', EventBuilder.TextInput.endEditing(text));\n dispatchEvent(element, 'blur', EventBuilder.Common.blur());\n}\n"],"mappings":";;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AAEO,eAAeO,KAAKA,CAEzBC,OAAoB,EACpBC,IAAY,EACG;EACf,IAAI,CAAC,IAAAC,mCAAe,EAACF,OAAO,CAAC,EAAE;IAC7B,MAAM,IAAIG,sBAAc,CACtB,8EAA8EH,OAAO,CAACI,IAAI,IAAI,EAC9FL,KACF,CAAC;EACH;EAEA,IAAI,CAAC,IAAAM,8BAAmB,EAACL,OAAO,CAAC,IAAI,CAAC,IAAAM,oCAAqB,EAACN,OAAO,CAAC,EAAE;IACpE;EACF;;EAEA;EACA,IAAAO,oBAAa,EAACP,OAAO,EAAE,OAAO,EAAEQ,0BAAY,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,CAAC;;EAE5D;EACA,MAAMC,WAAW,GAAG,IAAAC,4BAAiB,EAACZ,OAAO,CAAC;EAC9C,MAAMa,YAAY,GAAG;IAAEC,KAAK,EAAE,CAAC;IAAEC,GAAG,EAAEJ,WAAW,CAACK;EAAO,CAAC;EAC1D,IAAAT,oBAAa,EAACP,OAAO,EAAE,iBAAiB,EAAEQ,0BAAY,CAACS,SAAS,CAACC,eAAe,CAACL,YAAY,CAAC,CAAC;;EAE/F;EACAM,wBAAW,CAACC,eAAe,CAACC,GAAG,CAACrB,OAAO,EAAEC,IAAI,CAAC;EAC9C,IAAAM,oBAAa,EAACP,OAAO,EAAE,QAAQ,EAAEQ,0BAAY,CAACS,SAAS,CAACK,MAAM,CAACrB,IAAI,CAAC,CAAC;EACrE,IAAAM,oBAAa,EAACP,OAAO,EAAE,YAAY,EAAEC,IAAI,CAAC;EAE1C,MAAMsB,UAAU,GAAG;IAAET,KAAK,EAAEb,IAAI,CAACe,MAAM;IAAED,GAAG,EAAEd,IAAI,CAACe;EAAO,CAAC;EAC3D,IAAAT,oBAAa,EAACP,OAAO,EAAE,iBAAiB,EAAEQ,0BAAY,CAACS,SAAS,CAACC,eAAe,CAACK,UAAU,CAAC,CAAC;;EAE7F;EACA;EACA,MAAMC,WAAW,GAAGxB,OAAO,CAACyB,KAAK,CAACC,SAAS,KAAK,IAAI;EACpD,IAAIF,WAAW,EAAE;IACf,MAAMG,WAAW,GAAG,IAAAC,yBAAkB,EAAC3B,IAAI,CAAC;IAC5C,IAAAM,oBAAa,EACXP,OAAO,EACP,mBAAmB,EACnBQ,0BAAY,CAACS,SAAS,CAACY,iBAAiB,CAACF,WAAW,CACtD,CAAC;EACH;;EAEA;EACA,MAAM,IAAAG,WAAI,EAAC,IAAI,CAACC,MAAM,CAAC;EACvB,IAAAxB,oBAAa,EAACP,OAAO,EAAE,YAAY,EAAEQ,0BAAY,CAACS,SAAS,CAACe,UAAU,CAAC/B,IAAI,CAAC,CAAC;EAC7E,IAAAM,oBAAa,EAACP,OAAO,EAAE,MAAM,EAAEQ,0BAAY,CAACC,MAAM,CAACwB,IAAI,CAAC,CAAC,CAAC;AAC5D","ignoreList":[]}
1
+ {"version":3,"file":"paste.js","names":["_errors","require","_hostComponentNames","_pointerEvents","_textInput","_nativeState","_eventBuilder","_utils","paste","element","text","isHostTextInput","ErrorWithStack","type","isEditableTextInput","isPointerEventEnabled","dispatchEvent","EventBuilder","Common","focus","textToClear","getTextInputValue","rangeToClear","start","end","length","TextInput","selectionChange","nativeState","valueForElement","set","change","rangeAfter","isMultiline","props","multiline","contentSize","getTextContentSize","contentSizeChange","wait","config","endEditing","blur"],"sources":["../../src/user-event/paste.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\n\nimport { ErrorWithStack } from '../helpers/errors';\nimport { isHostTextInput } from '../helpers/host-component-names';\nimport { isPointerEventEnabled } from '../helpers/pointer-events';\nimport { getTextInputValue, isEditableTextInput } from '../helpers/text-input';\nimport { nativeState } from '../native-state';\nimport { EventBuilder } from './event-builder';\nimport type { UserEventInstance } from './setup';\nimport { dispatchEvent, getTextContentSize, wait } from './utils';\n\nexport async function paste(\n this: UserEventInstance,\n element: HostElement,\n text: string,\n): Promise<void> {\n if (!isHostTextInput(element)) {\n throw new ErrorWithStack(\n `paste() only supports host \"TextInput\" elements. Passed element has type: \"${element.type}\".`,\n paste,\n );\n }\n\n if (!isEditableTextInput(element) || !isPointerEventEnabled(element)) {\n return;\n }\n\n // 1. Enter element\n await dispatchEvent(element, 'focus', EventBuilder.Common.focus());\n\n // 2. Select all\n const textToClear = getTextInputValue(element);\n const rangeToClear = { start: 0, end: textToClear.length };\n await dispatchEvent(\n element,\n 'selectionChange',\n EventBuilder.TextInput.selectionChange(rangeToClear),\n );\n\n // 3. Paste the text\n nativeState.valueForElement.set(element, text);\n await dispatchEvent(element, 'change', EventBuilder.TextInput.change(text));\n await dispatchEvent(element, 'changeText', text);\n\n const rangeAfter = { start: text.length, end: text.length };\n await dispatchEvent(\n element,\n 'selectionChange',\n EventBuilder.TextInput.selectionChange(rangeAfter),\n );\n\n // According to the docs only multiline TextInput emits contentSizeChange event\n // @see: https://reactnative.dev/docs/textinput#oncontentsizechange\n const isMultiline = element.props.multiline === true;\n if (isMultiline) {\n const contentSize = getTextContentSize(text);\n await dispatchEvent(\n element,\n 'contentSizeChange',\n EventBuilder.TextInput.contentSizeChange(contentSize),\n );\n }\n\n // 4. Exit element\n await wait(this.config);\n await dispatchEvent(element, 'endEditing', EventBuilder.TextInput.endEditing(text));\n await dispatchEvent(element, 'blur', EventBuilder.Common.blur());\n}\n"],"mappings":";;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;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oBAAa,EACjBP,OAAO,EACP,iBAAiB,EACjBQ,0BAAY,CAACS,SAAS,CAACC,eAAe,CAACK,UAAU,CACnD,CAAC;;EAED;EACA;EACA,MAAMC,WAAW,GAAGxB,OAAO,CAACyB,KAAK,CAACC,SAAS,KAAK,IAAI;EACpD,IAAIF,WAAW,EAAE;IACf,MAAMG,WAAW,GAAG,IAAAC,yBAAkB,EAAC3B,IAAI,CAAC;IAC5C,MAAM,IAAAM,oBAAa,EACjBP,OAAO,EACP,mBAAmB,EACnBQ,0BAAY,CAACS,SAAS,CAACY,iBAAiB,CAACF,WAAW,CACtD,CAAC;EACH;;EAEA;EACA,MAAM,IAAAG,WAAI,EAAC,IAAI,CAACC,MAAM,CAAC;EACvB,MAAM,IAAAxB,oBAAa,EAACP,OAAO,EAAE,YAAY,EAAEQ,0BAAY,CAACS,SAAS,CAACe,UAAU,CAAC/B,IAAI,CAAC,CAAC;EACnF,MAAM,IAAAM,oBAAa,EAACP,OAAO,EAAE,MAAM,EAAEQ,0BAAY,CAACC,MAAM,CAACwB,IAAI,CAAC,CAAC,CAAC;AAClE","ignoreList":[]}
@@ -8,6 +8,8 @@ exports.longPress = longPress;
8
8
  exports.press = press;
9
9
  var _act = _interopRequireDefault(require("../../act"));
10
10
  var _eventHandler = require("../../event-handler");
11
+ var _componentTree = require("../../helpers/component-tree");
12
+ var _errors = require("../../helpers/errors");
11
13
  var _hostComponentNames = require("../../helpers/host-component-names");
12
14
  var _pointerEvents = require("../../helpers/pointer-events");
13
15
  var _eventBuilder = require("../event-builder");
@@ -18,11 +20,17 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
18
20
  const DEFAULT_MIN_PRESS_DURATION = exports.DEFAULT_MIN_PRESS_DURATION = 130;
19
21
  const DEFAULT_LONG_PRESS_DELAY_MS = exports.DEFAULT_LONG_PRESS_DELAY_MS = 500;
20
22
  async function press(element) {
23
+ if (!(0, _componentTree.isHostElement)(element)) {
24
+ throw new _errors.ErrorWithStack(`press() works only with host elements.`, press);
25
+ }
21
26
  await basePress(this.config, element, {
22
27
  type: 'press'
23
28
  });
24
29
  }
25
30
  async function longPress(element, options) {
31
+ if (!(0, _componentTree.isHostElement)(element)) {
32
+ throw new _errors.ErrorWithStack(`longPress() works only with host elements.`, longPress);
33
+ }
26
34
  await basePress(this.config, element, {
27
35
  type: 'longPress',
28
36
  duration: options?.duration ?? DEFAULT_LONG_PRESS_DELAY_MS
@@ -37,11 +45,10 @@ const basePress = async (config, element, options) => {
37
45
  await emitPressabilityPressEvents(config, element, options);
38
46
  return;
39
47
  }
40
- const hostParentElement = element.parent;
41
- if (!hostParentElement) {
48
+ if (!element.parent) {
42
49
  return;
43
50
  }
44
- await basePress(config, hostParentElement, options);
51
+ await basePress(config, element.parent, options);
45
52
  };
46
53
  function isEnabledHostElement(element) {
47
54
  if (!(0, _pointerEvents.isPointerEventEnabled)(element)) {
@@ -59,7 +66,7 @@ function isEnabledTouchResponder(element) {
59
66
  return (0, _pointerEvents.isPointerEventEnabled)(element) && element.props.onStartShouldSetResponder?.();
60
67
  }
61
68
  function hasPressEventHandler(element) {
62
- return (0, _eventHandler.getEventHandler)(element, 'press') || (0, _eventHandler.getEventHandler)(element, 'longPress') || (0, _eventHandler.getEventHandler)(element, 'pressIn') || (0, _eventHandler.getEventHandler)(element, 'pressOut');
69
+ return (0, _eventHandler.getEventHandlerFromProps)(element.props, 'press') || (0, _eventHandler.getEventHandlerFromProps)(element.props, 'longPress') || (0, _eventHandler.getEventHandlerFromProps)(element.props, 'pressIn') || (0, _eventHandler.getEventHandlerFromProps)(element.props, 'pressOut');
63
70
  }
64
71
 
65
72
  /**
@@ -67,29 +74,29 @@ function hasPressEventHandler(element) {
67
74
  */
68
75
  async function emitDirectPressEvents(config, element, options) {
69
76
  await (0, _utils.wait)(config);
70
- (0, _utils.dispatchEvent)(element, 'pressIn', _eventBuilder.EventBuilder.Common.touch());
77
+ await (0, _utils.dispatchEvent)(element, 'pressIn', _eventBuilder.EventBuilder.Common.touch());
71
78
  await (0, _utils.wait)(config, options.duration);
72
79
 
73
80
  // Long press events are emitted before `pressOut`.
74
81
  if (options.type === 'longPress') {
75
- (0, _utils.dispatchEvent)(element, 'longPress', _eventBuilder.EventBuilder.Common.touch());
82
+ await (0, _utils.dispatchEvent)(element, 'longPress', _eventBuilder.EventBuilder.Common.touch());
76
83
  }
77
- (0, _utils.dispatchEvent)(element, 'pressOut', _eventBuilder.EventBuilder.Common.touch());
84
+ await (0, _utils.dispatchEvent)(element, 'pressOut', _eventBuilder.EventBuilder.Common.touch());
78
85
 
79
86
  // Regular press events are emitted after `pressOut` according to the React Native docs.
80
87
  // See: https://reactnative.dev/docs/pressable#onpress
81
88
  // Experimentally for very short presses (< 130ms) `press` events are actually emitted before `onPressOut`, but
82
89
  // we will ignore that as in reality most pressed would be above the 130ms threshold.
83
90
  if (options.type === 'press') {
84
- (0, _utils.dispatchEvent)(element, 'press', _eventBuilder.EventBuilder.Common.touch());
91
+ await (0, _utils.dispatchEvent)(element, 'press', _eventBuilder.EventBuilder.Common.touch());
85
92
  }
86
93
  }
87
94
  async function emitPressabilityPressEvents(config, element, options) {
88
95
  await (0, _utils.wait)(config);
89
- (0, _utils.dispatchEvent)(element, 'responderGrant', _eventBuilder.EventBuilder.Common.responderGrant());
96
+ await (0, _utils.dispatchEvent)(element, 'responderGrant', _eventBuilder.EventBuilder.Common.responderGrant());
90
97
  const duration = options.duration ?? DEFAULT_MIN_PRESS_DURATION;
91
98
  await (0, _utils.wait)(config, duration);
92
- (0, _utils.dispatchEvent)(element, 'responderRelease', _eventBuilder.EventBuilder.Common.responderRelease());
99
+ await (0, _utils.dispatchEvent)(element, 'responderRelease', _eventBuilder.EventBuilder.Common.responderRelease());
93
100
 
94
101
  // React Native will wait for minimal delay of DEFAULT_MIN_PRESS_DURATION
95
102
  // before emitting the `pressOut` event. We need to wait here, so that