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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/build/act.d.ts +4 -3
  2. package/build/act.js +1 -6
  3. package/build/act.js.map +1 -1
  4. package/build/config.d.ts +1 -11
  5. package/build/config.js +1 -2
  6. package/build/config.js.map +1 -1
  7. package/build/fire-event.d.ts +7 -7
  8. package/build/fire-event.js +26 -4
  9. package/build/fire-event.js.map +1 -1
  10. package/build/helpers/accessibility.d.ts +14 -14
  11. package/build/helpers/accessibility.js +2 -2
  12. package/build/helpers/accessibility.js.map +1 -1
  13. package/build/helpers/component-tree.d.ts +7 -31
  14. package/build/helpers/component-tree.js +15 -73
  15. package/build/helpers/component-tree.js.map +1 -1
  16. package/build/helpers/debug.d.ts +2 -2
  17. package/build/helpers/debug.js.map +1 -1
  18. package/build/helpers/find-all.d.ts +2 -3
  19. package/build/helpers/find-all.js +5 -5
  20. package/build/helpers/find-all.js.map +1 -1
  21. package/build/helpers/format.d.ts +3 -3
  22. package/build/helpers/format.js.map +1 -1
  23. package/build/helpers/host-component-names.d.ts +7 -8
  24. package/build/helpers/host-component-names.js +7 -6
  25. package/build/helpers/host-component-names.js.map +1 -1
  26. package/build/helpers/matchers/match-accessibility-state.d.ts +2 -2
  27. package/build/helpers/matchers/match-accessibility-state.js.map +1 -1
  28. package/build/helpers/matchers/match-accessibility-value.d.ts +2 -2
  29. package/build/helpers/matchers/match-accessibility-value.js.map +1 -1
  30. package/build/helpers/matchers/match-label-text.d.ts +2 -2
  31. package/build/helpers/matchers/match-label-text.js.map +1 -1
  32. package/build/helpers/matchers/match-text-content.d.ts +2 -2
  33. package/build/helpers/matchers/match-text-content.js.map +1 -1
  34. package/build/helpers/pointer-events.d.ts +2 -2
  35. package/build/helpers/pointer-events.js +1 -2
  36. package/build/helpers/pointer-events.js.map +1 -1
  37. package/build/helpers/text-content.d.ts +2 -2
  38. package/build/helpers/text-content.js.map +1 -1
  39. package/build/helpers/text-input.d.ts +3 -3
  40. package/build/helpers/text-input.js.map +1 -1
  41. package/build/helpers/wrap-async.d.ts +1 -0
  42. package/build/helpers/wrap-async.js +1 -0
  43. package/build/helpers/wrap-async.js.map +1 -1
  44. package/build/index.d.ts +1 -0
  45. package/build/index.flow.js +0 -1
  46. package/build/index.js +11 -0
  47. package/build/index.js.map +1 -1
  48. package/build/matchers/to-be-busy.d.ts +2 -2
  49. package/build/matchers/to-be-busy.js.map +1 -1
  50. package/build/matchers/to-be-checked.d.ts +2 -2
  51. package/build/matchers/to-be-checked.js.map +1 -1
  52. package/build/matchers/to-be-disabled.d.ts +3 -3
  53. package/build/matchers/to-be-disabled.js +1 -2
  54. package/build/matchers/to-be-disabled.js.map +1 -1
  55. package/build/matchers/to-be-empty-element.d.ts +2 -2
  56. package/build/matchers/to-be-empty-element.js +1 -2
  57. package/build/matchers/to-be-empty-element.js.map +1 -1
  58. package/build/matchers/to-be-expanded.d.ts +3 -3
  59. package/build/matchers/to-be-expanded.js.map +1 -1
  60. package/build/matchers/to-be-on-the-screen.d.ts +2 -2
  61. package/build/matchers/to-be-on-the-screen.js +1 -1
  62. package/build/matchers/to-be-on-the-screen.js.map +1 -1
  63. package/build/matchers/to-be-partially-checked.d.ts +2 -2
  64. package/build/matchers/to-be-partially-checked.js.map +1 -1
  65. package/build/matchers/to-be-selected.d.ts +2 -2
  66. package/build/matchers/to-be-selected.js.map +1 -1
  67. package/build/matchers/to-be-visible.d.ts +2 -2
  68. package/build/matchers/to-be-visible.js +1 -2
  69. package/build/matchers/to-be-visible.js.map +1 -1
  70. package/build/matchers/to-contain-element.d.ts +2 -2
  71. package/build/matchers/to-contain-element.js +2 -1
  72. package/build/matchers/to-contain-element.js.map +1 -1
  73. package/build/matchers/to-have-accessibility-value.d.ts +2 -2
  74. package/build/matchers/to-have-accessibility-value.js.map +1 -1
  75. package/build/matchers/to-have-accessible-name.d.ts +2 -2
  76. package/build/matchers/to-have-accessible-name.js.map +1 -1
  77. package/build/matchers/to-have-display-value.d.ts +2 -2
  78. package/build/matchers/to-have-display-value.js.map +1 -1
  79. package/build/matchers/to-have-prop.d.ts +2 -2
  80. package/build/matchers/to-have-prop.js.map +1 -1
  81. package/build/matchers/to-have-style.d.ts +2 -2
  82. package/build/matchers/to-have-style.js.map +1 -1
  83. package/build/matchers/to-have-text-content.d.ts +2 -2
  84. package/build/matchers/to-have-text-content.js.map +1 -1
  85. package/build/matchers/types.d.ts +2 -2
  86. package/build/matchers/types.js.map +1 -1
  87. package/build/matchers/utils.d.ts +5 -5
  88. package/build/matchers/utils.js +10 -6
  89. package/build/matchers/utils.js.map +1 -1
  90. package/build/native-state.d.ts +3 -3
  91. package/build/native-state.js.map +1 -1
  92. package/build/queries/display-value.d.ts +2 -2
  93. package/build/queries/display-value.js.map +1 -1
  94. package/build/queries/hint-text.d.ts +2 -2
  95. package/build/queries/hint-text.js.map +1 -1
  96. package/build/queries/label-text.d.ts +2 -2
  97. package/build/queries/label-text.js.map +1 -1
  98. package/build/queries/make-queries.d.ts +9 -9
  99. package/build/queries/make-queries.js +2 -2
  100. package/build/queries/make-queries.js.map +1 -1
  101. package/build/queries/placeholder-text.d.ts +2 -2
  102. package/build/queries/placeholder-text.js.map +1 -1
  103. package/build/queries/role.d.ts +2 -2
  104. package/build/queries/role.js.map +1 -1
  105. package/build/queries/test-id.d.ts +2 -2
  106. package/build/queries/test-id.js.map +1 -1
  107. package/build/queries/text.d.ts +2 -2
  108. package/build/queries/text.js.map +1 -1
  109. package/build/render.d.ts +47 -85
  110. package/build/render.js +25 -69
  111. package/build/render.js.map +1 -1
  112. package/build/screen.js +1 -9
  113. package/build/screen.js.map +1 -1
  114. package/build/tsconfig.release.tsbuildinfo +1 -1
  115. package/build/user-event/clear.d.ts +2 -2
  116. package/build/user-event/clear.js.map +1 -1
  117. package/build/user-event/index.d.ts +7 -7
  118. package/build/user-event/index.js.map +1 -1
  119. package/build/user-event/paste.d.ts +2 -2
  120. package/build/user-event/paste.js.map +1 -1
  121. package/build/user-event/press/press.d.ts +3 -3
  122. package/build/user-event/press/press.js +1 -2
  123. package/build/user-event/press/press.js.map +1 -1
  124. package/build/user-event/scroll/scroll-to.d.ts +2 -2
  125. package/build/user-event/scroll/scroll-to.js.map +1 -1
  126. package/build/user-event/setup/setup.d.ts +7 -7
  127. package/build/user-event/setup/setup.js.map +1 -1
  128. package/build/user-event/type/type.d.ts +3 -3
  129. package/build/user-event/type/type.js.map +1 -1
  130. package/build/user-event/utils/dispatch-event.d.ts +2 -2
  131. package/build/user-event/utils/dispatch-event.js.map +1 -1
  132. package/build/within.d.ts +20 -36
  133. package/build/within.js +7 -11
  134. package/build/within.js.map +1 -1
  135. package/package.json +10 -11
  136. package/typings/index.flow.js +0 -1
  137. package/build/helpers/string-validation.d.ts +0 -2
  138. package/build/helpers/string-validation.js +0 -31
  139. package/build/helpers/string-validation.js.map +0 -1
  140. package/build/queries/unsafe-props.d.ts +0 -16
  141. package/build/queries/unsafe-props.js +0 -49
  142. package/build/queries/unsafe-props.js.map +0 -1
  143. package/build/queries/unsafe-type.d.ts +0 -9
  144. package/build/queries/unsafe-type.js +0 -47
  145. package/build/queries/unsafe-type.js.map +0 -1
  146. package/build/render-act.d.ts +0 -2
  147. package/build/render-act.js +0 -22
  148. package/build/render-act.js.map +0 -1
