@testing-library/react-native 14.0.0-alpha.1 → 14.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -11
- package/build/act.d.ts +2 -4
- package/build/act.js +4 -5
- package/build/act.js.map +1 -1
- package/build/cleanup.d.ts +3 -1
- package/build/cleanup.js +8 -0
- package/build/cleanup.js.map +1 -1
- package/build/event-handler.d.ts +2 -2
- package/build/event-handler.js +10 -10
- package/build/event-handler.js.map +1 -1
- package/build/fire-event.d.ts +8 -1
- package/build/fire-event.js +44 -28
- package/build/fire-event.js.map +1 -1
- package/build/helpers/accessibility.js +5 -2
- package/build/helpers/accessibility.js.map +1 -1
- package/build/helpers/component-tree.d.ts +8 -8
- package/build/helpers/component-tree.js +19 -16
- package/build/helpers/component-tree.js.map +1 -1
- package/build/helpers/debug.d.ts +1 -1
- package/build/helpers/debug.js +6 -7
- package/build/helpers/debug.js.map +1 -1
- package/build/helpers/find-all.js +7 -27
- package/build/helpers/find-all.js.map +1 -1
- package/build/helpers/format-element.d.ts +3 -3
- package/build/helpers/format-element.js +9 -9
- package/build/helpers/format-element.js.map +1 -1
- package/build/helpers/host-component-names.d.ts +0 -1
- package/build/helpers/host-component-names.js +7 -9
- package/build/helpers/host-component-names.js.map +1 -1
- package/build/helpers/logger.d.ts +22 -0
- package/build/helpers/logger.js +13 -8
- package/build/helpers/logger.js.map +1 -1
- package/build/helpers/pointer-events.js +9 -5
- package/build/helpers/pointer-events.js.map +1 -1
- package/build/helpers/wrap-async.d.ts +0 -1
- package/build/helpers/wrap-async.js +0 -1
- package/build/helpers/wrap-async.js.map +1 -1
- package/build/index.d.ts +0 -1
- package/build/index.flow.js +5 -4
- package/build/index.js +1 -12
- package/build/index.js.map +1 -1
- package/build/matchers/to-be-empty-element.js +6 -3
- package/build/matchers/to-be-empty-element.js.map +1 -1
- package/build/matchers/to-be-visible.js +3 -3
- package/build/matchers/to-be-visible.js.map +1 -1
- package/build/matchers/to-contain-element.js +1 -2
- package/build/matchers/to-contain-element.js.map +1 -1
- package/build/matchers/to-have-style.js +1 -1
- package/build/matchers/to-have-style.js.map +1 -1
- package/build/matchers/utils.js +3 -2
- package/build/matchers/utils.js.map +1 -1
- package/build/pure.d.ts +7 -5
- package/build/pure.js +30 -4
- package/build/pure.js.map +1 -1
- package/build/queries/display-value.d.ts +1 -1
- package/build/queries/display-value.js +9 -9
- package/build/queries/display-value.js.map +1 -1
- package/build/queries/hint-text.d.ts +1 -1
- package/build/queries/hint-text.js +9 -9
- package/build/queries/hint-text.js.map +1 -1
- package/build/queries/label-text.d.ts +1 -1
- package/build/queries/label-text.js +9 -9
- package/build/queries/label-text.js.map +1 -1
- package/build/queries/make-queries.d.ts +2 -2
- package/build/queries/make-queries.js +11 -11
- package/build/queries/make-queries.js.map +1 -1
- package/build/queries/placeholder-text.d.ts +1 -1
- package/build/queries/placeholder-text.js +9 -9
- package/build/queries/placeholder-text.js.map +1 -1
- package/build/queries/role.d.ts +2 -2
- package/build/queries/role.js +16 -9
- package/build/queries/role.js.map +1 -1
- package/build/queries/test-id.d.ts +1 -1
- package/build/queries/test-id.js +9 -9
- package/build/queries/test-id.js.map +1 -1
- package/build/queries/text.d.ts +1 -1
- package/build/queries/text.js +9 -9
- package/build/queries/text.js.map +1 -1
- package/build/react-versions.js +1 -2
- package/build/react-versions.js.map +1 -1
- package/build/render-act.d.ts +3 -0
- package/build/render-act.js +29 -0
- package/build/render-act.js.map +1 -0
- package/build/render-async.d.ts +83 -0
- package/build/render-async.js +96 -0
- package/build/render-async.js.map +1 -0
- package/build/render-hook.d.ts +9 -7
- package/build/render-hook.js +44 -14
- package/build/render-hook.js.map +1 -1
- package/build/render.d.ts +86 -17
- package/build/render.js +44 -27
- package/build/render.js.map +1 -1
- package/build/screen.js +7 -7
- package/build/screen.js.map +1 -1
- package/build/test-utils/console.d.ts +1 -0
- package/build/test-utils/console.js +17 -0
- package/build/test-utils/console.js.map +1 -0
- package/build/test-utils/json.d.ts +6 -0
- package/build/test-utils/json.js +33 -0
- package/build/test-utils/json.js.map +1 -0
- package/build/tsconfig.release.tsbuildinfo +1 -1
- package/build/types.d.ts +4 -0
- package/build/types.js.map +1 -1
- package/build/user-event/clear.js +4 -4
- package/build/user-event/clear.js.map +1 -1
- package/build/user-event/paste.js +8 -8
- package/build/user-event/paste.js.map +1 -1
- package/build/user-event/press/press.js +17 -10
- package/build/user-event/press/press.js.map +1 -1
- package/build/user-event/scroll/scroll-to.js +7 -7
- package/build/user-event/scroll/scroll-to.js.map +1 -1
- package/build/user-event/type/type.js +11 -11
- package/build/user-event/type/type.js.map +1 -1
- package/build/user-event/utils/dispatch-event.d.ts +1 -1
- package/build/user-event/utils/dispatch-event.js +4 -4
- package/build/user-event/utils/dispatch-event.js.map +1 -1
- package/build/wait-for.js +3 -1
- package/build/wait-for.js.map +1 -1
- package/build/within.d.ts +19 -19
- package/build/within.js +8 -8
- package/build/within.js.map +1 -1
- package/package.json +37 -35
- package/typings/index.flow.js +5 -4
- package/build/test-utils/index.d.ts +0 -1
- package/build/test-utils/index.js +0 -17
- package/build/test-utils/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"press.js","names":["_act","_interopRequireDefault","require","_eventHandler","_hostComponentNames","_pointerEvents","_eventBuilder","_utils","e","__esModule","default","DEFAULT_MIN_PRESS_DURATION","exports","DEFAULT_LONG_PRESS_DELAY_MS","press","element","basePress","config","type","longPress","options","duration","isEnabledHostElement","hasPressEventHandler","emitDirectPressEvents","isEnabledTouchResponder","emitPressabilityPressEvents","
|
|
1
|
+
{"version":3,"file":"press.js","names":["_act","_interopRequireDefault","require","_eventHandler","_componentTree","_errors","_hostComponentNames","_pointerEvents","_eventBuilder","_utils","e","__esModule","default","DEFAULT_MIN_PRESS_DURATION","exports","DEFAULT_LONG_PRESS_DELAY_MS","press","element","isHostElement","ErrorWithStack","basePress","config","type","longPress","options","duration","isEnabledHostElement","hasPressEventHandler","emitDirectPressEvents","isEnabledTouchResponder","emitPressabilityPressEvents","parent","isPointerEventEnabled","isHostText","props","disabled","isHostTextInput","editable","onStartShouldSetResponder","getEventHandlerFromProps","wait","dispatchEvent","EventBuilder","Common","touch","responderGrant","responderRelease","act"],"sources":["../../../src/user-event/press/press.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\n\nimport act from '../../act';\nimport { getEventHandlerFromProps } from '../../event-handler';\nimport { isHostElement } from '../../helpers/component-tree';\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { isHostText, isHostTextInput } from '../../helpers/host-component-names';\nimport { isPointerEventEnabled } from '../../helpers/pointer-events';\nimport { EventBuilder } from '../event-builder';\nimport type { 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 if (!isHostElement(element)) {\n throw new ErrorWithStack(`press() works only with host elements.`, press);\n }\n\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 if (!isHostElement(element)) {\n throw new ErrorWithStack(`longPress() works only with host elements.`, longPress);\n }\n\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 (isEnabledHostElement(element) && hasPressEventHandler(element)) {\n await emitDirectPressEvents(config, element, options);\n return;\n }\n\n if (isEnabledTouchResponder(element)) {\n await emitPressabilityPressEvents(config, element, options);\n return;\n }\n\n if (!element.parent) {\n return;\n }\n\n await basePress(config, element.parent, options);\n};\n\nfunction isEnabledHostElement(element: HostElement) {\n if (!isPointerEventEnabled(element)) {\n return false;\n }\n\n if (isHostText(element)) {\n return element.props.disabled !== true;\n }\n\n if (isHostTextInput(element)) {\n return element.props.editable !== false;\n }\n\n return true;\n}\n\nfunction isEnabledTouchResponder(element: HostElement) {\n return isPointerEventEnabled(element) && element.props.onStartShouldSetResponder?.();\n}\n\nfunction hasPressEventHandler(element: HostElement) {\n return (\n getEventHandlerFromProps(element.props, 'press') ||\n getEventHandlerFromProps(element.props, 'longPress') ||\n getEventHandlerFromProps(element.props, 'pressIn') ||\n getEventHandlerFromProps(element.props, 'pressOut')\n );\n}\n\n/**\n * Dispatches a press event sequence for host elements that have `onPress*` event handlers.\n */\nasync function emitDirectPressEvents(\n config: UserEventConfig,\n element: HostElement,\n options: BasePressOptions,\n) {\n await wait(config);\n await 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 await dispatchEvent(element, 'longPress', EventBuilder.Common.touch());\n }\n\n await 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 await dispatchEvent(element, 'press', EventBuilder.Common.touch());\n }\n}\n\nasync function emitPressabilityPressEvents(\n config: UserEventConfig,\n element: HostElement,\n options: BasePressOptions,\n) {\n await wait(config);\n\n await dispatchEvent(element, 'responderGrant', EventBuilder.Common.responderGrant());\n\n const duration = options.duration ?? DEFAULT_MIN_PRESS_DURATION;\n await wait(config, duration);\n\n await 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(() => wait(config, DEFAULT_MIN_PRESS_DURATION - duration));\n }\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AAEA,IAAAO,MAAA,GAAAP,OAAA;AAA+C,SAAAD,uBAAAS,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,OAAoB,EAAiB;EACxF,IAAI,CAAC,IAAAC,4BAAa,EAACD,OAAO,CAAC,EAAE;IAC3B,MAAM,IAAIE,sBAAc,CAAC,wCAAwC,EAAEH,KAAK,CAAC;EAC3E;EAEA,MAAMI,SAAS,CAAC,IAAI,CAACC,MAAM,EAAEJ,OAAO,EAAE;IACpCK,IAAI,EAAE;EACR,CAAC,CAAC;AACJ;AAEO,eAAeC,SAASA,CAE7BN,OAAoB,EACpBO,OAAsB,EACP;EACf,IAAI,CAAC,IAAAN,4BAAa,EAACD,OAAO,CAAC,EAAE;IAC3B,MAAM,IAAIE,sBAAc,CAAC,4CAA4C,EAAEI,SAAS,CAAC;EACnF;EAEA,MAAMH,SAAS,CAAC,IAAI,CAACC,MA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CAACE,cAAc,CAAC,CAAC,CAAC;EAEpF,MAAMpB,QAAQ,GAAGD,OAAO,CAACC,QAAQ,IAAIZ,0BAA0B;EAC/D,MAAM,IAAA2B,WAAI,EAACnB,MAAM,EAAEI,QAAQ,CAAC;EAE5B,MAAM,IAAAgB,oBAAa,EAACxB,OAAO,EAAE,kBAAkB,EAAEyB,0BAAY,CAACC,MAAM,CAACG,gBAAgB,CAAC,CAAC,CAAC;;EAExF;EACA;EACA;EACA,IAAIjC,0BAA0B,GAAGY,QAAQ,GAAG,CAAC,EAAE;IAC7C,MAAM,IAAAsB,YAAG,EAAC,MAAM,IAAAP,WAAI,EAACnB,MAAM,EAAER,0BAA0B,GAAGY,QAAQ,CAAC,CAAC;EACtE;AACF","ignoreList":[]}
|
|
@@ -17,7 +17,7 @@ async function scrollTo(element, options) {
|
|
|
17
17
|
throw new _errors.ErrorWithStack(`scrollTo() works only with host "ScrollView" elements. Passed element has type "${element.type}".`, scrollTo);
|
|
18
18
|
}
|
|
19
19
|
ensureScrollViewDirection(element, options);
|
|
20
|
-
(0, _utils.dispatchEvent)(element, 'contentSizeChange', options.contentSize?.width ?? 0, options.contentSize?.height ?? 0);
|
|
20
|
+
await (0, _utils.dispatchEvent)(element, 'contentSizeChange', options.contentSize?.width ?? 0, options.contentSize?.height ?? 0);
|
|
21
21
|
const initialOffset = _nativeState.nativeState.contentOffsetForElement.get(element) ?? {
|
|
22
22
|
x: 0,
|
|
23
23
|
y: 0
|
|
@@ -41,36 +41,36 @@ async function emitDragScrollEvents(config, element, scrollSteps, scrollOptions)
|
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
await (0, _utils.wait)(config);
|
|
44
|
-
(0, _utils.dispatchEvent)(element, 'scrollBeginDrag', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions));
|
|
44
|
+
await (0, _utils.dispatchEvent)(element, 'scrollBeginDrag', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions));
|
|
45
45
|
|
|
46
46
|
// Note: experimentally, in case of drag scroll the last scroll step
|
|
47
47
|
// will not trigger `scroll` event.
|
|
48
48
|
// See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events
|
|
49
49
|
for (let i = 1; i < scrollSteps.length - 1; i += 1) {
|
|
50
50
|
await (0, _utils.wait)(config);
|
|
51
|
-
(0, _utils.dispatchEvent)(element, 'scroll', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions));
|
|
51
|
+
await (0, _utils.dispatchEvent)(element, 'scroll', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions));
|
|
52
52
|
}
|
|
53
53
|
await (0, _utils.wait)(config);
|
|
54
54
|
const lastStep = scrollSteps.at(-1);
|
|
55
|
-
(0, _utils.dispatchEvent)(element, 'scrollEndDrag', _eventBuilder.EventBuilder.ScrollView.scroll(lastStep, scrollOptions));
|
|
55
|
+
await (0, _utils.dispatchEvent)(element, 'scrollEndDrag', _eventBuilder.EventBuilder.ScrollView.scroll(lastStep, scrollOptions));
|
|
56
56
|
}
|
|
57
57
|
async function emitMomentumScrollEvents(config, element, scrollSteps, scrollOptions) {
|
|
58
58
|
if (scrollSteps.length === 0) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
await (0, _utils.wait)(config);
|
|
62
|
-
(0, _utils.dispatchEvent)(element, 'momentumScrollBegin', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions));
|
|
62
|
+
await (0, _utils.dispatchEvent)(element, 'momentumScrollBegin', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions));
|
|
63
63
|
|
|
64
64
|
// Note: experimentally, in case of momentum scroll the last scroll step
|
|
65
65
|
// will trigger `scroll` event.
|
|
66
66
|
// See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events
|
|
67
67
|
for (let i = 1; i < scrollSteps.length; i += 1) {
|
|
68
68
|
await (0, _utils.wait)(config);
|
|
69
|
-
(0, _utils.dispatchEvent)(element, 'scroll', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions));
|
|
69
|
+
await (0, _utils.dispatchEvent)(element, 'scroll', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions));
|
|
70
70
|
}
|
|
71
71
|
await (0, _utils.wait)(config);
|
|
72
72
|
const lastStep = scrollSteps.at(-1);
|
|
73
|
-
(0, _utils.dispatchEvent)(element, 'momentumScrollEnd', _eventBuilder.EventBuilder.ScrollView.scroll(lastStep, scrollOptions));
|
|
73
|
+
await (0, _utils.dispatchEvent)(element, 'momentumScrollEnd', _eventBuilder.EventBuilder.ScrollView.scroll(lastStep, scrollOptions));
|
|
74
74
|
}
|
|
75
75
|
function ensureScrollViewDirection(element, options) {
|
|
76
76
|
const isVerticalScrollView = element.props.horizontal !== true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-to.js","names":["_jestMatcherUtils","require","_errors","_hostComponentNames","_object","_nativeState","_eventBuilder","_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 type { HostElement } from 'universal-test-renderer';\n\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { isHostScrollView } from '../../helpers/host-component-names';\nimport { pick } from '../../helpers/object';\nimport { nativeState } from '../../native-state';\nimport type { Point, Size } from '../../types';\nimport { EventBuilder } from '../event-builder';\nimport type { UserEventConfig, UserEventInstance } from '../setup';\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,OAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AAEA,IAAAK,aAAA,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,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,OAAO,CAACc,CAAC;IAAED,CAAC,EAAEb,OAAO,CAACa;EAAE,CAAC,EAC9BJ,aAAa,EACbQ,0BACF,CAAC;EACD,MAAMC,oBAAoB,CAAC,IAAI,CAACC,MAAM,E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AE;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
|
+
{"version":3,"file":"scroll-to.js","names":["_jestMatcherUtils","require","_errors","_hostComponentNames","_object","_nativeState","_eventBuilder","_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 type { HostElement } from 'universal-test-renderer';\n\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { isHostScrollView } from '../../helpers/host-component-names';\nimport { pick } from '../../helpers/object';\nimport { nativeState } from '../../native-state';\nimport type { Point, Size } from '../../types';\nimport { EventBuilder } from '../event-builder';\nimport type { UserEventConfig, UserEventInstance } from '../setup';\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 await 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 await 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 await dispatchEvent(\n element,\n 'scroll',\n EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions),\n );\n }\n\n await wait(config);\n const lastStep = scrollSteps.at(-1);\n await dispatchEvent(\n element,\n 'scrollEndDrag',\n EventBuilder.ScrollView.scroll(lastStep, scrollOptions),\n );\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 await 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 await dispatchEvent(\n element,\n 'scroll',\n EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions),\n );\n }\n\n await wait(config);\n const lastStep = scrollSteps.at(-1);\n await 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,OAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AAEA,IAAAK,aAAA,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,MAAM,IAAAK,oBAAa,EACjBN,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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,MAAMkB,QAAQ,GAAGR,WAAW,CAACR,EAAE,CAAC,CAAC,CAAC,CAAC;EACnC,MAAM,IAAAhB,oBAAa,EACjBN,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":[]}
|
|
@@ -24,12 +24,12 @@ async function type(element, text, options) {
|
|
|
24
24
|
}
|
|
25
25
|
const keys = (0, _parseKeys.parseKeys)(text);
|
|
26
26
|
if (!options?.skipPress) {
|
|
27
|
-
(0, _utils.dispatchEvent)(element, 'pressIn', _eventBuilder.EventBuilder.Common.touch());
|
|
27
|
+
await (0, _utils.dispatchEvent)(element, 'pressIn', _eventBuilder.EventBuilder.Common.touch());
|
|
28
28
|
}
|
|
29
|
-
(0, _utils.dispatchEvent)(element, 'focus', _eventBuilder.EventBuilder.Common.focus());
|
|
29
|
+
await (0, _utils.dispatchEvent)(element, 'focus', _eventBuilder.EventBuilder.Common.focus());
|
|
30
30
|
if (!options?.skipPress) {
|
|
31
31
|
await (0, _utils.wait)(this.config);
|
|
32
|
-
(0, _utils.dispatchEvent)(element, 'pressOut', _eventBuilder.EventBuilder.Common.touch());
|
|
32
|
+
await (0, _utils.dispatchEvent)(element, 'pressOut', _eventBuilder.EventBuilder.Common.touch());
|
|
33
33
|
}
|
|
34
34
|
let currentText = (0, _textInput.getTextInputValue)(element);
|
|
35
35
|
for (const key of keys) {
|
|
@@ -47,11 +47,11 @@ async function type(element, text, options) {
|
|
|
47
47
|
const finalText = (0, _textInput.getTextInputValue)(element);
|
|
48
48
|
await (0, _utils.wait)(this.config);
|
|
49
49
|
if (options?.submitEditing) {
|
|
50
|
-
(0, _utils.dispatchEvent)(element, 'submitEditing', _eventBuilder.EventBuilder.TextInput.submitEditing(finalText));
|
|
50
|
+
await (0, _utils.dispatchEvent)(element, 'submitEditing', _eventBuilder.EventBuilder.TextInput.submitEditing(finalText));
|
|
51
51
|
}
|
|
52
52
|
if (!options?.skipBlur) {
|
|
53
|
-
(0, _utils.dispatchEvent)(element, 'endEditing', _eventBuilder.EventBuilder.TextInput.endEditing(finalText));
|
|
54
|
-
(0, _utils.dispatchEvent)(element, 'blur', _eventBuilder.EventBuilder.Common.blur());
|
|
53
|
+
await (0, _utils.dispatchEvent)(element, 'endEditing', _eventBuilder.EventBuilder.TextInput.endEditing(finalText));
|
|
54
|
+
await (0, _utils.dispatchEvent)(element, 'blur', _eventBuilder.EventBuilder.Common.blur());
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
async function emitTypingEvents(element, {
|
|
@@ -62,7 +62,7 @@ async function emitTypingEvents(element, {
|
|
|
62
62
|
}) {
|
|
63
63
|
const isMultiline = element.props.multiline === true;
|
|
64
64
|
await (0, _utils.wait)(config);
|
|
65
|
-
(0, _utils.dispatchEvent)(element, 'keyPress', _eventBuilder.EventBuilder.TextInput.keyPress(key));
|
|
65
|
+
await (0, _utils.dispatchEvent)(element, 'keyPress', _eventBuilder.EventBuilder.TextInput.keyPress(key));
|
|
66
66
|
|
|
67
67
|
// Platform difference (based on experiments):
|
|
68
68
|
// - iOS and RN Web: TextInput emits only `keyPress` event when max length has been reached
|
|
@@ -71,19 +71,19 @@ async function emitTypingEvents(element, {
|
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
73
|
_nativeState.nativeState.valueForElement.set(element, text);
|
|
74
|
-
(0, _utils.dispatchEvent)(element, 'change', _eventBuilder.EventBuilder.TextInput.change(text));
|
|
75
|
-
(0, _utils.dispatchEvent)(element, 'changeText', text);
|
|
74
|
+
await (0, _utils.dispatchEvent)(element, 'change', _eventBuilder.EventBuilder.TextInput.change(text));
|
|
75
|
+
await (0, _utils.dispatchEvent)(element, 'changeText', text);
|
|
76
76
|
const selectionRange = {
|
|
77
77
|
start: text.length,
|
|
78
78
|
end: text.length
|
|
79
79
|
};
|
|
80
|
-
(0, _utils.dispatchEvent)(element, 'selectionChange', _eventBuilder.EventBuilder.TextInput.selectionChange(selectionRange));
|
|
80
|
+
await (0, _utils.dispatchEvent)(element, 'selectionChange', _eventBuilder.EventBuilder.TextInput.selectionChange(selectionRange));
|
|
81
81
|
|
|
82
82
|
// According to the docs only multiline TextInput emits contentSizeChange event
|
|
83
83
|
// @see: https://reactnative.dev/docs/textinput#oncontentsizechange
|
|
84
84
|
if (isMultiline) {
|
|
85
85
|
const contentSize = (0, _utils.getTextContentSize)(text);
|
|
86
|
-
(0, _utils.dispatchEvent)(element, 'contentSizeChange', _eventBuilder.EventBuilder.TextInput.contentSizeChange(contentSize));
|
|
86
|
+
await (0, _utils.dispatchEvent)(element, 'contentSizeChange', _eventBuilder.EventBuilder.TextInput.contentSizeChange(contentSize));
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
function applyKey(text, key) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","names":["_errors","require","_hostComponentNames","_pointerEvents","_textInput","_nativeState","_eventBuilder","_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","skipBlur","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 type { HostElement } from 'universal-test-renderer';\n\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { isHostTextInput } from '../../helpers/host-component-names';\nimport { isPointerEventEnabled } from '../../helpers/pointer-events';\nimport { getTextInputValue, isEditableTextInput } from '../../helpers/text-input';\nimport { nativeState } from '../../native-state';\nimport { EventBuilder } from '../event-builder';\nimport type { UserEventConfig, UserEventInstance } from '../setup';\nimport { dispatchEvent, getTextContentSize, wait } from '../utils';\nimport { parseKeys } from './parse-keys';\n\nexport interface TypeOptions {\n skipPress?: boolean;\n submitEditing?: boolean;\n skipBlur?: 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 if (!options?.skipBlur) {\n dispatchEvent(element, 'endEditing', EventBuilder.TextInput.endEditing(finalText));\n dispatchEvent(element, 'blur', EventBuilder.Common.blur());\n }\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
|
|
1
|
+
{"version":3,"file":"type.js","names":["_errors","require","_hostComponentNames","_pointerEvents","_textInput","_nativeState","_eventBuilder","_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","skipBlur","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 type { HostElement } from 'universal-test-renderer';\n\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { isHostTextInput } from '../../helpers/host-component-names';\nimport { isPointerEventEnabled } from '../../helpers/pointer-events';\nimport { getTextInputValue, isEditableTextInput } from '../../helpers/text-input';\nimport { nativeState } from '../../native-state';\nimport { EventBuilder } from '../event-builder';\nimport type { UserEventConfig, UserEventInstance } from '../setup';\nimport { dispatchEvent, getTextContentSize, wait } from '../utils';\nimport { parseKeys } from './parse-keys';\n\nexport interface TypeOptions {\n skipPress?: boolean;\n submitEditing?: boolean;\n skipBlur?: 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 await dispatchEvent(element, 'pressIn', EventBuilder.Common.touch());\n }\n\n await dispatchEvent(element, 'focus', EventBuilder.Common.focus());\n\n if (!options?.skipPress) {\n await wait(this.config);\n await 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 await dispatchEvent(element, 'submitEditing', EventBuilder.TextInput.submitEditing(finalText));\n }\n\n if (!options?.skipBlur) {\n await dispatchEvent(element, 'endEditing', EventBuilder.TextInput.endEditing(finalText));\n await dispatchEvent(element, 'blur', EventBuilder.Common.blur());\n }\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 await 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 await dispatchEvent(element, 'change', EventBuilder.TextInput.change(text));\n await dispatchEvent(element, 'changeText', text);\n\n const selectionRange = {\n start: text.length,\n end: text.length,\n };\n await dispatchEvent(\n element,\n 'selectionChange',\n EventBuilder.TextInput.selectionChange(selectionRange),\n );\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 await 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":";;;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAA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@ import type { HostElement } from 'universal-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: HostElement, eventName: string, ...event: unknown[]): void
|
|
9
|
+
export declare function dispatchEvent(element: HostElement, eventName: string, ...event: unknown[]): Promise<void>;
|
|
@@ -15,17 +15,17 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
15
15
|
* @param eventName name of the event
|
|
16
16
|
* @param event event payload(s)
|
|
17
17
|
*/
|
|
18
|
-
function dispatchEvent(element, eventName, ...event) {
|
|
18
|
+
async function dispatchEvent(element, eventName, ...event) {
|
|
19
19
|
if (!(0, _componentTree.isElementMounted)(element)) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
const handler = (0, _eventHandler.
|
|
22
|
+
const handler = (0, _eventHandler.getEventHandlerFromProps)(element.props, eventName);
|
|
23
23
|
if (!handler) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
//
|
|
28
|
-
|
|
27
|
+
// eslint-disable-next-line require-await
|
|
28
|
+
await (0, _act.default)(async () => {
|
|
29
29
|
handler(...event);
|
|
30
30
|
});
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","_eventHandler","_componentTree","e","__esModule","default","dispatchEvent","element","eventName","event","isElementMounted","handler","
|
|
1
|
+
{"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","_eventHandler","_componentTree","e","__esModule","default","dispatchEvent","element","eventName","event","isElementMounted","handler","getEventHandlerFromProps","props","act"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\n\nimport act from '../../act';\nimport { getEventHandlerFromProps } from '../../event-handler';\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 async function dispatchEvent(element: HostElement, eventName: string, ...event: unknown[]) {\n if (!isElementMounted(element)) {\n return;\n }\n\n const handler = getEventHandlerFromProps(element.props, eventName);\n if (!handler) {\n return;\n }\n\n // eslint-disable-next-line require-await\n await act(async () => {\n handler(...event);\n });\n}\n"],"mappings":";;;;;;AAEA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAAgE,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeG,aAAaA,CAACC,OAAoB,EAAEC,SAAiB,EAAE,GAAGC,KAAgB,EAAE;EAChG,IAAI,CAAC,IAAAC,+BAAgB,EAACH,OAAO,CAAC,EAAE;IAC9B;EACF;EAEA,MAAMI,OAAO,GAAG,IAAAC,sCAAwB,EAACL,OAAO,CAACM,KAAK,EAAEL,SAAS,CAAC;EAClE,IAAI,CAACG,OAAO,EAAE;IACZ;EACF;;EAEA;EACA,MAAM,IAAAG,YAAG,EAAC,YAAY;IACpBH,OAAO,CAAC,GAAGF,KAAK,CAAC;EACnB,CAAC,CAAC;AACJ","ignoreList":[]}
|
package/build/wait-for.js
CHANGED
|
@@ -4,11 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = waitFor;
|
|
7
|
+
var _act = _interopRequireDefault(require("./act"));
|
|
7
8
|
var _config = require("./config");
|
|
8
9
|
var _flushMicroTasks = require("./flush-micro-tasks");
|
|
9
10
|
var _errors = require("./helpers/errors");
|
|
10
11
|
var _timers = require("./helpers/timers");
|
|
11
12
|
var _wrapAsync = require("./helpers/wrap-async");
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
14
|
/* globals jest */
|
|
13
15
|
|
|
14
16
|
const DEFAULT_INTERVAL = 50;
|
|
@@ -59,7 +61,7 @@ function waitForInternal(expectation, {
|
|
|
59
61
|
// third party code that's setting up recursive timers so rapidly that
|
|
60
62
|
// the user's timer's don't get a chance to resolve. So we'll advance
|
|
61
63
|
// by an interval instead. (We have a test for this case).
|
|
62
|
-
jest.advanceTimersByTime(interval);
|
|
64
|
+
await (0, _act.default)(async () => await jest.advanceTimersByTime(interval));
|
|
63
65
|
|
|
64
66
|
// It's really important that checkExpectation is run *before* we flush
|
|
65
67
|
// in-flight promises. To be honest, I'm not sure why, and I can't quite
|
package/build/wait-for.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wait-for.js","names":["_config","require","_flushMicroTasks","_errors","_timers","_wrapAsync","DEFAULT_INTERVAL","waitForInternal","expectation","timeout","getConfig","asyncUtilTimeout","interval","stackTraceError","onTimeout","TypeError","Promise","resolve","reject","lastError","intervalId","finished","promiseStatus","overallTimeoutTimer","usingFakeTimers","jestFakeTimersAreEnabled","checkExpectation","fakeTimeRemaining","error","Error","copyStackTrace","handleTimeout","jest","advanceTimersByTime","flushMicroTasks","setTimeout","setInterval","checkRealTimersCallback","onDone","done","clearTimeout","clearInterval","type","result","then","promiseResult","resolvedValue","rejectedValue","String","waitFor","options","ErrorWithStack","optionsWithStackTrace","wrapAsync"],"sources":["../src/wait-for.ts"],"sourcesContent":["/* globals jest */\nimport { getConfig } from './config';\nimport { flushMicroTasks } from './flush-micro-tasks';\nimport { copyStackTrace, ErrorWithStack } from './helpers/errors';\nimport { clearTimeout, jestFakeTimersAreEnabled, setTimeout } from './helpers/timers';\nimport { wrapAsync } from './helpers/wrap-async';\n\nconst DEFAULT_INTERVAL = 50;\n\nexport type WaitForOptions = {\n timeout?: number;\n interval?: number;\n stackTraceError?: ErrorWithStack;\n onTimeout?: (error: Error) => Error;\n};\n\nfunction waitForInternal<T>(\n expectation: () => T,\n {\n timeout = getConfig().asyncUtilTimeout,\n interval = DEFAULT_INTERVAL,\n stackTraceError,\n onTimeout,\n }: WaitForOptions,\n): Promise<T> {\n if (typeof expectation !== 'function') {\n throw new TypeError('Received `expectation` arg must be a function');\n }\n\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n let lastError: unknown, intervalId: ReturnType<typeof setTimeout>;\n let finished = false;\n let promiseStatus = 'idle';\n\n let overallTimeoutTimer: NodeJS.Timeout | null = null;\n\n const usingFakeTimers = jestFakeTimersAreEnabled();\n\n if (usingFakeTimers) {\n checkExpectation();\n // this is a dangerous rule to disable because it could lead to an\n // infinite loop. However, eslint isn't smart enough to know that we're\n // setting finished inside `onDone` which will be called when we're done\n // waiting or when we've timed out.\n let fakeTimeRemaining = timeout;\n while (!finished) {\n if (!jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`,\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n reject(error);\n return;\n }\n\n // when fake timers are used we want to simulate the interval time passing\n if (fakeTimeRemaining <= 0) {\n handleTimeout();\n return;\n } else {\n fakeTimeRemaining -= interval;\n }\n\n // we *could* (maybe should?) use `advanceTimersToNextTimer` but it's\n // possible that could make this loop go on forever if someone is using\n // third party code that's setting up recursive timers so rapidly that\n // the user's timer's don't get a chance to resolve. So we'll advance\n // by an interval instead. (We have a test for this case).\n jest.advanceTimersByTime(interval);\n\n // It's really important that checkExpectation is run *before* we flush\n // in-flight promises. To be honest, I'm not sure why, and I can't quite\n // think of a way to reproduce the problem in a test, but I spent\n // an entire day banging my head against a wall on this.\n checkExpectation();\n\n // In this rare case, we *need* to wait for in-flight promises\n // to resolve before continuing. We don't need to take advantage\n // of parallelization so we're fine.\n // https://stackoverflow.com/a/59243586/971592\n await flushMicroTasks();\n }\n } else {\n overallTimeoutTimer = setTimeout(handleTimeout, timeout);\n intervalId = setInterval(checkRealTimersCallback, interval);\n checkExpectation();\n }\n\n function onDone(done: { type: 'result'; result: T } | { type: 'error'; error: unknown }) {\n finished = true;\n if (overallTimeoutTimer) {\n clearTimeout(overallTimeoutTimer);\n }\n\n if (!usingFakeTimers) {\n clearInterval(intervalId);\n }\n\n if (done.type === 'error') {\n reject(done.error);\n } else {\n resolve(done.result);\n }\n }\n\n function checkRealTimersCallback() {\n if (jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`,\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n return reject(error);\n } else {\n return checkExpectation();\n }\n }\n\n function checkExpectation() {\n if (promiseStatus === 'pending') return;\n try {\n const result = expectation();\n\n // @ts-expect-error result can be a promise\n if (typeof result?.then === 'function') {\n const promiseResult: Promise<T> = result as unknown as Promise<T>;\n promiseStatus = 'pending';\n // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then\n promiseResult.then(\n (resolvedValue) => {\n promiseStatus = 'resolved';\n onDone({ type: 'result', result: resolvedValue });\n return;\n },\n (rejectedValue) => {\n promiseStatus = 'rejected';\n lastError = rejectedValue;\n return;\n },\n );\n } else {\n onDone({ type: 'result', result: result });\n }\n // If `callback` throws, wait for the next mutation, interval, or timeout.\n } catch (error) {\n // Save the most recent callback error to reject the promise with it in the event of a timeout\n lastError = error;\n }\n }\n\n function handleTimeout() {\n let error: Error;\n if (lastError) {\n if (lastError instanceof Error) {\n error = lastError;\n } else {\n error = new Error(String(lastError));\n }\n\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n } else {\n error = new Error('Timed out in waitFor.');\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n }\n if (typeof onTimeout === 'function') {\n const result = onTimeout(error);\n if (result) {\n error = result;\n }\n }\n onDone({ type: 'error', error });\n }\n });\n}\n\nexport default function waitFor<T>(expectation: () => T, options?: WaitForOptions): Promise<T> {\n // Being able to display a useful stack trace requires generating it before doing anything async\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', waitFor);\n const optionsWithStackTrace = { stackTraceError, ...options };\n\n return wrapAsync(() => waitForInternal(expectation, optionsWithStackTrace));\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AALA;;AAOA,MAAMK,gBAAgB,GAAG,EAAE;AAS3B,SAASC,eAAeA,CACtBC,WAAoB,EACpB;EACEC,OAAO,GAAG,IAAAC,iBAAS,EAAC,CAAC,CAACC,gBAAgB;EACtCC,QAAQ,GAAGN,gBAAgB;EAC3BO,eAAe;EACfC;AACc,CAAC,EACL;EACZ,IAAI,OAAON,WAAW,KAAK,UAAU,EAAE;IACrC,MAAM,IAAIO,SAAS,CAAC,+CAA+C,CAAC;EACtE;;EAEA;EACA,OAAO,IAAIC,OAAO,CAAC,OAAOC,OAAO,EAAEC,MAAM,KAAK;IAC5C,IAAIC,SAAkB,EAAEC,UAAyC;IACjE,IAAIC,QAAQ,GAAG,KAAK;IACpB,IAAIC,aAAa,GAAG,MAAM;IAE1B,IAAIC,mBAA0C,GAAG,IAAI;IAErD,MAAMC,eAAe,GAAG,IAAAC,gCAAwB,EAAC,CAAC;IAElD,IAAID,eAAe,EAAE;MACnBE,gBAAgB,CAAC,CAAC;MAClB;MACA;MACA;MACA;MACA,IAAIC,iBAAiB,GAAGlB,OAAO;MAC/B,OAAO,CAACY,QAAQ,EAAE;QAChB,IAAI,CAAC,IAAAI,gCAAwB,EAAC,CAAC,EAAE;UAC/B,M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K,CAAC,uBAAuB,CAAC;QAC1C,IAAIhB,eAAe,EAAE;UACnB,IAAAiB,sBAAc,EAACF,KAAK,EAAEf,eAAe,CAAC;QACxC;MACF;MACA,IAAI,OAAOC,SAAS,KAAK,UAAU,EAAE;QACnC,MAAM6B,MAAM,GAAG7B,SAAS,CAACc,KAAK,CAAC;QAC/B,IAAIe,MAAM,EAAE;UACVf,KAAK,GAAGe,MAAM;QAChB;MACF;MACAL,MAAM,CAAC;QAAEI,IAAI,EAAE,OAAO;QAAEd;MAAM,CAAC,CAAC;IAClC;EACF,CAAC,CAAC;AACJ;AAEe,SAASqB,OAAOA,CAAIzC,WAAoB,EAAE0C,OAAwB,EAAc;EAC7F;EACA,MAAMrC,eAAe,GAAG,IAAIsC,sBAAc,CAAC,mBAAmB,EAAEF,OAAO,CAAC;EACxE,MAAMG,qBAAqB,GAAG;IAAEvC,eAAe;IAAE,GAAGqC;EAAQ,CAAC;EAE7D,OAAO,IAAAG,oBAAS,EAAC,MAAM9C,eAAe,CAACC,WAAW,EAAE4C,qBAAqB,CAAC,CAAC;AAC7E","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"wait-for.js","names":["_act","_interopRequireDefault","require","_config","_flushMicroTasks","_errors","_timers","_wrapAsync","e","__esModule","default","DEFAULT_INTERVAL","waitForInternal","expectation","timeout","getConfig","asyncUtilTimeout","interval","stackTraceError","onTimeout","TypeError","Promise","resolve","reject","lastError","intervalId","finished","promiseStatus","overallTimeoutTimer","usingFakeTimers","jestFakeTimersAreEnabled","checkExpectation","fakeTimeRemaining","error","Error","copyStackTrace","handleTimeout","act","jest","advanceTimersByTime","flushMicroTasks","setTimeout","setInterval","checkRealTimersCallback","onDone","done","clearTimeout","clearInterval","type","result","then","promiseResult","resolvedValue","rejectedValue","String","waitFor","options","ErrorWithStack","optionsWithStackTrace","wrapAsync"],"sources":["../src/wait-for.ts"],"sourcesContent":["/* globals jest */\nimport act from './act';\nimport { getConfig } from './config';\nimport { flushMicroTasks } from './flush-micro-tasks';\nimport { copyStackTrace, ErrorWithStack } from './helpers/errors';\nimport { clearTimeout, jestFakeTimersAreEnabled, setTimeout } from './helpers/timers';\nimport { wrapAsync } from './helpers/wrap-async';\n\nconst DEFAULT_INTERVAL = 50;\n\nexport type WaitForOptions = {\n timeout?: number;\n interval?: number;\n stackTraceError?: ErrorWithStack;\n onTimeout?: (error: Error) => Error;\n};\n\nfunction waitForInternal<T>(\n expectation: () => T,\n {\n timeout = getConfig().asyncUtilTimeout,\n interval = DEFAULT_INTERVAL,\n stackTraceError,\n onTimeout,\n }: WaitForOptions,\n): Promise<T> {\n if (typeof expectation !== 'function') {\n throw new TypeError('Received `expectation` arg must be a function');\n }\n\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n let lastError: unknown, intervalId: ReturnType<typeof setTimeout>;\n let finished = false;\n let promiseStatus = 'idle';\n\n let overallTimeoutTimer: NodeJS.Timeout | null = null;\n\n const usingFakeTimers = jestFakeTimersAreEnabled();\n\n if (usingFakeTimers) {\n checkExpectation();\n // this is a dangerous rule to disable because it could lead to an\n // infinite loop. However, eslint isn't smart enough to know that we're\n // setting finished inside `onDone` which will be called when we're done\n // waiting or when we've timed out.\n let fakeTimeRemaining = timeout;\n while (!finished) {\n if (!jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`,\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n reject(error);\n return;\n }\n\n // when fake timers are used we want to simulate the interval time passing\n if (fakeTimeRemaining <= 0) {\n handleTimeout();\n return;\n } else {\n fakeTimeRemaining -= interval;\n }\n\n // we *could* (maybe should?) use `advanceTimersToNextTimer` but it's\n // possible that could make this loop go on forever if someone is using\n // third party code that's setting up recursive timers so rapidly that\n // the user's timer's don't get a chance to resolve. So we'll advance\n // by an interval instead. (We have a test for this case).\n await act(async () => await jest.advanceTimersByTime(interval));\n\n // It's really important that checkExpectation is run *before* we flush\n // in-flight promises. To be honest, I'm not sure why, and I can't quite\n // think of a way to reproduce the problem in a test, but I spent\n // an entire day banging my head against a wall on this.\n checkExpectation();\n\n // In this rare case, we *need* to wait for in-flight promises\n // to resolve before continuing. We don't need to take advantage\n // of parallelization so we're fine.\n // https://stackoverflow.com/a/59243586/971592\n await flushMicroTasks();\n }\n } else {\n overallTimeoutTimer = setTimeout(handleTimeout, timeout);\n intervalId = setInterval(checkRealTimersCallback, interval);\n checkExpectation();\n }\n\n function onDone(done: { type: 'result'; result: T } | { type: 'error'; error: unknown }) {\n finished = true;\n if (overallTimeoutTimer) {\n clearTimeout(overallTimeoutTimer);\n }\n\n if (!usingFakeTimers) {\n clearInterval(intervalId);\n }\n\n if (done.type === 'error') {\n reject(done.error);\n } else {\n resolve(done.result);\n }\n }\n\n function checkRealTimersCallback() {\n if (jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`,\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n return reject(error);\n } else {\n return checkExpectation();\n }\n }\n\n function checkExpectation() {\n if (promiseStatus === 'pending') return;\n try {\n const result = expectation();\n\n // @ts-expect-error result can be a promise\n if (typeof result?.then === 'function') {\n const promiseResult: Promise<T> = result as unknown as Promise<T>;\n promiseStatus = 'pending';\n // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then\n promiseResult.then(\n (resolvedValue) => {\n promiseStatus = 'resolved';\n onDone({ type: 'result', result: resolvedValue });\n return;\n },\n (rejectedValue) => {\n promiseStatus = 'rejected';\n lastError = rejectedValue;\n return;\n },\n );\n } else {\n onDone({ type: 'result', result: result });\n }\n // If `callback` throws, wait for the next mutation, interval, or timeout.\n } catch (error) {\n // Save the most recent callback error to reject the promise with it in the event of a timeout\n lastError = error;\n }\n }\n\n function handleTimeout() {\n let error: Error;\n if (lastError) {\n if (lastError instanceof Error) {\n error = lastError;\n } else {\n error = new Error(String(lastError));\n }\n\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n } else {\n error = new Error('Timed out in waitFor.');\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n }\n if (typeof onTimeout === 'function') {\n const result = onTimeout(error);\n if (result) {\n error = result;\n }\n }\n onDone({ type: 'error', error });\n }\n });\n}\n\nexport default function waitFor<T>(expectation: () => T, options?: WaitForOptions): Promise<T> {\n // Being able to display a useful stack trace requires generating it before doing anything async\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', waitFor);\n const optionsWithStackTrace = { stackTraceError, ...options };\n\n return wrapAsync(() => waitForInternal(expectation, optionsWithStackTrace));\n}\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAAiD,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AANjD;;AAQA,MAAMG,gBAAgB,GAAG,EAAE;AAS3B,SAASC,eAAeA,CACtBC,WAAoB,EACpB;EACEC,OAAO,GAAG,IAAAC,iBAAS,EAAC,CAAC,CAACC,gBAAgB;EACtCC,QAAQ,GAAGN,gBAAgB;EAC3BO,eAAe;EACfC;AACc,CAAC,EACL;EACZ,IAAI,OAAON,WAAW,KAAK,UAAU,EAAE;IACrC,MAAM,IAAIO,SAAS,CAAC,+CAA+C,CAAC;EACtE;;EAEA;EACA,OAAO,IAAIC,OAAO,CAAC,OAAOC,OAAO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
2
|
-
export declare function within(
|
|
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>;
|
|
2
|
+
export declare function within(element: HostElement): {
|
|
15
3
|
getByRole: import("./queries/make-queries").GetByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
|
|
16
4
|
getAllByRole: import("./queries/make-queries").GetAllByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
|
|
17
5
|
queryByRole: import("./queries/make-queries").QueryByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
|
|
18
6
|
queryAllByRole: import("./queries/make-queries").QueryAllByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
|
|
19
7
|
findByRole: import("./queries/make-queries").FindByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
|
|
20
8
|
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>;
|
|
27
9
|
getByHintText: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
28
10
|
getAllByHintText: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
29
11
|
queryByHintText: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
@@ -42,6 +24,12 @@ export declare function within(instance: HostElement): {
|
|
|
42
24
|
queryAllByAccessibilityHint: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
43
25
|
findByAccessibilityHint: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
44
26
|
findAllByAccessibilityHint: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
27
|
+
getByLabelText: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
28
|
+
getAllByLabelText: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
29
|
+
queryByLabelText: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
30
|
+
queryAllByLabelText: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
31
|
+
findByLabelText: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
32
|
+
findAllByLabelText: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
45
33
|
getByPlaceholderText: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
46
34
|
getAllByPlaceholderText: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
47
35
|
queryByPlaceholderText: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
@@ -54,5 +42,17 @@ export declare function within(instance: HostElement): {
|
|
|
54
42
|
queryAllByDisplayValue: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
55
43
|
findByDisplayValue: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
56
44
|
findAllByDisplayValue: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
45
|
+
getByTestId: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
46
|
+
getAllByTestId: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
47
|
+
queryByTestId: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
48
|
+
queryAllByTestId: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
49
|
+
findByTestId: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
50
|
+
findAllByTestId: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
51
|
+
getByText: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
52
|
+
getAllByText: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
53
|
+
queryByText: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
54
|
+
queryAllByText: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
55
|
+
findByText: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
56
|
+
findAllByText: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
57
57
|
};
|
|
58
58
|
export declare const getQueriesForElement: typeof within;
|
package/build/within.js
CHANGED
|
@@ -12,15 +12,15 @@ var _placeholderText = require("./queries/placeholder-text");
|
|
|
12
12
|
var _role = require("./queries/role");
|
|
13
13
|
var _testId = require("./queries/test-id");
|
|
14
14
|
var _text = require("./queries/text");
|
|
15
|
-
function within(
|
|
15
|
+
function within(element) {
|
|
16
16
|
return {
|
|
17
|
-
...(0,
|
|
18
|
-
...(0,
|
|
19
|
-
...(0,
|
|
20
|
-
...(0,
|
|
21
|
-
...(0,
|
|
22
|
-
...(0,
|
|
23
|
-
...(0,
|
|
17
|
+
...(0, _text.bindByTextQueries)(element),
|
|
18
|
+
...(0, _testId.bindByTestIdQueries)(element),
|
|
19
|
+
...(0, _displayValue.bindByDisplayValueQueries)(element),
|
|
20
|
+
...(0, _placeholderText.bindByPlaceholderTextQueries)(element),
|
|
21
|
+
...(0, _labelText.bindByLabelTextQueries)(element),
|
|
22
|
+
...(0, _hintText.bindByHintTextQueries)(element),
|
|
23
|
+
...(0, _role.bindByRoleQueries)(element)
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
const getQueriesForElement = exports.getQueriesForElement = within;
|
package/build/within.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"within.js","names":["_displayValue","require","_hintText","_labelText","_placeholderText","_role","_testId","_text","within","
|
|
1
|
+
{"version":3,"file":"within.js","names":["_displayValue","require","_hintText","_labelText","_placeholderText","_role","_testId","_text","within","element","bindByTextQueries","bindByTestIdQueries","bindByDisplayValueQueries","bindByPlaceholderTextQueries","bindByLabelTextQueries","bindByHintTextQueries","bindByRoleQueries","getQueriesForElement","exports"],"sources":["../src/within.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\n\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(element: HostElement) {\n return {\n ...bindByTextQueries(element),\n ...bindByTestIdQueries(element),\n ...bindByDisplayValueQueries(element),\n ...bindByPlaceholderTextQueries(element),\n ...bindByLabelTextQueries(element),\n ...bindByHintTextQueries(element),\n ...bindByRoleQueries(element),\n };\n}\n\nexport const getQueriesForElement = within;\n"],"mappings":";;;;;;;AAEA,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,OAAoB,EAAE;EAC3C,OAAO;IACL,GAAG,IAAAC,uBAAiB,EAACD,OAAO,CAAC;IAC7B,GAAG,IAAAE,2BAAmB,EAACF,OAAO,CAAC;IAC/B,GAAG,IAAAG,uCAAyB,EAACH,OAAO,CAAC;IACrC,GAAG,IAAAI,6CAA4B,EAACJ,OAAO,CAAC;IACxC,GAAG,IAAAK,iCAAsB,EAACL,OAAO,CAAC;IAClC,GAAG,IAAAM,+BAAqB,EAACN,OAAO,CAAC;IACjC,GAAG,IAAAO,uBAAiB,EAACP,OAAO;EAC9B,CAAC;AACH;AAEO,MAAMQ,oBAAoB,GAAAC,OAAA,CAAAD,oBAAA,GAAGT,MAAM","ignoreList":[]}
|