@@ -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 { ReactTestInstance } from 'react-test-renderer';\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 { UserEventInstance } from './setup';\nimport { dispatchEvent, getTextContentSize, wait } from './utils';\n\nexport async function paste(\n this: UserEventInstance,\n element: ReactTestInstance,\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":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GA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Y,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 { HostElement } from 'universal-test-renderer';\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 { 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":";;;;;;AACA,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,sBAA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XP,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,9 +1,9 @@
1
- import { ReactTestInstance } from 'react-test-renderer';
1
+ import { HostElement } from 'universal-test-renderer';
2
2
  import { UserEventInstance } from '../setup';
3
3
  export declare const DEFAULT_MIN_PRESS_DURATION = 130;
4
4
  export declare const DEFAULT_LONG_PRESS_DELAY_MS = 500;
5
5
  export interface PressOptions {
6
6
  duration?: number;
7
7
  }
8
- export declare function press(this: UserEventInstance, element: ReactTestInstance): Promise<void>;
9
- export declare function longPress(this: UserEventInstance, element: ReactTestInstance, options?: PressOptions): Promise<void>;
8
+ export declare function press(this: UserEventInstance, element: HostElement): Promise<void>;
9
+ export declare function longPress(this: UserEventInstance, element: HostElement, options?: PressOptions): Promise<void>;
@@ -7,7 +7,6 @@ exports.DEFAULT_MIN_PRESS_DURATION = exports.DEFAULT_LONG_PRESS_DELAY_MS = void
7
7
  exports.longPress = longPress;
8
8
  exports.press = press;
9
9
  var _act = _interopRequireDefault(require("../../act"));
10
- var _componentTree = require("../../helpers/component-tree");
11
10
  var _textInput = require("../../helpers/text-input");
12
11
  var _pointerEvents = require("../../helpers/pointer-events");
13
12
  var _hostComponentNames = require("../../helpers/host-component-names");
@@ -42,7 +41,7 @@ const basePress = async (config, element, options) => {
42
41
  await emitPressablePressEvents(config, element, options);
43
42
  return;
44
43
  }
45
- const hostParentElement = (0, _componentTree.getHostParent)(element);
44
+ const hostParentElement = element.parent;
46
45
  if (!hostParentElement) {
47
46
  return;
48
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"press.js","names":["_act","_interopRequireDefault","require","_componentTree","_textInput","_pointerEvents","_hostComponentNames","_eventBuilder","_utils","e","__esModule","default","DEFAULT_MIN_PRESS_DURATION","exports","DEFAULT_LONG_PRESS_DELAY_MS","press","element","basePress","config","type","longPress","options","duration","isPressableText","emitTextPressEvents","isEditableTextInput","isPointerEventEnabled","emitTextInputPressEvents","isEnabledTouchResponder","emitPressablePressEvents","hostParentElement","getHostParent","wait","dispatchEvent","EventBuilder","Common","responderGrant","responderRelease","act","props","onStartShouldSetResponder","hasPressEventHandler","Boolean","onPress","onLongPress","onPressIn","onPressOut","isHostText","disabled","touch"],"sources":["../../../src/user-event/press/press.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport act from '../../act';\nimport { getHostParent } from '../../helpers/component-tree';\nimport { isEditableTextInput } from '../../helpers/text-input';\nimport { isPointerEventEnabled } from '../../helpers/pointer-events';\nimport { isHostText } from '../../helpers/host-component-names';\nimport { EventBuilder } from '../event-builder';\nimport { UserEventConfig, UserEventInstance } from '../setup';\nimport { dispatchEvent, wait } from '../utils';\n\n// These are constants defined in the React Native repo\n// See: https://github.com/facebook/react-native/blob/50e38cc9f1e6713228a91ad50f426c4f65e65e1a/packages/react-native/Libraries/Pressability/Pressability.js#L264\nexport const DEFAULT_MIN_PRESS_DURATION = 130;\nexport const DEFAULT_LONG_PRESS_DELAY_MS = 500;\n\nexport interface PressOptions {\n duration?: number;\n}\n\nexport async function press(this: UserEventInstance, element: ReactTestInstance): Promise<void> {\n await basePress(this.config, element, {\n type: 'press',\n });\n}\n\nexport async function longPress(\n this: UserEventInstance,\n element: ReactTestInstance,\n options?: PressOptions,\n): Promise<void> {\n await basePress(this.config, element, {\n type: 'longPress',\n duration: options?.duration ?? DEFAULT_LONG_PRESS_DELAY_MS,\n });\n}\n\ninterface BasePressOptions {\n type: 'press' | 'longPress';\n duration?: number;\n}\n\nconst basePress = async (\n config: UserEventConfig,\n element: ReactTestInstance,\n options: BasePressOptions,\n): Promise<void> => {\n if (isPressableText(element)) {\n await emitTextPressEvents(config, element, options);\n return;\n }\n\n if (isEditableTextInput(element) && isPointerEventEnabled(element)) {\n await emitTextInputPressEvents(config, element, options);\n return;\n }\n\n if (isEnabledTouchResponder(element)) {\n await emitPressablePressEvents(config, element, options);\n return;\n }\n\n const hostParentElement = getHostParent(element);\n if (!hostParentElement) {\n return;\n }\n\n await basePress(config, hostParentElement, options);\n};\n\nconst emitPressablePressEvents = async (\n config: UserEventConfig,\n element: ReactTestInstance,\n options: BasePressOptions,\n) => {\n await wait(config);\n\n dispatchEvent(element, 'responderGrant', EventBuilder.Common.responderGrant());\n\n const duration = options.duration ?? DEFAULT_MIN_PRESS_DURATION;\n await wait(config, duration);\n\n dispatchEvent(element, 'responderRelease', EventBuilder.Common.responderRelease());\n\n // React Native will wait for minimal delay of DEFAULT_MIN_PRESS_DURATION\n // before emitting the `pressOut` event. We need to wait here, so that\n // `press()` function does not return before that.\n if (DEFAULT_MIN_PRESS_DURATION - duration > 0) {\n await act(async () => {\n await wait(config, DEFAULT_MIN_PRESS_DURATION - duration);\n });\n }\n};\n\nconst isEnabledTouchResponder = (element: ReactTestInstance) => {\n return isPointerEventEnabled(element) && element.props.onStartShouldSetResponder?.();\n};\n\nconst isPressableText = (element: ReactTestInstance) => {\n const hasPressEventHandler = Boolean(\n element.props.onPress ||\n element.props.onLongPress ||\n element.props.onPressIn ||\n element.props.onPressOut,\n );\n\n return (\n isHostText(element) &&\n isPointerEventEnabled(element) &&\n !element.props.disabled &&\n hasPressEventHandler\n );\n};\n\n/**\n * Dispatches a press event sequence for Text.\n */\nasync function emitTextPressEvents(\n config: UserEventConfig,\n element: ReactTestInstance,\n options: BasePressOptions,\n) {\n await wait(config);\n dispatchEvent(element, 'pressIn', EventBuilder.Common.touch());\n\n await wait(config, options.duration);\n\n // Long press events are emitted before `pressOut`.\n if (options.type === 'longPress') {\n dispatchEvent(element, 'longPress', EventBuilder.Common.touch());\n }\n\n dispatchEvent(element, 'pressOut', EventBuilder.Common.touch());\n\n // Regular press events are emitted after `pressOut` according to the React Native docs.\n // See: https://reactnative.dev/docs/pressable#onpress\n // Experimentally for very short presses (< 130ms) `press` events are actually emitted before `onPressOut`, but\n // we will ignore that as in reality most pressed would be above the 130ms threshold.\n if (options.type === 'press') {\n dispatchEvent(element, 'press', EventBuilder.Common.touch());\n }\n}\n\n/**\n * Dispatches a press event sequence for TextInput.\n */\nasync function emitTextInputPressEvents(\n config: UserEventConfig,\n element: ReactTestInstance,\n options: BasePressOptions,\n) {\n await wait(config);\n dispatchEvent(element, 'pressIn', EventBuilder.Common.touch());\n\n // Note: TextInput does not have `onPress`/`onLongPress` props.\n\n await wait(config, options.duration);\n dispatchEvent(element, 'pressOut', EventBuilder.Common.touch());\n}\n"],"mappings":";;;;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AAA+C,SAAAD,uBAAAQ,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE/C;AACA;AACO,MAAMG,0BAA0B,GAAAC,OAAA,CAAAD,0BAAA,GAAG,GAAG;AACtC,MAAME,2BAA2B,GAAAD,OAAA,CAAAC,2BAAA,GAAG,GAAG;AAMvC,eAAeC,KAAKA,CAA0BC,OAA0B,EAAiB;EAC9F,MAAMC,SAAS,CAAC,IAAI,CAACC,MAAM,EAAEF,OAAO,EAAE;IACpCG,IAAI,EAAE;EACR,CAAC,CAAC;AACJ;AAEO,eAAeC,SAAS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K,WAAW,EAAE;IAChC,IAAAc,oBAAa,EAACjB,OAAO,EAAE,WAAW,EAAEkB,0BAAY,CAACC,MAAM,CAACc,KAAK,CAAC,CAAC,CAAC;EAClE;EAEA,IAAAhB,oBAAa,EAACjB,OAAO,EAAE,UAAU,EAAEkB,0BAAY,CAACC,MAAM,CAACc,KAAK,CAAC,CAAC,CAAC;;EAE/D;EACA;EACA;EACA;EACA,IAAI5B,OAAO,CAACF,IAAI,KAAK,OAAO,EAAE;IAC5B,IAAAc,oBAAa,EAACjB,OAAO,EAAE,OAAO,EAAEkB,0BAAY,CAACC,MAAM,CAACc,KAAK,CAAC,CAAC,CAAC;EAC9D;AACF;;AAEA;AACA;AACA;AACA,eAAetB,wBAAwBA,CACrCT,MAAuB,EACvBF,OAA0B,EAC1BK,OAAyB,EACzB;EACA,MAAM,IAAAW,WAAI,EAACd,MAAM,CAAC;EAClB,IAAAe,oBAAa,EAACjB,OAAO,EAAE,SAAS,EAAEkB,0BAAY,CAACC,MAAM,CAACc,KAAK,CAAC,CAAC,CAAC;;EAE9D;;EAEA,MAAM,IAAAjB,WAAI,EAACd,MAAM,EAAEG,OAAO,CAACC,QAAQ,CAAC;EACpC,IAAAW,oBAAa,EAACjB,OAAO,EAAE,UAAU,EAAEkB,0BAAY,CAACC,MAAM,CAACc,KAAK,CAAC,CAAC,CAAC;AACjE","ignoreList":[]}
1
+ {"version":3,"file":"press.js","names":["_act","_interopRequireDefault","require","_textInput","_pointerEvents","_hostComponentNames","_eventBuilder","_utils","e","__esModule","default","DEFAULT_MIN_PRESS_DURATION","exports","DEFAULT_LONG_PRESS_DELAY_MS","press","element","basePress","config","type","longPress","options","duration","isPressableText","emitTextPressEvents","isEditableTextInput","isPointerEventEnabled","emitTextInputPressEvents","isEnabledTouchResponder","emitPressablePressEvents","hostParentElement","parent","wait","dispatchEvent","EventBuilder","Common","responderGrant","responderRelease","act","props","onStartShouldSetResponder","hasPressEventHandler","Boolean","onPress","onLongPress","onPressIn","onPressOut","isHostText","disabled","touch"],"sources":["../../../src/user-event/press/press.ts"],"sourcesContent":["import { HostElement } from 'universal-test-renderer';\nimport act from '../../act';\nimport { isEditableTextInput } from '../../helpers/text-input';\nimport { isPointerEventEnabled } from '../../helpers/pointer-events';\nimport { isHostText } from '../../helpers/host-component-names';\nimport { EventBuilder } from '../event-builder';\nimport { UserEventConfig, UserEventInstance } from '../setup';\nimport { dispatchEvent, wait } from '../utils';\n\n// These are constants defined in the React Native repo\n// See: https://github.com/facebook/react-native/blob/50e38cc9f1e6713228a91ad50f426c4f65e65e1a/packages/react-native/Libraries/Pressability/Pressability.js#L264\nexport const DEFAULT_MIN_PRESS_DURATION = 130;\nexport const DEFAULT_LONG_PRESS_DELAY_MS = 500;\n\nexport interface PressOptions {\n duration?: number;\n}\n\nexport async function press(this: UserEventInstance, element: HostElement): Promise<void> {\n await basePress(this.config, element, {\n type: 'press',\n });\n}\n\nexport async function longPress(\n this: UserEventInstance,\n element: HostElement,\n options?: PressOptions,\n): Promise<void> {\n await basePress(this.config, element, {\n type: 'longPress',\n duration: options?.duration ?? DEFAULT_LONG_PRESS_DELAY_MS,\n });\n}\n\ninterface BasePressOptions {\n type: 'press' | 'longPress';\n duration?: number;\n}\n\nconst basePress = async (\n config: UserEventConfig,\n element: HostElement,\n options: BasePressOptions,\n): Promise<void> => {\n if (isPressableText(element)) {\n await emitTextPressEvents(config, element, options);\n return;\n }\n\n if (isEditableTextInput(element) && isPointerEventEnabled(element)) {\n await emitTextInputPressEvents(config, element, options);\n return;\n }\n\n if (isEnabledTouchResponder(element)) {\n await emitPressablePressEvents(config, element, options);\n return;\n }\n\n const hostParentElement = element.parent;\n if (!hostParentElement) {\n return;\n }\n\n await basePress(config, hostParentElement, options);\n};\n\nconst emitPressablePressEvents = async (\n config: UserEventConfig,\n element: HostElement,\n options: BasePressOptions,\n) => {\n await wait(config);\n\n dispatchEvent(element, 'responderGrant', EventBuilder.Common.responderGrant());\n\n const duration = options.duration ?? DEFAULT_MIN_PRESS_DURATION;\n await wait(config, duration);\n\n dispatchEvent(element, 'responderRelease', EventBuilder.Common.responderRelease());\n\n // React Native will wait for minimal delay of DEFAULT_MIN_PRESS_DURATION\n // before emitting the `pressOut` event. We need to wait here, so that\n // `press()` function does not return before that.\n if (DEFAULT_MIN_PRESS_DURATION - duration > 0) {\n await act(async () => {\n await wait(config, DEFAULT_MIN_PRESS_DURATION - duration);\n });\n }\n};\n\nconst isEnabledTouchResponder = (element: HostElement) => {\n return isPointerEventEnabled(element) && element.props.onStartShouldSetResponder?.();\n};\n\nconst isPressableText = (element: HostElement) => {\n const hasPressEventHandler = Boolean(\n element.props.onPress ||\n element.props.onLongPress ||\n element.props.onPressIn ||\n element.props.onPressOut,\n );\n\n return (\n isHostText(element) &&\n isPointerEventEnabled(element) &&\n !element.props.disabled &&\n hasPressEventHandler\n );\n};\n\n/**\n * Dispatches a press event sequence for Text.\n */\nasync function emitTextPressEvents(\n config: UserEventConfig,\n element: HostElement,\n options: BasePressOptions,\n) {\n await wait(config);\n dispatchEvent(element, 'pressIn', EventBuilder.Common.touch());\n\n await wait(config, options.duration);\n\n // Long press events are emitted before `pressOut`.\n if (options.type === 'longPress') {\n dispatchEvent(element, 'longPress', EventBuilder.Common.touch());\n }\n\n dispatchEvent(element, 'pressOut', EventBuilder.Common.touch());\n\n // Regular press events are emitted after `pressOut` according to the React Native docs.\n // See: https://reactnative.dev/docs/pressable#onpress\n // Experimentally for very short presses (< 130ms) `press` events are actually emitted before `onPressOut`, but\n // we will ignore that as in reality most pressed would be above the 130ms threshold.\n if (options.type === 'press') {\n dispatchEvent(element, 'press', EventBuilder.Common.touch());\n }\n}\n\n/**\n * Dispatches a press event sequence for TextInput.\n */\nasync function emitTextInputPressEvents(\n config: UserEventConfig,\n element: HostElement,\n options: BasePressOptions,\n) {\n await wait(config);\n dispatchEvent(element, 'pressIn', EventBuilder.Common.touch());\n\n // Note: TextInput does not have `onPress`/`onLongPress` props.\n\n await wait(config, options.duration);\n dispatchE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E,SAAS,EAAEkB,0BAAY,CAACC,MAAM,CAACc,KAAK,CAAC,CAAC,CAAC;;EAE9D;;EAEA,MAAM,IAAAjB,WAAI,EAACd,MAAM,EAAEG,OAAO,CAACC,QAAQ,CAAC;EACpC,IAAAW,oBAAa,EAACjB,OAAO,EAAE,UAAU,EAAEkB,0BAAY,CAACC,MAAM,CAACc,KAAK,CAAC,CAAC,CAAC;AACjE","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { ReactTestInstance } from 'react-test-renderer';
1
+ import { HostElement } from 'universal-test-renderer';
2
2
  import { UserEventInstance } from '../setup';
3
3
  import { Size } from '../../types';
4
4
  interface CommonScrollToOptions {
@@ -18,5 +18,5 @@ export interface HorizontalScrollToOptions extends CommonScrollToOptions {
18
18
  momentumY?: never;
19
19
  }
20
20
  export type ScrollToOptions = VerticalScrollToOptions | HorizontalScrollToOptions;
21
- export declare function scrollTo(this: UserEventInstance, element: ReactTestInstance, options: ScrollToOptions): Promise<void>;
21
+ export declare function scrollTo(this: UserEventInstance, element: HostElement, options: ScrollToOptions): Promise<void>;
22
22
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"scroll-to.js","names":["_jestMatcherUtils","require","_eventBuilder","_errors","_hostComponentNames","_object","_nativeState","_utils","_utils2","scrollTo","element","options","isHostScrollView","ErrorWithStack","type","ensureScrollViewDirection","dispatchEvent","contentSize","width","height","initialOffset","nativeState","contentOffsetForElement","get","x","y","dragSteps","createScrollSteps","linearInterpolator","emitDragScrollEvents","config","momentumStart","at","momentumSteps","momentumY","momentumX","inertialInterpolator","emitMomentumScrollEvents","finalOffset","set","scrollSteps","scrollOptions","length","wait","EventBuilder","ScrollView","scroll","i","lastStep","isVerticalScrollView","props","horizontal","hasHorizontalScrollOptions","undefined","stringify","pick","hasVerticalScrollOptions"],"sources":["../../../src/user-event/scroll/scroll-to.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { stringify } from 'jest-matcher-utils';\nimport { UserEventConfig, UserEventInstance } from '../setup';\nimport { EventBuilder } from '../event-builder';\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { isHostScrollView } from '../../helpers/host-component-names';\nimport { pick } from '../../helpers/object';\nimport { nativeState } from '../../native-state';\nimport { Point, Size } from '../../types';\nimport { dispatchEvent, wait } from '../utils';\nimport { createScrollSteps, inertialInterpolator, linearInterpolator } from './utils';\n\ninterface CommonScrollToOptions {\n contentSize?: Size;\n layoutMeasurement?: Size;\n}\n\nexport interface VerticalScrollToOptions extends CommonScrollToOptions {\n y: number;\n momentumY?: number;\n\n // Vertical scroll should not contain horizontal scroll part.\n x?: never;\n momentumX?: never;\n}\n\nexport interface HorizontalScrollToOptions extends CommonScrollToOptions {\n x: number;\n momentumX?: number;\n\n // Horizontal scroll should not contain vertical scroll part.\n y?: never;\n momentumY?: never;\n}\n\nexport type ScrollToOptions = VerticalScrollToOptions | HorizontalScrollToOptions;\n\nexport async function scrollTo(\n this: UserEventInstance,\n element: ReactTestInstance,\n options: ScrollToOptions,\n): Promise<void> {\n if (!isHostScrollView(element)) {\n throw new ErrorWithStack(\n `scrollTo() works only with host \"ScrollView\" elements. Passed element has type \"${element.type}\".`,\n scrollTo,\n );\n }\n\n ensureScrollViewDirection(element, options);\n\n dispatchEvent(\n element,\n 'contentSizeChange',\n options.contentSize?.width ?? 0,\n options.contentSize?.height ?? 0,\n );\n\n const initialOffset = nativeState.contentOffsetForElement.get(element) ?? { x: 0, y: 0 };\n const dragSteps = createScrollSteps(\n { y: options.y, x: options.x },\n initialOffset,\n linearInterpolator,\n );\n await emitDragScrollEvents(this.config, element, dragSteps, options);\n\n const momentumStart = dragSteps.at(-1) ?? initialOffset;\n const momentumSteps = createScrollSteps(\n { y: options.momentumY, x: options.momentumX },\n momentumStart,\n inertialInterpolator,\n );\n await emitMomentumScrollEvents(this.config, element, momentumSteps, options);\n\n const finalOffset = momentumSteps.at(-1) ?? dragSteps.at(-1) ?? initialOffset;\n nativeState.contentOffsetForElement.set(element, finalOffset);\n}\n\nasync function emitDragScrollEvents(\n config: UserEventConfig,\n element: ReactTestInstance,\n scrollSteps: Point[],\n scrollOptions: ScrollToOptions,\n) {\n if (scrollSteps.length === 0) {\n return;\n }\n\n await wait(config);\n dispatchEvent(\n element,\n 'scrollBeginDrag',\n EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions),\n );\n\n // Note: experimentally, in case of drag scroll the last scroll step\n // will not trigger `scroll` event.\n // See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events\n for (let i = 1; i < scrollSteps.length - 1; i += 1) {\n await wait(config);\n dispatchEvent(element, 'scroll', EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions));\n }\n\n await wait(config);\n const lastStep = scrollSteps.at(-1);\n dispatchEvent(element, 'scrollEndDrag', EventBuilder.ScrollView.scroll(lastStep, scrollOptions));\n}\n\nasync function emitMomentumScrollEvents(\n config: UserEventConfig,\n element: ReactTestInstance,\n scrollSteps: Point[],\n scrollOptions: ScrollToOptions,\n) {\n if (scrollSteps.length === 0) {\n return;\n }\n\n await wait(config);\n dispatchEvent(\n element,\n 'momentumScrollBegin',\n EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions),\n );\n\n // Note: experimentally, in case of momentum scroll the last scroll step\n // will trigger `scroll` event.\n // See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events\n for (let i = 1; i < scrollSteps.length; i += 1) {\n await wait(config);\n dispatchEvent(element, 'scroll', EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions));\n }\n\n await wait(config);\n const lastStep = scrollSteps.at(-1);\n dispatchEvent(\n element,\n 'momentumScrollEnd',\n EventBuilder.ScrollView.scroll(lastStep, scrollOptions),\n );\n}\n\nfunction ensureScrollViewDirection(element: ReactTestInstance, options: ScrollToOptions) {\n const isVerticalScrollView = element.props.horizontal !== true;\n\n const hasHorizontalScrollOptions = options.x !== undefined || options.momentumX !== undefined;\n if (isVerticalScrollView && hasHorizontalScrollOptions) {\n throw new ErrorWithStack(\n `scrollTo() expected only vertical scroll options: \"y\" and \"momentumY\" for vertical \"ScrollView\" element but received ${stringify(\n pick(options, ['x', 'momentumX']),\n )}`,\n scrollTo,\n );\n }\n\n const hasVerticalScrollOptions = options.y !== undefined || options.momentumY !== undefined;\n if (!isVerticalScrollView && hasVerticalScrollOptions) {\n throw new ErrorWithStack(\n `scrollTo() expected only horizontal scroll options: \"x\" and \"momentumX\" for horizontal \"ScrollView\" element but received ${stringify(\n pick(options, ['y', 'momentumY']),\n )}`,\n scrollTo,\n );\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AA2BO,eAAeQ,QAAQA,CAE5BC,OAA0B,EAC1BC,OAAwB,EACT;EACf,IAAI,CAAC,IAAAC,oCAAgB,EAACF,OAAO,CAAC,EAAE;IAC9B,MAAM,IAAIG,sBAAc,CACtB,mFAAmFH,OAAO,CAACI,IAAI,IAAI,EACnGL,QACF,CAAC;EACH;EAEAM,yBAAyB,CAACL,OAAO,EAAEC,OAAO,CAAC;EAE3C,IAAAK,oBAAa,EACXN,OAAO,EACP,mBAAmB,EACnBC,OAAO,CAACM,WAAW,EAAEC,KAAK,IAAI,CAAC,EAC/BP,OAAO,CAACM,WAAW,EAAEE,MAAM,IAAI,CACjC,CAAC;EAED,MAAMC,aAAa,GAAGC,wBAAW,CAACC,uBAAuB,CAACC,GAAG,CAACb,OAAO,CAAC,IAAI;IAAEc,CAAC,EAAE,CAAC;IAAEC,CAAC,EAAE;EAAE,CAAC;EACxF,MAAMC,SAAS,GAAG,IAAAC,yBAAiB,EACjC;IAAEF,CAAC,EAAEd,OA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AmB,EACnBkC,0BAAY,CAACC,UAAU,CAACC,MAAM,CAACE,QAAQ,EAAEP,aAAa,CACxD,CAAC;AACH;AAEA,SAAS1B,yBAAyBA,CAACL,OAA0B,EAAEC,OAAwB,EAAE;EACvF,MAAMsC,oBAAoB,GAAGvC,OAAO,CAACwC,KAAK,CAACC,UAAU,KAAK,IAAI;EAE9D,MAAMC,0BAA0B,GAAGzC,OAAO,CAACa,CAAC,KAAK6B,SAAS,IAAI1C,OAAO,CAACwB,SAAS,KAAKkB,SAAS;EAC7F,IAAIJ,oBAAoB,IAAIG,0BAA0B,EAAE;IACtD,MAAM,IAAIvC,sBAAc,CACtB,wHAAwH,IAAAyC,2BAAS,EAC/H,IAAAC,YAAI,EAAC5C,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,CAClC,CAAC,EAAE,EACHF,QACF,CAAC;EACH;EAEA,MAAM+C,wBAAwB,GAAG7C,OAAO,CAACc,CAAC,KAAK4B,SAAS,IAAI1C,OAAO,CAACuB,SAAS,KAAKmB,SAAS;EAC3F,IAAI,CAACJ,oBAAoB,IAAIO,wBAAwB,EAAE;IACrD,MAAM,IAAI3C,sBAAc,CACtB,4HAA4H,IAAAyC,2BAAS,EACnI,IAAAC,YAAI,EAAC5C,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,CAClC,CAAC,EAAE,EACHF,QACF,CAAC;EACH;AACF","ignoreList":[]}
1
+ {"version":3,"file":"scroll-to.js","names":["_jestMatcherUtils","require","_eventBuilder","_errors","_hostComponentNames","_object","_nativeState","_utils","_utils2","scrollTo","element","options","isHostScrollView","ErrorWithStack","type","ensureScrollViewDirection","dispatchEvent","contentSize","width","height","initialOffset","nativeState","contentOffsetForElement","get","x","y","dragSteps","createScrollSteps","linearInterpolator","emitDragScrollEvents","config","momentumStart","at","momentumSteps","momentumY","momentumX","inertialInterpolator","emitMomentumScrollEvents","finalOffset","set","scrollSteps","scrollOptions","length","wait","EventBuilder","ScrollView","scroll","i","lastStep","isVerticalScrollView","props","horizontal","hasHorizontalScrollOptions","undefined","stringify","pick","hasVerticalScrollOptions"],"sources":["../../../src/user-event/scroll/scroll-to.ts"],"sourcesContent":["import { stringify } from 'jest-matcher-utils';\nimport { HostElement } from 'universal-test-renderer';\nimport { UserEventConfig, UserEventInstance } from '../setup';\nimport { EventBuilder } from '../event-builder';\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { isHostScrollView } from '../../helpers/host-component-names';\nimport { pick } from '../../helpers/object';\nimport { nativeState } from '../../native-state';\nimport { Point, Size } from '../../types';\nimport { dispatchEvent, wait } from '../utils';\nimport { createScrollSteps, inertialInterpolator, linearInterpolator } from './utils';\n\ninterface CommonScrollToOptions {\n contentSize?: Size;\n layoutMeasurement?: Size;\n}\n\nexport interface VerticalScrollToOptions extends CommonScrollToOptions {\n y: number;\n momentumY?: number;\n\n // Vertical scroll should not contain horizontal scroll part.\n x?: never;\n momentumX?: never;\n}\n\nexport interface HorizontalScrollToOptions extends CommonScrollToOptions {\n x: number;\n momentumX?: number;\n\n // Horizontal scroll should not contain vertical scroll part.\n y?: never;\n momentumY?: never;\n}\n\nexport type ScrollToOptions = VerticalScrollToOptions | HorizontalScrollToOptions;\n\nexport async function scrollTo(\n this: UserEventInstance,\n element: HostElement,\n options: ScrollToOptions,\n): Promise<void> {\n if (!isHostScrollView(element)) {\n throw new ErrorWithStack(\n `scrollTo() works only with host \"ScrollView\" elements. Passed element has type \"${element.type}\".`,\n scrollTo,\n );\n }\n\n ensureScrollViewDirection(element, options);\n\n dispatchEvent(\n element,\n 'contentSizeChange',\n options.contentSize?.width ?? 0,\n options.contentSize?.height ?? 0,\n );\n\n const initialOffset = nativeState.contentOffsetForElement.get(element) ?? { x: 0, y: 0 };\n const dragSteps = createScrollSteps(\n { y: options.y, x: options.x },\n initialOffset,\n linearInterpolator,\n );\n await emitDragScrollEvents(this.config, element, dragSteps, options);\n\n const momentumStart = dragSteps.at(-1) ?? initialOffset;\n const momentumSteps = createScrollSteps(\n { y: options.momentumY, x: options.momentumX },\n momentumStart,\n inertialInterpolator,\n );\n await emitMomentumScrollEvents(this.config, element, momentumSteps, options);\n\n const finalOffset = momentumSteps.at(-1) ?? dragSteps.at(-1) ?? initialOffset;\n nativeState.contentOffsetForElement.set(element, finalOffset);\n}\n\nasync function emitDragScrollEvents(\n config: UserEventConfig,\n element: HostElement,\n scrollSteps: Point[],\n scrollOptions: ScrollToOptions,\n) {\n if (scrollSteps.length === 0) {\n return;\n }\n\n await wait(config);\n dispatchEvent(\n element,\n 'scrollBeginDrag',\n EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions),\n );\n\n // Note: experimentally, in case of drag scroll the last scroll step\n // will not trigger `scroll` event.\n // See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events\n for (let i = 1; i < scrollSteps.length - 1; i += 1) {\n await wait(config);\n dispatchEvent(element, 'scroll', EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions));\n }\n\n await wait(config);\n const lastStep = scrollSteps.at(-1);\n dispatchEvent(element, 'scrollEndDrag', EventBuilder.ScrollView.scroll(lastStep, scrollOptions));\n}\n\nasync function emitMomentumScrollEvents(\n config: UserEventConfig,\n element: HostElement,\n scrollSteps: Point[],\n scrollOptions: ScrollToOptions,\n) {\n if (scrollSteps.length === 0) {\n return;\n }\n\n await wait(config);\n dispatchEvent(\n element,\n 'momentumScrollBegin',\n EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions),\n );\n\n // Note: experimentally, in case of momentum scroll the last scroll step\n // will trigger `scroll` event.\n // See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events\n for (let i = 1; i < scrollSteps.length; i += 1) {\n await wait(config);\n dispatchEvent(element, 'scroll', EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions));\n }\n\n await wait(config);\n const lastStep = scrollSteps.at(-1);\n dispatchEvent(\n element,\n 'momentumScrollEnd',\n EventBuilder.ScrollView.scroll(lastStep, scrollOptions),\n );\n}\n\nfunction ensureScrollViewDirection(element: HostElement, options: ScrollToOptions) {\n const isVerticalScrollView = element.props.horizontal !== true;\n\n const hasHorizontalScrollOptions = options.x !== undefined || options.momentumX !== undefined;\n if (isVerticalScrollView && hasHorizontalScrollOptions) {\n throw new ErrorWithStack(\n `scrollTo() expected only vertical scroll options: \"y\" and \"momentumY\" for vertical \"ScrollView\" element but received ${stringify(\n pick(options, ['x', 'momentumX']),\n )}`,\n scrollTo,\n );\n }\n\n const hasVerticalScrollOptions = options.y !== undefined || options.momentumY !== undefined;\n if (!isVerticalScrollView && hasVerticalScrollOptions) {\n throw new ErrorWithStack(\n `scrollTo() expected only horizontal scroll options: \"x\" and \"momentumX\" for horizontal \"ScrollView\" element but received ${stringify(\n pick(options, ['y', 'momentumY']),\n )}`,\n scrollTo,\n );\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AAGA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AA2BO,eAAeQ,QAAQA,CAE5BC,OAAoB,EACpBC,OAAwB,EACT;EACf,IAAI,CAAC,IAAAC,oCAAgB,EAACF,OAAO,CAAC,EAAE;IAC9B,MAAM,IAAIG,sBAAc,CACtB,mFAAmFH,OAAO,CAACI,IAAI,IAAI,EACnGL,QACF,CAAC;EACH;EAEAM,yBAAyB,CAACL,OAAO,EAAEC,OAAO,CAAC;EAE3C,IAAAK,oBAAa,EACXN,OAAO,EACP,mBAAmB,EACnBC,OAAO,CAACM,WAAW,EAAEC,KAAK,IAAI,CAAC,EAC/BP,OAAO,CAACM,WAAW,EAAEE,MAAM,IAAI,CACjC,CAAC;EAED,MAAMC,aAAa,GAAGC,wBAAW,CAACC,uBAAuB,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jG;EAEA,MAAM,IAAAE,WAAI,EAACb,MAAM,CAAC;EAClB,MAAMkB,QAAQ,GAAGR,WAAW,CAACR,EAAE,CAAC,CAAC,CAAC,CAAC;EACnC,IAAAhB,oBAAa,EACXN,OAAO,EACP,mBAAmB,EACnBkC,0BAAY,CAACC,UAAU,CAACC,MAAM,CAACE,QAAQ,EAAEP,aAAa,CACxD,CAAC;AACH;AAEA,SAAS1B,yBAAyBA,CAACL,OAAoB,EAAEC,OAAwB,EAAE;EACjF,MAAMsC,oBAAoB,GAAGvC,OAAO,CAACwC,KAAK,CAACC,UAAU,KAAK,IAAI;EAE9D,MAAMC,0BAA0B,GAAGzC,OAAO,CAACa,CAAC,KAAK6B,SAAS,IAAI1C,OAAO,CAACwB,SAAS,KAAKkB,SAAS;EAC7F,IAAIJ,oBAAoB,IAAIG,0BAA0B,EAAE;IACtD,MAAM,IAAIvC,sBAAc,CACtB,wHAAwH,IAAAyC,2BAAS,EAC/H,IAAAC,YAAI,EAAC5C,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,CAClC,CAAC,EAAE,EACHF,QACF,CAAC;EACH;EAEA,MAAM+C,wBAAwB,GAAG7C,OAAO,CAACc,CAAC,KAAK4B,SAAS,IAAI1C,OAAO,CAACuB,SAAS,KAAKmB,SAAS;EAC3F,IAAI,CAACJ,oBAAoB,IAAIO,wBAAwB,EAAE;IACrD,MAAM,IAAI3C,sBAAc,CACtB,4HAA4H,IAAAyC,2BAAS,EACnI,IAAAC,YAAI,EAAC5C,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,CAClC,CAAC,EAAE,EACHF,QACF,CAAC;EACH;AACF","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { ReactTestInstance } from 'react-test-renderer';
1
+ import { HostElement } from 'universal-test-renderer';
2
2
  import { PressOptions } from '../press';
3
3
  import { ScrollToOptions } from '../scroll';
4
4
  import { TypeOptions } from '../type';
@@ -44,8 +44,8 @@ export interface UserEventConfig {
44
44
  */
45
45
  export interface UserEventInstance {
46
46
  config: UserEventConfig;
47
- press: (element: ReactTestInstance) => Promise<void>;
48
- longPress: (element: ReactTestInstance, options?: PressOptions) => Promise<void>;
47
+ press: (element: HostElement) => Promise<void>;
48
+ longPress: (element: HostElement, options?: PressOptions) => Promise<void>;
49
49
  /**
50
50
  * Simulate user pressing on a given `TextInput` element and typing given text.
51
51
  *
@@ -66,7 +66,7 @@ export interface UserEventInstance {
66
66
  * - `submitEditing` - if true, `submitEditing` event will be triggered after
67
67
  * typing the text.
68
68
  */
69
- type: (element: ReactTestInstance, text: string, options?: TypeOptions) => Promise<void>;
69
+ type: (element: HostElement, text: string, options?: TypeOptions) => Promise<void>;
70
70
  /**
71
71
  * Simulate user clearing the text of a given `TextInput` element.
72
72
  *
@@ -78,7 +78,7 @@ export interface UserEventInstance {
78
78
  *
79
79
  * @param element TextInput element to clear
80
80
  */
81
- clear: (element: ReactTestInstance) => Promise<void>;
81
+ clear: (element: HostElement) => Promise<void>;
82
82
  /**
83
83
  * Simulate user pasting the text to a given `TextInput` element.
84
84
  *
@@ -90,12 +90,12 @@ export interface UserEventInstance {
90
90
  *
91
91
  * @param element TextInput element to paste to
92
92
  */
93
- paste: (element: ReactTestInstance, text: string) => Promise<void>;
93
+ paste: (element: HostElement, text: string) => Promise<void>;
94
94
  /**
95
95
  * Simlate user scorlling a ScrollView element.
96
96
  *
97
97
  * @param element ScrollView element
98
98
  * @returns
99
99
  */
100
- scrollTo: (element: ReactTestInstance, options: ScrollToOptions) => Promise<void>;
100
+ scrollTo: (element: HostElement, options: ScrollToOptions) => Promise<void>;
101
101
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setup.js","names":["_timers","require","_wrapAsync","_clear","_paste","_press","_scroll","_type","_utils","universalJestAdvanceTimersBy","ms","jestFakeTimersAreEnabled","jest","advanceTimersByTime","Promise","resolve","defaultOptions","delay","advanceTimers","setup","options","config","createConfig","instance","createInstance","api","press","wrapAndBindImpl","longPress","type","clear","paste","scrollTo","Object","assign","impl","method","args","wrapAsync","apply","then","result","wait","defineProperty","get","name"],"sources":["../../../src/user-event/setup/setup.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { jestFakeTimersAreEnabled } from '../../helpers/timers';\nimport { wrapAsync } from '../../helpers/wrap-async';\nimport { clear } from '../clear';\nimport { paste } from '../paste';\nimport { PressOptions, press, longPress } from '../press';\nimport { ScrollToOptions, scrollTo } from '../scroll';\nimport { TypeOptions, type } from '../type';\nimport { wait } from '../utils';\n\nexport interface UserEventSetupOptions {\n /**\n * Between some subsequent inputs like typing a series of characters\n * the code execution is delayed per `setTimeout` for (at least) `delay` seconds.\n * This moves the next changes at least to next macro task\n * and allows other (asynchronous) code to run between events.\n *\n * `null` prevents `setTimeout` from being called.\n *\n * @default 0\n */\n delay?: number;\n\n /**\n * Function to be called to advance fake timers. Setting it is necessary for\n * fake timers to work.\n *\n * @example jest.advanceTimersByTime\n */\n advanceTimers?: (delay: number) => Promise<void> | void;\n}\n\n/**\n * This functions allow wait to work correctly under both real and fake Jest timers.\n */\nfunction universalJestAdvanceTimersBy(ms: number) {\n if (jestFakeTimersAreEnabled()) {\n return jest.advanceTimersByTime(ms);\n } else {\n return Promise.resolve();\n }\n}\n\nconst defaultOptions: Required<UserEventSetupOptions> = {\n delay: 0,\n advanceTimers: universalJestAdvanceTimersBy,\n};\n\n/**\n * Creates a new instance of user event instance with the given options.\n *\n * @param options\n * @returns UserEvent instance\n */\nexport function setup(options?: UserEventSetupOptions) {\n const config = createConfig(options);\n const instance = createInstance(config);\n return instance;\n}\n\n/**\n * Options affecting all user event interactions.\n *\n * @param delay between some subsequent inputs like typing a series of characters\n * @param advanceTimers function to be called to advance fake timers\n */\nexport interface UserEventConfig {\n delay: number;\n advanceTimers: (delay: number) => Promise<void> | void;\n}\n\nfunction createConfig(options?: UserEventSetupOptions): UserEventConfig {\n return {\n ...defaultOptions,\n ...options,\n };\n}\n\n/**\n * UserEvent instance used to invoke user interaction functions.\n */\nexport interface UserEventInstance {\n config: UserEventConfig;\n\n press: (element: ReactTestInstance) => Promise<void>;\n longPress: (element: ReactTestInstance, options?: PressOptions) => Promise<void>;\n\n /**\n * Simulate user pressing on a given `TextInput` element and typing given text.\n *\n * This method will trigger the events for each character of the text:\n * `keyPress`, `change`, `changeText`, `endEditing`, etc.\n *\n * It will also trigger events connected with entering and leaving the text\n * input.\n *\n * The exact events sent depend on the props of the TextInput (`editable`,\n * `multiline`, etc) and passed options.\n *\n * @param element TextInput element to type on\n * @param text Text to type\n * @param options Options affecting typing behavior:\n * - `skipPress` - if true, `pressIn` and `pressOut` events will not be\n * triggered.\n * - `submitEditing` - if true, `submitEditing` event will be triggered after\n * typing the text.\n */\n type: (element: ReactTestInstance, text: string, options?: TypeOptions) => Promise<void>;\n\n /**\n * Simulate user clearing the text of a given `TextInput` element.\n *\n * This method will simulate:\n * 1. entering TextInput\n * 2. selecting all text\n * 3. pressing backspace to delete all text\n * 4. leaving TextInput\n *\n * @param element TextInput element to clear\n */\n clear: (element: ReactTestInstance) => Promise<void>;\n\n /**\n * Simulate user pasting the text to a given `TextInput` element.\n *\n * This method will simulate:\n * 1. entering TextInput\n * 2. selecting all text\n * 3. paste the text\n * 4. leaving TextInput\n *\n * @param element TextInput element to paste to\n */\n paste: (element: ReactTestInstance, text: string) => Promise<void>;\n\n /**\n * Simlate user scorlling a ScrollView element.\n *\n * @param element ScrollView element\n * @returns\n */\n scrollTo: (element: ReactTestInstance, options: ScrollToOptions) => Promise<void>;\n}\n\nfunction createInstance(config: UserEventConfig): UserEventInstance {\n const instance = {\n config,\n } as UserEventInstance;\n\n // Bind interactions to given User Event instance.\n const api = {\n press: wrapAndBindImpl(instance, press),\n longPress: wrapAndBindImpl(instance, longPress),\n type: wrapAndBindImpl(instance, type),\n clear: wrapAndBindImpl(instance, clear),\n paste: wrapAndBindImpl(instance, paste),\n scrollTo: wrapAndBindImpl(instance, scrollTo),\n };\n\n Object.assign(instance, api);\n return instance;\n}\n\n/**\n * Wraps user interaction with `wrapAsync` (temporarily disable `act` environment while\n * calling & resolving the async callback, then flush the microtask queue)\n *\n * This implementation is sourced from `testing-library/user-event`\n * @see https://github.com/testing-library/user-event/blob/7a305dee9ab833d6f338d567fc2e862b4838b76a/src/setup/setup.ts#L121\n */\nfunction wrapAndBindImpl<\n Args extends any[],\n Impl extends (this: UserEventInstance, ...args: Args) => Promise<unknown>,\n>(instance: UserEventInstance, impl: Impl) {\n function method(...args: Args) {\n return wrapAsync(() =>\n // eslint-disable-next-line promise/prefer-await-to-then\n impl.apply(instance, args).then(async (result) => {\n await wait(instance.config);\n return result;\n }),\n );\n }\n\n // Copy implementation name to the returned function\n Object.defineProperty(method, 'name', { get: () => impl.name });\n\n return method as Impl;\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAwBA;AACA;AACA;AACA,SAASQ,4BAA4BA,CAACC,EAAU,EAAE;EAChD,IAAI,IAAAC,gCAAwB,EAAC,CAAC,EAAE;IAC9B,OAAOC,IAAI,CAACC,mBAAmB,CAACH,EAAE,CAAC;EACrC,CAAC,MAAM;IACL,OAAOI,OAAO,CAACC,OAAO,CAAC,CAAC;EAC1B;AACF;AAEA,MAAMC,cAA+C,GAAG;EACtDC,KAAK,EAAE,CAAC;EACRC,aAAa,EAAET;AACjB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACO,SAASU,KAAKA,CAACC,OAA+B,EAAE;EACrD,MAAMC,MAAM,GAAGC,YAAY,CAACF,OAAO,CAAC;EACpC,MAAMG,QAAQ,GAAGC,cAAc,CAACH,MAAM,CAAC;EACvC,OAAOE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C,CAAC;EAE/D,OAAOT,MAAM;AACf","ignoreList":[]}
1
+ {"version":3,"file":"setup.js","names":["_timers","require","_wrapAsync","_clear","_paste","_press","_scroll","_type","_utils","universalJestAdvanceTimersBy","ms","jestFakeTimersAreEnabled","jest","advanceTimersByTime","Promise","resolve","defaultOptions","delay","advanceTimers","setup","options","config","createConfig","instance","createInstance","api","press","wrapAndBindImpl","longPress","type","clear","paste","scrollTo","Object","assign","impl","method","args","wrapAsync","apply","then","result","wait","defineProperty","get","name"],"sources":["../../../src/user-event/setup/setup.ts"],"sourcesContent":["import { HostElement } from 'universal-test-renderer';\nimport { jestFakeTimersAreEnabled } from '../../helpers/timers';\nimport { wrapAsync } from '../../helpers/wrap-async';\nimport { clear } from '../clear';\nimport { paste } from '../paste';\nimport { PressOptions, press, longPress } from '../press';\nimport { ScrollToOptions, scrollTo } from '../scroll';\nimport { TypeOptions, type } from '../type';\nimport { wait } from '../utils';\n\nexport interface UserEventSetupOptions {\n /**\n * Between some subsequent inputs like typing a series of characters\n * the code execution is delayed per `setTimeout` for (at least) `delay` seconds.\n * This moves the next changes at least to next macro task\n * and allows other (asynchronous) code to run between events.\n *\n * `null` prevents `setTimeout` from being called.\n *\n * @default 0\n */\n delay?: number;\n\n /**\n * Function to be called to advance fake timers. Setting it is necessary for\n * fake timers to work.\n *\n * @example jest.advanceTimersByTime\n */\n advanceTimers?: (delay: number) => Promise<void> | void;\n}\n\n/**\n * This functions allow wait to work correctly under both real and fake Jest timers.\n */\nfunction universalJestAdvanceTimersBy(ms: number) {\n if (jestFakeTimersAreEnabled()) {\n return jest.advanceTimersByTime(ms);\n } else {\n return Promise.resolve();\n }\n}\n\nconst defaultOptions: Required<UserEventSetupOptions> = {\n delay: 0,\n advanceTimers: universalJestAdvanceTimersBy,\n};\n\n/**\n * Creates a new instance of user event instance with the given options.\n *\n * @param options\n * @returns UserEvent instance\n */\nexport function setup(options?: UserEventSetupOptions) {\n const config = createConfig(options);\n const instance = createInstance(config);\n return instance;\n}\n\n/**\n * Options affecting all user event interactions.\n *\n * @param delay between some subsequent inputs like typing a series of characters\n * @param advanceTimers function to be called to advance fake timers\n */\nexport interface UserEventConfig {\n delay: number;\n advanceTimers: (delay: number) => Promise<void> | void;\n}\n\nfunction createConfig(options?: UserEventSetupOptions): UserEventConfig {\n return {\n ...defaultOptions,\n ...options,\n };\n}\n\n/**\n * UserEvent instance used to invoke user interaction functions.\n */\nexport interface UserEventInstance {\n config: UserEventConfig;\n\n press: (element: HostElement) => Promise<void>;\n longPress: (element: HostElement, options?: PressOptions) => Promise<void>;\n\n /**\n * Simulate user pressing on a given `TextInput` element and typing given text.\n *\n * This method will trigger the events for each character of the text:\n * `keyPress`, `change`, `changeText`, `endEditing`, etc.\n *\n * It will also trigger events connected with entering and leaving the text\n * input.\n *\n * The exact events sent depend on the props of the TextInput (`editable`,\n * `multiline`, etc) and passed options.\n *\n * @param element TextInput element to type on\n * @param text Text to type\n * @param options Options affecting typing behavior:\n * - `skipPress` - if true, `pressIn` and `pressOut` events will not be\n * triggered.\n * - `submitEditing` - if true, `submitEditing` event will be triggered after\n * typing the text.\n */\n type: (element: HostElement, text: string, options?: TypeOptions) => Promise<void>;\n\n /**\n * Simulate user clearing the text of a given `TextInput` element.\n *\n * This method will simulate:\n * 1. entering TextInput\n * 2. selecting all text\n * 3. pressing backspace to delete all text\n * 4. leaving TextInput\n *\n * @param element TextInput element to clear\n */\n clear: (element: HostElement) => Promise<void>;\n\n /**\n * Simulate user pasting the text to a given `TextInput` element.\n *\n * This method will simulate:\n * 1. entering TextInput\n * 2. selecting all text\n * 3. paste the text\n * 4. leaving TextInput\n *\n * @param element TextInput element to paste to\n */\n paste: (element: HostElement, text: string) => Promise<void>;\n\n /**\n * Simlate user scorlling a ScrollView element.\n *\n * @param element ScrollView element\n * @returns\n */\n scrollTo: (element: HostElement, options: ScrollToOptions) => Promise<void>;\n}\n\nfunction createInstance(config: UserEventConfig): UserEventInstance {\n const instance = {\n config,\n } as UserEventInstance;\n\n // Bind interactions to given User Event instance.\n const api = {\n press: wrapAndBindImpl(instance, press),\n longPress: wrapAndBindImpl(instance, longPress),\n type: wrapAndBindImpl(instance, type),\n clear: wrapAndBindImpl(instance, clear),\n paste: wrapAndBindImpl(instance, paste),\n scrollTo: wrapAndBindImpl(instance, scrollTo),\n };\n\n Object.assign(instance, api);\n return instance;\n}\n\n/**\n * Wraps user interaction with `wrapAsync` (temporarily disable `act` environment while\n * calling & resolving the async callback, then flush the microtask queue)\n *\n * This implementation is sourced from `testing-library/user-event`\n * @see https://github.com/testing-library/user-event/blob/7a305dee9ab833d6f338d567fc2e862b4838b76a/src/setup/setup.ts#L121\n */\nfunction wrapAndBindImpl<\n Args extends any[],\n Impl extends (this: UserEventInstance, ...args: Args) => Promise<unknown>,\n>(instance: UserEventInstance, impl: Impl) {\n function method(...args: Args) {\n return wrapAsync(() =>\n // eslint-disable-next-line promise/prefer-await-to-then\n impl.apply(instance, args).then(async (result) => {\n await wait(instance.config);\n return result;\n }),\n );\n }\n\n // Copy implementation name to the returned function\n Object.defineProperty(method, 'name', { get: () => impl.name });\n\n return method as Impl;\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAwBA;AACA;AACA;AACA,SAASQ,4BAA4BA,CAACC,EAAU,EAAE;EAChD,IAAI,IAAAC,gCAAwB,EAAC,CAAC,EAAE;IAC9B,OAAOC,IAAI,CAACC,mBAAmB,CAACH,EAAE,CAAC;EACrC,CAAC,MAAM;IACL,OAAOI,OAAO,CAACC,OAAO,CAAC,CAAC;EAC1B;AACF;AAEA,MAAMC,cAA+C,GAAG;EACtDC,KAA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K;MAChD,MAAM,IAAAC,WAAI,EAACnB,QAAQ,CAACF,MAAM,CAAC;MAC3B,OAAOoB,MAAM;IACf,CAAC,CACH,CAAC;EACH;;EAEA;EACAR,MAAM,CAACU,cAAc,CAACP,MAAM,EAAE,MAAM,EAAE;IAAEQ,GAAG,EAAEA,CAAA,KAAMT,IAAI,CAACU;EAAK,CAAC,CAAC;EAE/D,OAAOT,MAAM;AACf","ignoreList":[]}
@@ -1,15 +1,15 @@
1
- import { ReactTestInstance } from 'react-test-renderer';
1
+ import { HostElement } from 'universal-test-renderer';
2
2
  import { UserEventConfig, UserEventInstance } from '../setup';
3
3
  export interface TypeOptions {
4
4
  skipPress?: boolean;
5
5
  submitEditing?: boolean;
6
6
  }
7
- export declare function type(this: UserEventInstance, element: ReactTestInstance, text: string, options?: TypeOptions): Promise<void>;
7
+ export declare function type(this: UserEventInstance, element: HostElement, text: string, options?: TypeOptions): Promise<void>;
8
8
  type EmitTypingEventsContext = {
9
9
  config: UserEventConfig;
10
10
  key: string;
11
11
  text: string;
12
12
  isAccepted?: boolean;
13
13
  };
14
- export declare function emitTypingEvents(element: ReactTestInstance, { config, key, text, isAccepted }: EmitTypingEventsContext): Promise<void>;
14
+ export declare function emitTypingEvents(element: HostElement, { config, key, text, isAccepted }: EmitTypingEventsContext): Promise<void>;
15
15
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"type.js","names":["_hostComponentNames","require","_nativeState","_eventBuilder","_errors","_textInput","_pointerEvents","_utils","_parseKeys","type","element","text","options","isHostTextInput","ErrorWithStack","isEditableTextInput","isPointerEventEnabled","keys","parseKeys","skipPress","dispatchEvent","EventBuilder","Common","touch","focus","wait","config","currentText","getTextInputValue","key","previousText","proposedText","applyKey","isAccepted","isTextChangeAccepted","emitTypingEvents","finalText","submitEditing","TextInput","endEditing","blur","isMultiline","props","multiline","keyPress","nativeState","valueForElement","set","change","selectionRange","start","length","end","selectionChange","contentSize","getTextContentSize","contentSizeChange","slice","maxLength","undefined"],"sources":["../../../src/user-event/type/type.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { isHostTextInput } from '../../helpers/host-component-names';\nimport { nativeState } from '../../native-state';\nimport { EventBuilder } from '../event-builder';\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { getTextInputValue, isEditableTextInput } from '../../helpers/text-input';\nimport { isPointerEventEnabled } from '../../helpers/pointer-events';\nimport { UserEventConfig, UserEventInstance } from '../setup';\nimport { dispatchEvent, wait, getTextContentSize } from '../utils';\nimport { parseKeys } from './parse-keys';\n\nexport interface TypeOptions {\n skipPress?: boolean;\n submitEditing?: boolean;\n}\n\nexport async function type(\n this: UserEventInstance,\n element: ReactTestInstance,\n text: string,\n options?: TypeOptions,\n): Promise<void> {\n if (!isHostTextInput(element)) {\n throw new ErrorWithStack(\n `type() works only with host \"TextInput\" elements. Passed element has type \"${element.type}\".`,\n type,\n );\n }\n\n // Skip events if the element is disabled\n if (!isEditableTextInput(element) || !isPointerEventEnabled(element)) {\n return;\n }\n\n const keys = parseKeys(text);\n\n if (!options?.skipPress) {\n dispatchEvent(element, 'pressIn', EventBuilder.Common.touch());\n }\n\n dispatchEvent(element, 'focus', EventBuilder.Common.focus());\n\n if (!options?.skipPress) {\n await wait(this.config);\n dispatchEvent(element, 'pressOut', EventBuilder.Common.touch());\n }\n\n let currentText = getTextInputValue(element);\n for (const key of keys) {\n const previousText = getTextInputValue(element);\n const proposedText = applyKey(previousText, key);\n const isAccepted = isTextChangeAccepted(element, proposedText);\n currentText = isAccepted ? proposedText : previousText;\n\n await emitTypingEvents(element, {\n config: this.config,\n key,\n text: currentText,\n isAccepted,\n });\n }\n\n const finalText = getTextInputValue(element);\n await wait(this.config);\n\n if (options?.submitEditing) {\n dispatchEvent(element, 'submitEditing', EventBuilder.TextInput.submitEditing(finalText));\n }\n\n dispatchEvent(element, 'endEditing', EventBuilder.TextInput.endEditing(finalText));\n\n dispatchEvent(element, 'blur', EventBuilder.Common.blur());\n}\n\ntype EmitTypingEventsContext = {\n config: UserEventConfig;\n key: string;\n text: string;\n isAccepted?: boolean;\n};\n\nexport async function emitTypingEvents(\n element: ReactTestInstance,\n { config, key, text, isAccepted }: EmitTypingEventsContext,\n) {\n const isMultiline = element.props.multiline === true;\n\n await wait(config);\n dispatchEvent(element, 'keyPress', EventBuilder.TextInput.keyPress(key));\n\n // Platform difference (based on experiments):\n // - iOS and RN Web: TextInput emits only `keyPress` event when max length has been reached\n // - Android: TextInputs does not emit any events\n if (isAccepted === false) {\n return;\n }\n\n nativeState.valueForElement.set(element, text);\n dispatchEvent(element, 'change', EventBuilder.TextInput.change(text));\n dispatchEvent(element, 'changeText', text);\n\n const selectionRange = {\n start: text.length,\n end: text.length,\n };\n dispatchEvent(element, 'selectionChange', EventBuilder.TextInput.selectionChange(selectionRange));\n\n // According to the docs only multiline TextInput emits contentSizeChange event\n // @see: https://reactnative.dev/docs/textinput#oncontentsizechange\n if (isMultiline) {\n const contentSize = getTextContentSize(text);\n dispatchEvent(\n element,\n 'contentSizeChange',\n EventBuilder.TextInput.contentSizeChange(contentSize),\n );\n }\n}\n\nfunction applyKey(text: string, key: string) {\n if (key === 'Enter') {\n return `${text}\\n`;\n }\n\n if (key === 'Backspace') {\n return text.slice(0, -1);\n }\n\n return text + key;\n}\n\nfunction isTextChangeAccepted(element: ReactTestInstance, text: string) {\n const maxLength = element.props.maxLength;\n return maxLength === undefined || text.length <= maxLength;\n}\n"],"mappings":";;;;;;;AACA,IAAAA,mBAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA;AAOO,eAAeQ,IAAIA,CAExBC,OAA0B,EAC1BC,IAAY,EACZC,OAAqB,EACN;EACf,IAA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C,KAAK,EAAEvC,IAAI,CAACwC,MAAM;IAClBC,GAAG,EAAEzC,IAAI,CAACwC;EACZ,CAAC;EACD,IAAA/B,oBAAa,EAACV,OAAO,EAAE,iBAAiB,EAAEW,0BAAY,CAACiB,SAAS,CAACe,eAAe,CAACJ,cAAc,CAAC,CAAC;;EAEjG;EACA;EACA,IAAIR,WAAW,EAAE;IACf,MAAMa,WAAW,GAAG,IAAAC,yBAAkB,EAAC5C,IAAI,CAAC;IAC5C,IAAAS,oBAAa,EACXV,OAAO,EACP,mBAAmB,EACnBW,0BAAY,CAACiB,SAAS,CAACkB,iBAAiB,CAACF,WAAW,CACtD,CAAC;EACH;AACF;AAEA,SAAStB,QAAQA,CAACrB,IAAY,EAAEkB,GAAW,EAAE;EAC3C,IAAIA,GAAG,KAAK,OAAO,EAAE;IACnB,OAAO,GAAGlB,IAAI,IAAI;EACpB;EAEA,IAAIkB,GAAG,KAAK,WAAW,EAAE;IACvB,OAAOlB,IAAI,CAAC8C,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAC1B;EAEA,OAAO9C,IAAI,GAAGkB,GAAG;AACnB;AAEA,SAASK,oBAAoBA,CAACxB,OAA0B,EAAEC,IAAY,EAAE;EACtE,MAAM+C,SAAS,GAAGhD,OAAO,CAACgC,KAAK,CAACgB,SAAS;EACzC,OAAOA,SAAS,KAAKC,SAAS,IAAIhD,IAAI,CAACwC,MAAM,IAAIO,SAAS;AAC5D","ignoreList":[]}
1
+ {"version":3,"file":"type.js","names":["_hostComponentNames","require","_nativeState","_eventBuilder","_errors","_textInput","_pointerEvents","_utils","_parseKeys","type","element","text","options","isHostTextInput","ErrorWithStack","isEditableTextInput","isPointerEventEnabled","keys","parseKeys","skipPress","dispatchEvent","EventBuilder","Common","touch","focus","wait","config","currentText","getTextInputValue","key","previousText","proposedText","applyKey","isAccepted","isTextChangeAccepted","emitTypingEvents","finalText","submitEditing","TextInput","endEditing","blur","isMultiline","props","multiline","keyPress","nativeState","valueForElement","set","change","selectionRange","start","length","end","selectionChange","contentSize","getTextContentSize","contentSizeChange","slice","maxLength","undefined"],"sources":["../../../src/user-event/type/type.ts"],"sourcesContent":["import { HostElement } from 'universal-test-renderer';\nimport { isHostTextInput } from '../../helpers/host-component-names';\nimport { nativeState } from '../../native-state';\nimport { EventBuilder } from '../event-builder';\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { getTextInputValue, isEditableTextInput } from '../../helpers/text-input';\nimport { isPointerEventEnabled } from '../../helpers/pointer-events';\nimport { UserEventConfig, UserEventInstance } from '../setup';\nimport { dispatchEvent, wait, getTextContentSize } from '../utils';\nimport { parseKeys } from './parse-keys';\n\nexport interface TypeOptions {\n skipPress?: boolean;\n submitEditing?: boolean;\n}\n\nexport async function type(\n this: UserEventInstance,\n element: HostElement,\n text: string,\n options?: TypeOptions,\n): Promise<void> {\n if (!isHostTextInput(element)) {\n throw new ErrorWithStack(\n `type() works only with host \"TextInput\" elements. Passed element has type \"${element.type}\".`,\n type,\n );\n }\n\n // Skip events if the element is disabled\n if (!isEditableTextInput(element) || !isPointerEventEnabled(element)) {\n return;\n }\n\n const keys = parseKeys(text);\n\n if (!options?.skipPress) {\n dispatchEvent(element, 'pressIn', EventBuilder.Common.touch());\n }\n\n dispatchEvent(element, 'focus', EventBuilder.Common.focus());\n\n if (!options?.skipPress) {\n await wait(this.config);\n dispatchEvent(element, 'pressOut', EventBuilder.Common.touch());\n }\n\n let currentText = getTextInputValue(element);\n for (const key of keys) {\n const previousText = getTextInputValue(element);\n const proposedText = applyKey(previousText, key);\n const isAccepted = isTextChangeAccepted(element, proposedText);\n currentText = isAccepted ? proposedText : previousText;\n\n await emitTypingEvents(element, {\n config: this.config,\n key,\n text: currentText,\n isAccepted,\n });\n }\n\n const finalText = getTextInputValue(element);\n await wait(this.config);\n\n if (options?.submitEditing) {\n dispatchEvent(element, 'submitEditing', EventBuilder.TextInput.submitEditing(finalText));\n }\n\n dispatchEvent(element, 'endEditing', EventBuilder.TextInput.endEditing(finalText));\n\n dispatchEvent(element, 'blur', EventBuilder.Common.blur());\n}\n\ntype EmitTypingEventsContext = {\n config: UserEventConfig;\n key: string;\n text: string;\n isAccepted?: boolean;\n};\n\nexport async function emitTypingEvents(\n element: HostElement,\n { config, key, text, isAccepted }: EmitTypingEventsContext,\n) {\n const isMultiline = element.props.multiline === true;\n\n await wait(config);\n dispatchEvent(element, 'keyPress', EventBuilder.TextInput.keyPress(key));\n\n // Platform difference (based on experiments):\n // - iOS and RN Web: TextInput emits only `keyPress` event when max length has been reached\n // - Android: TextInputs does not emit any events\n if (isAccepted === false) {\n return;\n }\n\n nativeState.valueForElement.set(element, text);\n dispatchEvent(element, 'change', EventBuilder.TextInput.change(text));\n dispatchEvent(element, 'changeText', text);\n\n const selectionRange = {\n start: text.length,\n end: text.length,\n };\n dispatchEvent(element, 'selectionChange', EventBuilder.TextInput.selectionChange(selectionRange));\n\n // According to the docs only multiline TextInput emits contentSizeChange event\n // @see: https://reactnative.dev/docs/textinput#oncontentsizechange\n if (isMultiline) {\n const contentSize = getTextContentSize(text);\n dispatchEvent(\n element,\n 'contentSizeChange',\n EventBuilder.TextInput.contentSizeChange(contentSize),\n );\n }\n}\n\nfunction applyKey(text: string, key: string) {\n if (key === 'Enter') {\n return `${text}\\n`;\n }\n\n if (key === 'Backspace') {\n return text.slice(0, -1);\n }\n\n return text + key;\n}\n\nfunction isTextChangeAccepted(element: HostElement, text: string) {\n const maxLength = element.props.maxLength;\n return maxLength === undefined || text.length <= maxLength;\n}\n"],"mappings":";;;;;;;AACA,IAAAA,mBAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA;AAOO,eAAeQ,IAAIA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Y,EAAEC,IAAI,CAAC;EAE1C,MAAMsC,cAAc,GAAG;IACrBC,KAAK,EAAEvC,IAAI,CAACwC,MAAM;IAClBC,GAAG,EAAEzC,IAAI,CAACwC;EACZ,CAAC;EACD,IAAA/B,oBAAa,EAACV,OAAO,EAAE,iBAAiB,EAAEW,0BAAY,CAACiB,SAAS,CAACe,eAAe,CAACJ,cAAc,CAAC,CAAC;;EAEjG;EACA;EACA,IAAIR,WAAW,EAAE;IACf,MAAMa,WAAW,GAAG,IAAAC,yBAAkB,EAAC5C,IAAI,CAAC;IAC5C,IAAAS,oBAAa,EACXV,OAAO,EACP,mBAAmB,EACnBW,0BAAY,CAACiB,SAAS,CAACkB,iBAAiB,CAACF,WAAW,CACtD,CAAC;EACH;AACF;AAEA,SAAStB,QAAQA,CAACrB,IAAY,EAAEkB,GAAW,EAAE;EAC3C,IAAIA,GAAG,KAAK,OAAO,EAAE;IACnB,OAAO,GAAGlB,IAAI,IAAI;EACpB;EAEA,IAAIkB,GAAG,KAAK,WAAW,EAAE;IACvB,OAAOlB,IAAI,CAAC8C,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAC1B;EAEA,OAAO9C,IAAI,GAAGkB,GAAG;AACnB;AAEA,SAASK,oBAAoBA,CAACxB,OAAoB,EAAEC,IAAY,EAAE;EAChE,MAAM+C,SAAS,GAAGhD,OAAO,CAACgC,KAAK,CAACgB,SAAS;EACzC,OAAOA,SAAS,KAAKC,SAAS,IAAIhD,IAAI,CAACwC,MAAM,IAAIO,SAAS;AAC5D","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { ReactTestInstance } from 'react-test-renderer';
1
+ import { HostElement } from 'universal-test-renderer';
2
2
  /**
3
3
  * Basic dispatch event function used by User Event module.
4
4
  *
@@ -6,4 +6,4 @@ import { ReactTestInstance } from 'react-test-renderer';
6
6
  * @param eventName name of the event
7
7
  * @param event event payload(s)
8
8
  */
9
- export declare function dispatchEvent(element: ReactTestInstance, eventName: string, ...event: unknown[]): void;
9
+ export declare function dispatchEvent(element: HostElement, eventName: string, ...event: unknown[]): void;
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","_componentTree","e","__esModule","default","dispatchEvent","element","eventName","event","isElementMounted","handler","getEventHandler","act","handleName","getEventHandlerName","handle","props","undefined","charAt","toUpperCase","slice"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport act from '../../act';\nimport { isElementMounted } from '../../helpers/component-tree';\n\n/**\n * Basic dispatch event function used by User Event module.\n *\n * @param element element trigger event on\n * @param eventName name of the event\n * @param event event payload(s)\n */\nexport function dispatchEvent(element: ReactTestInstance, eventName: string, ...event: unknown[]) {\n if (!isElementMounted(element)) {\n return;\n }\n\n const handler = getEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n // This will be called synchronously.\n void act(() => {\n handler(...event);\n });\n}\n\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const handleName = getEventHandlerName(eventName);\n const handle = element.props[handleName] as unknown;\n if (typeof handle !== 'function') {\n return undefined;\n }\n\n return handle;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n}\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAAgE,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAaA,CAACC,OAA0B,EAAEC,SAAiB,EAAE,GAAGC,KAAgB,EAAE;EAChG,IAAI,CAAC,IAAAC,+BAAgB,EAACH,OAAO,CAAC,EAAE;IAC9B;EACF;EAEA,MAAMI,OAAO,GAAGC,eAAe,CAACL,OAAO,EAAEC,SAAS,CAAC;EACnD,IAAI,CAACG,OAAO,EAAE;IACZ;EACF;;EAEA;EACA,KAAK,IAAAE,YAAG,EAAC,MAAM;IACbF,OAAO,CAAC,GAAGF,KAAK,CAAC;EACnB,CAAC,CAAC;AACJ;AAEA,SAASG,eAAeA,CAACL,OAA0B,EAAEC,SAAiB,EAAE;EACtE,MAAMM,UAAU,GAAGC,mBAAmB,CAACP,SAAS,CAAC;EACjD,MAAMQ,MAAM,GAAGT,OAAO,CAACU,KAAK,CAACH,UAAU,CAAY;EACnD,IAAI,OAAOE,MAAM,KAAK,UAAU,EAAE;IAChC,OAAOE,SAAS;EAClB;EAEA,OAAOF,MAAM;AACf;AAEA,SAASD,mBAAmBA,CAACP,SAAiB,EAAE;EAC9C,OAAO,KAAKA,SAAS,CAACW,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,GAAGZ,SAAS,CAACa,KAAK,CAAC,CAAC,CAAC,EAAE;AACtE","ignoreList":[]}
1
+ {"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","_componentTree","e","__esModule","default","dispatchEvent","element","eventName","event","isElementMounted","handler","getEventHandler","act","handleName","getEventHandlerName","handle","props","undefined","charAt","toUpperCase","slice"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import { HostElement } from 'universal-test-renderer';\nimport act from '../../act';\nimport { isElementMounted } from '../../helpers/component-tree';\n\n/**\n * Basic dispatch event function used by User Event module.\n *\n * @param element element trigger event on\n * @param eventName name of the event\n * @param event event payload(s)\n */\nexport function dispatchEvent(element: HostElement, eventName: string, ...event: unknown[]) {\n if (!isElementMounted(element)) {\n return;\n }\n\n const handler = getEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n // This will be called synchronously.\n void act(() => {\n handler(...event);\n });\n}\n\nfunction getEventHandler(element: HostElement, eventName: string) {\n const handleName = getEventHandlerName(eventName);\n const handle = element.props[handleName] as unknown;\n if (typeof handle !== 'function') {\n return undefined;\n }\n\n return handle;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n}\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAAgE,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAaA,CAACC,OAAoB,EAAEC,SAAiB,EAAE,GAAGC,KAAgB,EAAE;EAC1F,IAAI,CAAC,IAAAC,+BAAgB,EAACH,OAAO,CAAC,EAAE;IAC9B;EACF;EAEA,MAAMI,OAAO,GAAGC,eAAe,CAACL,OAAO,EAAEC,SAAS,CAAC;EACnD,IAAI,CAACG,OAAO,EAAE;IACZ;EACF;;EAEA;EACA,KAAK,IAAAE,YAAG,EAAC,MAAM;IACbF,OAAO,CAAC,GAAGF,KAAK,CAAC;EACnB,CAAC,CAAC;AACJ;AAEA,SAASG,eAAeA,CAACL,OAAoB,EAAEC,SAAiB,EAAE;EAChE,MAAMM,UAAU,GAAGC,mBAAmB,CAACP,SAAS,CAAC;EACjD,MAAMQ,MAAM,GAAGT,OAAO,CAACU,KAAK,CAACH,UAAU,CAAY;EACnD,IAAI,OAAOE,MAAM,KAAK,UAAU,EAAE;IAChC,OAAOE,SAAS;EAClB;EAEA,OAAOF,MAAM;AACf;AAEA,SAASD,mBAAmBA,CAACP,SAAiB,EAAE;EAC9C,OAAO,KAAKA,SAAS,CAACW,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,GAAGZ,SAAS,CAACa,KAAK,CAAC,CAAC,CAAC,EAAE;AACtE","ignoreList":[]}
package/build/within.d.ts CHANGED
@@ -1,27 +1,29 @@
1
- import type { ReactTestInstance } from 'react-test-renderer';
2
- export declare function within(instance: ReactTestInstance): {
3
- UNSAFE_getByProps: (props: {
4
- [key: string]: any;
5
- }) => ReactTestInstance;
6
- UNSAFE_getAllByProps: (props: {
7
- [key: string]: any;
8
- }) => Array<ReactTestInstance>;
9
- UNSAFE_queryByProps: (props: {
10
- [key: string]: any;
11
- }) => ReactTestInstance | null;
12
- UNSAFE_queryAllByProps: (props: {
13
- [key: string]: any;
14
- }) => Array<ReactTestInstance>;
15
- UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;
16
- UNSAFE_getAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance>;
17
- UNSAFE_queryByType: <P>(type: React.ComponentType<P>) => ReactTestInstance | null;
18
- UNSAFE_queryAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance>;
1
+ import { HostElement } from 'universal-test-renderer';
2
+ export declare function within(instance: HostElement): {
3
+ getByText: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
4
+ getAllByText: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
5
+ queryByText: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
6
+ queryAllByText: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
7
+ findByText: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
8
+ findAllByText: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
9
+ getByTestId: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
10
+ getAllByTestId: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
11
+ queryByTestId: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
12
+ queryAllByTestId: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
13
+ findByTestId: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
14
+ findAllByTestId: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
19
15
  getByRole: import("./queries/make-queries").GetByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
20
16
  getAllByRole: import("./queries/make-queries").GetAllByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
21
17
  queryByRole: import("./queries/make-queries").QueryByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
22
18
  queryAllByRole: import("./queries/make-queries").QueryAllByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
23
19
  findByRole: import("./queries/make-queries").FindByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
24
20
  findAllByRole: import("./queries/make-queries").FindAllByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
21
+ getByLabelText: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
22
+ getAllByLabelText: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
23
+ queryByLabelText: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
24
+ queryAllByLabelText: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
25
+ findByLabelText: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
26
+ findAllByLabelText: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
25
27
  getByHintText: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
26
28
  getAllByHintText: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
27
29
  queryByHintText: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
@@ -40,12 +42,6 @@ export declare function within(instance: ReactTestInstance): {
40
42
  queryAllByAccessibilityHint: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
41
43
  findByAccessibilityHint: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
42
44
  findAllByAccessibilityHint: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
43
- getByLabelText: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
44
- getAllByLabelText: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
45
- queryByLabelText: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
46
- queryAllByLabelText: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
47
- findByLabelText: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
48
- findAllByLabelText: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
49
45
  getByPlaceholderText: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
50
46
  getAllByPlaceholderText: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
51
47
  queryByPlaceholderText: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
@@ -58,17 +54,5 @@ export declare function within(instance: ReactTestInstance): {
58
54
  queryAllByDisplayValue: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
59
55
  findByDisplayValue: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
60
56
  findAllByDisplayValue: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
61
- getByTestId: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
62
- getAllByTestId: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
63
- queryByTestId: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
64
- queryAllByTestId: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
65
- findByTestId: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
66
- findAllByTestId: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
67
- getByText: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
68
- getAllByText: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
69
- queryByText: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
70
- queryAllByText: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
71
- findByText: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
72
- findAllByText: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
73
57
  };
74
58
  export declare const getQueriesForElement: typeof within;
package/build/within.js CHANGED
@@ -5,26 +5,22 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getQueriesForElement = void 0;
7
7
  exports.within = within;
8
- var _text = require("./queries/text");
9
- var _testId = require("./queries/test-id");
10
8
  var _displayValue = require("./queries/display-value");
11
- var _placeholderText = require("./queries/placeholder-text");
12
- var _labelText = require("./queries/label-text");
13
9
  var _hintText = require("./queries/hint-text");
10
+ var _labelText = require("./queries/label-text");
11
+ var _placeholderText = require("./queries/placeholder-text");
14
12
  var _role = require("./queries/role");
15
- var _unsafeType = require("./queries/unsafe-type");
16
- var _unsafeProps = require("./queries/unsafe-props");
13
+ var _testId = require("./queries/test-id");
14
+ var _text = require("./queries/text");
17
15
  function within(instance) {
18
16
  return {
19
- ...(0, _text.bindByTextQueries)(instance),
20
- ...(0, _testId.bindByTestIdQueries)(instance),
21
17
  ...(0, _displayValue.bindByDisplayValueQueries)(instance),
22
18
  ...(0, _placeholderText.bindByPlaceholderTextQueries)(instance),
23
- ...(0, _labelText.bindByLabelTextQueries)(instance),
24
19
  ...(0, _hintText.bindByHintTextQueries)(instance),
20
+ ...(0, _labelText.bindByLabelTextQueries)(instance),
25
21
  ...(0, _role.bindByRoleQueries)(instance),
26
- ...(0, _unsafeType.bindUnsafeByTypeQueries)(instance),
27
- ...(0, _unsafeProps.bindUnsafeByPropsQueries)(instance)
22
+ ...(0, _testId.bindByTestIdQueries)(instance),
23
+ ...(0, _text.bindByTextQueries)(instance)
28
24
  };
29
25
  }
30
26
  const getQueriesForElement = exports.getQueriesForElement = within;
@@ -1 +1 @@
1
- {"version":3,"file":"within.js","names":["_text","require","_testId","_displayValue","_placeholderText","_labelText","_hintText","_role","_unsafeType","_unsafeProps","within","instance","bindByTextQueries","bindByTestIdQueries","bindByDisplayValueQueries","bindByPlaceholderTextQueries","bindByLabelTextQueries","bindByHintTextQueries","bindByRoleQueries","bindUnsafeByTypeQueries","bindUnsafeByPropsQueries","getQueriesForElement","exports"],"sources":["../src/within.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { bindByTextQueries } from './queries/text';\nimport { bindByTestIdQueries } from './queries/test-id';\nimport { bindByDisplayValueQueries } from './queries/display-value';\nimport { bindByPlaceholderTextQueries } from './queries/placeholder-text';\nimport { bindByLabelTextQueries } from './queries/label-text';\nimport { bindByHintTextQueries } from './queries/hint-text';\nimport { bindByRoleQueries } from './queries/role';\nimport { bindUnsafeByTypeQueries } from './queries/unsafe-type';\nimport { bindUnsafeByPropsQueries } from './queries/unsafe-props';\n\nexport function within(instance: ReactTestInstance) {\n return {\n ...bindByTextQueries(instance),\n ...bindByTestIdQueries(instance),\n ...bindByDisplayValueQueries(instance),\n ...bindByPlaceholderTextQueries(instance),\n ...bindByLabelTextQueries(instance),\n ...bindByHintTextQueries(instance),\n ...bindByRoleQueries(instance),\n ...bindUnsafeByTypeQueries(instance),\n ...bindUnsafeByPropsQueries(instance),\n };\n}\n\nexport const getQueriesForElement = within;\n"],"mappings":";;;;;;;AACA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AACA,IAAAQ,YAAA,GAAAR,OAAA;AAEO,SAASS,MAAMA,CAACC,QAA2B,EAAE;EAClD,OAAO;IACL,GAAG,IAAAC,uBAAiB,EAACD,QAAQ,CAAC;IAC9B,GAAG,IAAAE,2BAAmB,EAACF,QAAQ,CAAC;IAChC,GAAG,IAAAG,uCAAyB,EAACH,QAAQ,CAAC;IACtC,GAAG,IAAAI,6CAA4B,EAACJ,QAAQ,CAAC;IACzC,GAAG,IAAAK,iCAAsB,EAACL,QAAQ,CAAC;IACnC,GAAG,IAAAM,+BAAqB,EAACN,QAAQ,CAAC;IAClC,GAAG,IAAAO,uBAAiB,EAACP,QAAQ,CAAC;IAC9B,GAAG,IAAAQ,mCAAuB,EAACR,QAAQ,CAAC;IACpC,GAAG,IAAAS,qCAAwB,EAACT,QAAQ;EACtC,CAAC;AACH;AAEO,MAAMU,oBAAoB,GAAAC,OAAA,CAAAD,oBAAA,GAAGX,MAAM","ignoreList":[]}
1
+ {"version":3,"file":"within.js","names":["_displayValue","require","_hintText","_labelText","_placeholderText","_role","_testId","_text","within","instance","bindByDisplayValueQueries","bindByPlaceholderTextQueries","bindByHintTextQueries","bindByLabelTextQueries","bindByRoleQueries","bindByTestIdQueries","bindByTextQueries","getQueriesForElement","exports"],"sources":["../src/within.ts"],"sourcesContent":["import { HostElement } from 'universal-test-renderer';\nimport { bindByDisplayValueQueries } from './queries/display-value';\nimport { bindByHintTextQueries } from './queries/hint-text';\nimport { bindByLabelTextQueries } from './queries/label-text';\nimport { bindByPlaceholderTextQueries } from './queries/placeholder-text';\nimport { bindByRoleQueries } from './queries/role';\nimport { bindByTestIdQueries } from './queries/test-id';\nimport { bindByTextQueries } from './queries/text';\n\nexport function within(instance: HostElement) {\n return {\n ...bindByDisplayValueQueries(instance),\n ...bindByPlaceholderTextQueries(instance),\n ...bindByHintTextQueries(instance),\n ...bindByLabelTextQueries(instance),\n ...bindByRoleQueries(instance),\n ...bindByTestIdQueries(instance),\n ...bindByTextQueries(instance),\n };\n}\n\nexport const getQueriesForElement = within;\n"],"mappings":";;;;;;;AACA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AAEO,SAASO,MAAMA,CAACC,QAAqB,EAAE;EAC5C,OAAO;IACL,GAAG,IAAAC,uCAAyB,EAACD,QAAQ,CAAC;IACtC,GAAG,IAAAE,6CAA4B,EAACF,QAAQ,CAAC;IACzC,GAAG,IAAAG,+BAAqB,EAACH,QAAQ,CAAC;IAClC,GAAG,IAAAI,iCAAsB,EAACJ,QAAQ,CAAC;IACnC,GAAG,IAAAK,uBAAiB,EAACL,QAAQ,CAAC;IAC9B,GAAG,IAAAM,2BAAmB,EAACN,QAAQ,CAAC;IAChC,GAAG,IAAAO,uBAAiB,EAACP,QAAQ;EAC/B,CAAC;AACH;AAEO,MAAMQ,oBAAoB,GAAAC,OAAA,CAAAD,oBAAA,GAAGT,MAAM","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/react-native",
3
- "version": "13.0.0-alpha.2",
3
+ "version": "14.0.0-alpha.0",
4
4
  "description": "Simple and complete React Native testing utilities that encourage good testing practices.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -53,9 +53,9 @@
53
53
  },
54
54
  "peerDependencies": {
55
55
  "jest": ">=29.0.0",
56
- "react": ">=18.2.0",
57
- "react-native": ">=0.71",
58
- "react-test-renderer": ">=18.2.0"
56
+ "react": ">=19.0.0",
57
+ "react-native": ">=0.77",
58
+ "universal-test-renderer": "0.5.0"
59
59
  },
60
60
  "peerDependenciesMeta": {
61
61
  "jest": {
@@ -71,12 +71,11 @@
71
71
  "@babel/preset-react": "^7.25.9",
72
72
  "@babel/preset-typescript": "^7.26.0",
73
73
  "@callstack/eslint-config": "^15.0.0",
74
- "@react-native/babel-preset": "^0.76.1",
74
+ "@react-native/babel-preset": "0.77.0-nightly-20241107-0ca2ba082",
75
75
  "@release-it/conventional-changelog": "^9.0.2",
76
76
  "@relmify/jest-serializer-strip-ansi": "^1.0.2",
77
77
  "@types/jest": "^29.5.14",
78
78
  "@types/react": "^18.3.12",
79
- "@types/react-test-renderer": "^18.3.0",
80
79
  "babel-jest": "^29.7.0",
81
80
  "babel-plugin-module-resolver": "^5.0.2",
82
81
  "del-cli": "^6.0.0",
@@ -85,18 +84,18 @@
85
84
  "flow-bin": "~0.170.0",
86
85
  "jest": "^29.7.0",
87
86
  "prettier": "^2.8.8",
88
- "react": "18.3.1",
89
- "react-native": "0.76.1",
90
- "react-test-renderer": "18.3.1",
87
+ "react": "19.0.0-rc-fb9a90fa48-20240614",
88
+ "react-native": "0.77.0-nightly-20241107-0ca2ba082",
91
89
  "release-it": "^17.10.0",
92
90
  "strip-ansi": "^6.0.1",
93
- "typescript": "^5.6.3"
91
+ "typescript": "^5.6.3",
92
+ "universal-test-renderer": "0.5.0"
94
93
  },
95
94
  "publishConfig": {
96
95
  "registry": "https://registry.npmjs.org"
97
96
  },
98
97
  "packageManager": "yarn@4.4.0",
99
98
  "engines": {
100
- "node": ">=18"
99
+ "node": ">=20"
101
100
  }
102
101
  }
@@ -314,7 +314,6 @@ declare module '@testing-library/react-native' {
314
314
  declare interface RenderOptions {
315
315
  wrapper?: React.ComponentType<any>;
316
316
  createNodeMock?: (element: React.Element<any>) => any;
317
- unstable_validateStringsRenderedWithinText?: boolean;
318
317
  unstable_isConcurrent?: boolean;
319
318
  unstable_strictMode?: boolean;
320
319
  unstable_concurrentUpdatesByDefault?: boolean;
@@ -1,2 +0,0 @@
1
- import { ReactTestRendererNode } from 'react-test-renderer';
2
- export declare const validateStringsRenderedWithinText: (rendererJSON: ReactTestRendererNode | Array<ReactTestRendererNode> | null) => void;