@testing-library/react-native 13.2.0 → 14.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/act.d.ts +5 -4
- package/build/act.js +3 -6
- package/build/act.js.map +1 -1
- package/build/config.d.ts +0 -10
- package/build/config.js +1 -2
- package/build/config.js.map +1 -1
- package/build/event-handler.d.ts +2 -2
- package/build/event-handler.js.map +1 -1
- package/build/fire-event.d.ts +7 -7
- package/build/fire-event.js +26 -4
- package/build/fire-event.js.map +1 -1
- package/build/helpers/accessibility.d.ts +14 -14
- package/build/helpers/accessibility.js +2 -2
- package/build/helpers/accessibility.js.map +1 -1
- package/build/helpers/component-tree.d.ts +7 -31
- package/build/helpers/component-tree.js +15 -73
- package/build/helpers/component-tree.js.map +1 -1
- package/build/helpers/debug.d.ts +2 -2
- package/build/helpers/debug.js +5 -4
- package/build/helpers/debug.js.map +1 -1
- package/build/helpers/find-all.d.ts +2 -3
- package/build/helpers/find-all.js +5 -5
- package/build/helpers/find-all.js.map +1 -1
- package/build/helpers/format-element.d.ts +4 -4
- package/build/helpers/format-element.js +6 -7
- package/build/helpers/format-element.js.map +1 -1
- package/build/helpers/host-component-names.d.ts +8 -8
- package/build/helpers/host-component-names.js +9 -7
- package/build/helpers/host-component-names.js.map +1 -1
- package/build/helpers/matchers/match-accessibility-state.d.ts +2 -2
- package/build/helpers/matchers/match-accessibility-state.js.map +1 -1
- package/build/helpers/matchers/match-accessibility-value.d.ts +2 -2
- package/build/helpers/matchers/match-accessibility-value.js.map +1 -1
- package/build/helpers/matchers/match-label-text.d.ts +2 -2
- package/build/helpers/matchers/match-label-text.js.map +1 -1
- package/build/helpers/matchers/match-text-content.d.ts +2 -2
- package/build/helpers/matchers/match-text-content.js.map +1 -1
- package/build/helpers/pointer-events.d.ts +2 -2
- package/build/helpers/pointer-events.js +1 -2
- package/build/helpers/pointer-events.js.map +1 -1
- package/build/helpers/text-content.d.ts +2 -2
- package/build/helpers/text-content.js.map +1 -1
- package/build/helpers/text-input.d.ts +3 -3
- package/build/helpers/text-input.js.map +1 -1
- package/build/helpers/wrap-async.d.ts +1 -0
- package/build/helpers/wrap-async.js +1 -0
- package/build/helpers/wrap-async.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.flow.js +0 -1
- package/build/index.js +11 -1
- package/build/index.js.map +1 -1
- package/build/matchers/to-be-busy.d.ts +2 -2
- package/build/matchers/to-be-busy.js.map +1 -1
- package/build/matchers/to-be-checked.d.ts +2 -2
- package/build/matchers/to-be-checked.js.map +1 -1
- package/build/matchers/to-be-disabled.d.ts +3 -3
- package/build/matchers/to-be-disabled.js +1 -2
- package/build/matchers/to-be-disabled.js.map +1 -1
- package/build/matchers/to-be-empty-element.d.ts +2 -2
- package/build/matchers/to-be-empty-element.js +2 -3
- package/build/matchers/to-be-empty-element.js.map +1 -1
- package/build/matchers/to-be-expanded.d.ts +3 -3
- package/build/matchers/to-be-expanded.js.map +1 -1
- package/build/matchers/to-be-on-the-screen.d.ts +2 -2
- package/build/matchers/to-be-on-the-screen.js +1 -1
- package/build/matchers/to-be-on-the-screen.js.map +1 -1
- package/build/matchers/to-be-partially-checked.d.ts +2 -2
- package/build/matchers/to-be-partially-checked.js.map +1 -1
- package/build/matchers/to-be-selected.d.ts +2 -2
- package/build/matchers/to-be-selected.js.map +1 -1
- package/build/matchers/to-be-visible.d.ts +2 -2
- package/build/matchers/to-be-visible.js +1 -2
- package/build/matchers/to-be-visible.js.map +1 -1
- package/build/matchers/to-contain-element.d.ts +2 -2
- package/build/matchers/to-contain-element.js +2 -1
- package/build/matchers/to-contain-element.js.map +1 -1
- package/build/matchers/to-have-accessibility-value.d.ts +2 -2
- package/build/matchers/to-have-accessibility-value.js.map +1 -1
- package/build/matchers/to-have-accessible-name.d.ts +2 -2
- package/build/matchers/to-have-accessible-name.js.map +1 -1
- package/build/matchers/to-have-display-value.d.ts +2 -2
- package/build/matchers/to-have-display-value.js.map +1 -1
- package/build/matchers/to-have-prop.d.ts +2 -2
- package/build/matchers/to-have-prop.js.map +1 -1
- package/build/matchers/to-have-style.d.ts +2 -2
- package/build/matchers/to-have-style.js.map +1 -1
- package/build/matchers/to-have-text-content.d.ts +2 -2
- package/build/matchers/to-have-text-content.js.map +1 -1
- package/build/matchers/types.d.ts +2 -2
- package/build/matchers/types.js.map +1 -1
- package/build/matchers/utils.d.ts +3 -3
- package/build/matchers/utils.js +3 -4
- package/build/matchers/utils.js.map +1 -1
- package/build/native-state.d.ts +3 -3
- package/build/native-state.js.map +1 -1
- package/build/pure.d.ts +1 -1
- package/build/pure.js +2 -2
- package/build/pure.js.map +1 -1
- package/build/queries/display-value.d.ts +2 -2
- package/build/queries/display-value.js.map +1 -1
- package/build/queries/hint-text.d.ts +2 -2
- package/build/queries/hint-text.js.map +1 -1
- package/build/queries/label-text.d.ts +2 -2
- package/build/queries/label-text.js.map +1 -1
- package/build/queries/make-queries.d.ts +9 -9
- package/build/queries/make-queries.js.map +1 -1
- package/build/queries/placeholder-text.d.ts +2 -2
- package/build/queries/placeholder-text.js.map +1 -1
- package/build/queries/role.d.ts +2 -2
- package/build/queries/role.js.map +1 -1
- package/build/queries/test-id.d.ts +2 -2
- package/build/queries/test-id.js.map +1 -1
- package/build/queries/text.d.ts +2 -2
- package/build/queries/text.js.map +1 -1
- package/build/render-hook.js +1 -1
- package/build/render-hook.js.map +1 -1
- package/build/render.d.ts +20 -121
- package/build/render.js +27 -67
- package/build/render.js.map +1 -1
- package/build/screen.js +1 -9
- package/build/screen.js.map +1 -1
- package/build/tsconfig.release.tsbuildinfo +1 -1
- package/build/user-event/clear.d.ts +2 -2
- package/build/user-event/clear.js.map +1 -1
- package/build/user-event/index.d.ts +7 -7
- package/build/user-event/index.js.map +1 -1
- package/build/user-event/paste.d.ts +2 -2
- package/build/user-event/paste.js.map +1 -1
- package/build/user-event/press/press.d.ts +3 -3
- package/build/user-event/press/press.js +1 -10
- package/build/user-event/press/press.js.map +1 -1
- package/build/user-event/scroll/scroll-to.d.ts +2 -2
- package/build/user-event/scroll/scroll-to.js.map +1 -1
- package/build/user-event/setup/setup.d.ts +7 -7
- package/build/user-event/setup/setup.js.map +1 -1
- package/build/user-event/type/type.d.ts +3 -3
- package/build/user-event/type/type.js.map +1 -1
- package/build/user-event/utils/dispatch-event.d.ts +2 -2
- package/build/user-event/utils/dispatch-event.js.map +1 -1
- package/build/within.d.ts +20 -36
- package/build/within.js +3 -7
- package/build/within.js.map +1 -1
- package/package.json +8 -8
- package/typings/index.flow.js +0 -1
- package/build/helpers/ensure-peer-deps.d.ts +0 -3
- package/build/helpers/ensure-peer-deps.js +0 -32
- package/build/helpers/ensure-peer-deps.js.map +0 -1
- package/build/helpers/string-validation.d.ts +0 -2
- package/build/helpers/string-validation.js +0 -31
- package/build/helpers/string-validation.js.map +0 -1
- package/build/queries/unsafe-props.d.ts +0 -10
- package/build/queries/unsafe-props.js +0 -49
- package/build/queries/unsafe-props.js.map +0 -1
- package/build/queries/unsafe-type.d.ts +0 -10
- package/build/queries/unsafe-type.js +0 -49
- package/build/queries/unsafe-type.js.map +0 -1
- package/build/render-act.d.ts +0 -2
- package/build/render-act.js +0 -22
- package/build/render-act.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clear.js","names":["_errors","require","_hostComponentNames","_pointerEvents","_textInput","_eventBuilder","_type","_utils","clear","element","isHostTextInput","ErrorWithStack","type","isEditableTextInput","isPointerEventEnabled","dispatchEvent","EventBuilder","Common","focus","textToClear","getTextInputValue","selectionRange","start","end","length","TextInput","selectionChange","emptyText","emitTypingEvents","config","key","text","wait","endEditing","blur"],"sources":["../../src/user-event/clear.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"clear.js","names":["_errors","require","_hostComponentNames","_pointerEvents","_textInput","_eventBuilder","_type","_utils","clear","element","isHostTextInput","ErrorWithStack","type","isEditableTextInput","isPointerEventEnabled","dispatchEvent","EventBuilder","Common","focus","textToClear","getTextInputValue","selectionRange","start","end","length","TextInput","selectionChange","emptyText","emitTypingEvents","config","key","text","wait","endEditing","blur"],"sources":["../../src/user-event/clear.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\n\nimport { ErrorWithStack } from '../helpers/errors';\nimport { isHostTextInput } from '../helpers/host-component-names';\nimport { isPointerEventEnabled } from '../helpers/pointer-events';\nimport { getTextInputValue, isEditableTextInput } from '../helpers/text-input';\nimport { EventBuilder } from './event-builder';\nimport type { UserEventInstance } from './setup';\nimport { emitTypingEvents } from './type/type';\nimport { dispatchEvent, wait } from './utils';\n\nexport async function clear(this: UserEventInstance, element: HostElement): Promise<void> {\n if (!isHostTextInput(element)) {\n throw new ErrorWithStack(\n `clear() only supports host \"TextInput\" elements. Passed element has type: \"${element.type}\".`,\n clear,\n );\n }\n\n if (!isEditableTextInput(element) || !isPointerEventEnabled(element)) {\n return;\n }\n\n // 1. Enter element\n dispatchEvent(element, 'focus', EventBuilder.Common.focus());\n\n // 2. Select all\n const textToClear = getTextInputValue(element);\n const selectionRange = {\n start: 0,\n end: textToClear.length,\n };\n dispatchEvent(element, 'selectionChange', EventBuilder.TextInput.selectionChange(selectionRange));\n\n // 3. Press backspace with selected text\n const emptyText = '';\n await emitTypingEvents(element, {\n config: this.config,\n key: 'Backspace',\n text: emptyText,\n });\n\n // 4. Exit element\n await wait(this.config);\n dispatchEvent(element, 'endEditing', EventBuilder.TextInput.endEditing(emptyText));\n dispatchEvent(element, 'blur', EventBuilder.Common.blur());\n}\n"],"mappings":";;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAEA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAEO,eAAeO,KAAKA,CAA0BC,OAAoB,EAAiB;EACxF,IAAI,CAAC,IAAAC,mCAAe,EAACD,OAAO,CAAC,EAAE;IAC7B,MAAM,IAAIE,sBAAc,CACtB,8EAA8EF,OAAO,CAACG,IAAI,IAAI,EAC9FJ,KACF,CAAC;EACH;EAEA,IAAI,CAAC,IAAAK,8BAAmB,EAACJ,OAAO,CAAC,IAAI,CAAC,IAAAK,oCAAqB,EAACL,OAAO,CAAC,EAAE;IACpE;EACF;;EAEA;EACA,IAAAM,oBAAa,EAACN,OAAO,EAAE,OAAO,EAAEO,0BAAY,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,CAAC;;EAE5D;EACA,MAAMC,WAAW,GAAG,IAAAC,4BAAiB,EAACX,OAAO,CAAC;EAC9C,MAAMY,cAAc,GAAG;IACrBC,KAAK,EAAE,CAAC;IACRC,GAAG,EAAEJ,WAAW,CAACK;EACnB,CAAC;EACD,IAAAT,oBAAa,EAACN,OAAO,EAAE,iBAAiB,EAAEO,0BAAY,CAACS,SAAS,CAACC,eAAe,CAACL,cAAc,CAAC,CAAC;;EAEjG;EACA,MAAMM,SAAS,GAAG,EAAE;EACpB,MAAM,IAAAC,sBAAgB,EAACnB,OAAO,EAAE;IAC9BoB,MAAM,EAAE,IAAI,CAACA,MAAM;IACnBC,GAAG,EAAE,WAAW;IAChBC,IAAI,EAAEJ;EACR,CAAC,CAAC;;EAEF;EACA,MAAM,IAAAK,WAAI,EAAC,IAAI,CAACH,MAAM,CAAC;EACvB,IAAAd,oBAAa,EAACN,OAAO,EAAE,YAAY,EAAEO,0BAAY,CAACS,SAAS,CAACQ,UAAU,CAACN,SAAS,CAAC,CAAC;EAClF,IAAAZ,oBAAa,EAACN,OAAO,EAAE,MAAM,EAAEO,0BAAY,CAACC,MAAM,CAACiB,IAAI,CAAC,CAAC,CAAC;AAC5D","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HostElement } from 'universal-test-renderer';
|
|
2
2
|
import type { PressOptions } from './press';
|
|
3
3
|
import type { ScrollToOptions } from './scroll';
|
|
4
4
|
import { setup } from './setup';
|
|
@@ -6,10 +6,10 @@ import type { TypeOptions } from './type';
|
|
|
6
6
|
export { UserEventConfig } from './setup';
|
|
7
7
|
export declare const userEvent: {
|
|
8
8
|
setup: typeof setup;
|
|
9
|
-
press: (element:
|
|
10
|
-
longPress: (element:
|
|
11
|
-
type: (element:
|
|
12
|
-
clear: (element:
|
|
13
|
-
paste: (element:
|
|
14
|
-
scrollTo: (element:
|
|
9
|
+
press: (element: HostElement) => Promise<void>;
|
|
10
|
+
longPress: (element: HostElement, options?: PressOptions) => Promise<void>;
|
|
11
|
+
type: (element: HostElement, text: string, options?: TypeOptions) => Promise<void>;
|
|
12
|
+
clear: (element: HostElement) => Promise<void>;
|
|
13
|
+
paste: (element: HostElement, text: string) => Promise<void>;
|
|
14
|
+
scrollTo: (element: HostElement, options: ScrollToOptions) => Promise<void>;
|
|
15
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_setup","require","userEvent","exports","setup","press","element","longPress","options","type","text","clear","paste","scrollTo"],"sources":["../../src/user-event/index.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"index.js","names":["_setup","require","userEvent","exports","setup","press","element","longPress","options","type","text","clear","paste","scrollTo"],"sources":["../../src/user-event/index.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\n\nimport type { PressOptions } from './press';\nimport type { ScrollToOptions } from './scroll';\nimport { setup } from './setup';\nimport type { TypeOptions } from './type';\n\nexport { UserEventConfig } from './setup';\n\nexport const userEvent = {\n setup,\n\n // Direct access for User Event v13 compatibility\n press: (element: HostElement) => setup().press(element),\n longPress: (element: HostElement, options?: PressOptions) => setup().longPress(element, options),\n type: (element: HostElement, text: string, options?: TypeOptions) =>\n setup().type(element, text, options),\n clear: (element: HostElement) => setup().clear(element),\n paste: (element: HostElement, text: string) => setup().paste(element, text),\n scrollTo: (element: HostElement, options: ScrollToOptions) => setup().scrollTo(element, options),\n};\n"],"mappings":";;;;;;;;;;;;AAIA,IAAAA,MAAA,GAAAC,OAAA;AAKO,MAAMC,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG;EACvBE,KAAK,EAALA,YAAK;EAEL;EACAC,KAAK,EAAGC,OAAoB,IAAK,IAAAF,YAAK,EAAC,CAAC,CAACC,KAAK,CAACC,OAAO,CAAC;EACvDC,SAAS,EAAEA,CAACD,OAAoB,EAAEE,OAAsB,KAAK,IAAAJ,YAAK,EAAC,CAAC,CAACG,SAAS,CAACD,OAAO,EAAEE,OAAO,CAAC;EAChGC,IAAI,EAAEA,CAACH,OAAoB,EAAEI,IAAY,EAAEF,OAAqB,KAC9D,IAAAJ,YAAK,EAAC,CAAC,CAACK,IAAI,CAACH,OAAO,EAAEI,IAAI,EAAEF,OAAO,CAAC;EACtCG,KAAK,EAAGL,OAAoB,IAAK,IAAAF,YAAK,EAAC,CAAC,CAACO,KAAK,CAACL,OAAO,CAAC;EACvDM,KAAK,EAAEA,CAACN,OAAoB,EAAEI,IAAY,KAAK,IAAAN,YAAK,EAAC,CAAC,CAACQ,KAAK,CAACN,OAAO,EAAEI,IAAI,CAAC;EAC3EG,QAAQ,EAAEA,CAACP,OAAoB,EAAEE,OAAwB,KAAK,IAAAJ,YAAK,EAAC,CAAC,CAACS,QAAQ,CAACP,OAAO,EAAEE,OAAO;AACjG,CAAC","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HostElement } from 'universal-test-renderer';
|
|
2
2
|
import type { UserEventInstance } from './setup';
|
|
3
|
-
export declare function paste(this: UserEventInstance, element:
|
|
3
|
+
export declare function paste(this: UserEventInstance, element: HostElement, text: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paste.js","names":["_errors","require","_hostComponentNames","_pointerEvents","_textInput","_nativeState","_eventBuilder","_utils","paste","element","text","isHostTextInput","ErrorWithStack","type","isEditableTextInput","isPointerEventEnabled","dispatchEvent","EventBuilder","Common","focus","textToClear","getTextInputValue","rangeToClear","start","end","length","TextInput","selectionChange","nativeState","valueForElement","set","change","rangeAfter","isMultiline","props","multiline","contentSize","getTextContentSize","contentSizeChange","wait","config","endEditing","blur"],"sources":["../../src/user-event/paste.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"paste.js","names":["_errors","require","_hostComponentNames","_pointerEvents","_textInput","_nativeState","_eventBuilder","_utils","paste","element","text","isHostTextInput","ErrorWithStack","type","isEditableTextInput","isPointerEventEnabled","dispatchEvent","EventBuilder","Common","focus","textToClear","getTextInputValue","rangeToClear","start","end","length","TextInput","selectionChange","nativeState","valueForElement","set","change","rangeAfter","isMultiline","props","multiline","contentSize","getTextContentSize","contentSizeChange","wait","config","endEditing","blur"],"sources":["../../src/user-event/paste.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\n\nimport { ErrorWithStack } from '../helpers/errors';\nimport { isHostTextInput } from '../helpers/host-component-names';\nimport { isPointerEventEnabled } from '../helpers/pointer-events';\nimport { getTextInputValue, isEditableTextInput } from '../helpers/text-input';\nimport { nativeState } from '../native-state';\nimport { EventBuilder } from './event-builder';\nimport type { UserEventInstance } from './setup';\nimport { dispatchEvent, getTextContentSize, wait } from './utils';\n\nexport async function paste(\n this: UserEventInstance,\n element: HostElement,\n text: string,\n): Promise<void> {\n if (!isHostTextInput(element)) {\n throw new ErrorWithStack(\n `paste() only supports host \"TextInput\" elements. Passed element has type: \"${element.type}\".`,\n paste,\n );\n }\n\n if (!isEditableTextInput(element) || !isPointerEventEnabled(element)) {\n return;\n }\n\n // 1. Enter element\n dispatchEvent(element, 'focus', EventBuilder.Common.focus());\n\n // 2. Select all\n const textToClear = getTextInputValue(element);\n const rangeToClear = { start: 0, end: textToClear.length };\n dispatchEvent(element, 'selectionChange', EventBuilder.TextInput.selectionChange(rangeToClear));\n\n // 3. Paste the text\n nativeState.valueForElement.set(element, text);\n dispatchEvent(element, 'change', EventBuilder.TextInput.change(text));\n dispatchEvent(element, 'changeText', text);\n\n const rangeAfter = { start: text.length, end: text.length };\n dispatchEvent(element, 'selectionChange', EventBuilder.TextInput.selectionChange(rangeAfter));\n\n // According to the docs only multiline TextInput emits contentSizeChange event\n // @see: https://reactnative.dev/docs/textinput#oncontentsizechange\n const isMultiline = element.props.multiline === true;\n if (isMultiline) {\n const contentSize = getTextContentSize(text);\n dispatchEvent(\n element,\n 'contentSizeChange',\n EventBuilder.TextInput.contentSizeChange(contentSize),\n );\n }\n\n // 4. Exit element\n await wait(this.config);\n dispatchEvent(element, 'endEditing', EventBuilder.TextInput.endEditing(text));\n dispatchEvent(element, 'blur', EventBuilder.Common.blur());\n}\n"],"mappings":";;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AAEO,eAAeO,KAAKA,CAEzBC,OAAoB,EACpBC,IAAY,EACG;EACf,IAAI,CAAC,IAAAC,mCAAe,EAACF,OAAO,CAAC,EAAE;IAC7B,MAAM,IAAIG,sBAAc,CACtB,8EAA8EH,OAAO,CAACI,IAAI,IAAI,EAC9FL,KACF,CAAC;EACH;EAEA,IAAI,CAAC,IAAAM,8BAAmB,EAACL,OAAO,CAAC,IAAI,CAAC,IAAAM,oCAAqB,EAACN,OAAO,CAAC,EAAE;IACpE;EACF;;EAEA;EACA,IAAAO,oBAAa,EAACP,OAAO,EAAE,OAAO,EAAEQ,0BAAY,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,CAAC;;EAE5D;EACA,MAAMC,WAAW,GAAG,IAAAC,4BAAiB,EAACZ,OAAO,CAAC;EAC9C,MAAMa,YAAY,GAAG;IAAEC,KAAK,EAAE,CAAC;IAAE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@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HostElement } from 'universal-test-renderer';
|
|
2
2
|
import type { 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:
|
|
9
|
-
export declare function longPress(this: UserEventInstance, element:
|
|
8
|
+
export declare function press(this: UserEventInstance, element: HostElement): Promise<void>;
|
|
9
|
+
export declare function longPress(this: UserEventInstance, element: HostElement, options?: PressOptions): Promise<void>;
|
|
@@ -8,8 +8,6 @@ exports.longPress = longPress;
|
|
|
8
8
|
exports.press = press;
|
|
9
9
|
var _act = _interopRequireDefault(require("../../act"));
|
|
10
10
|
var _eventHandler = require("../../event-handler");
|
|
11
|
-
var _componentTree = require("../../helpers/component-tree");
|
|
12
|
-
var _errors = require("../../helpers/errors");
|
|
13
11
|
var _hostComponentNames = require("../../helpers/host-component-names");
|
|
14
12
|
var _pointerEvents = require("../../helpers/pointer-events");
|
|
15
13
|
var _eventBuilder = require("../event-builder");
|
|
@@ -20,17 +18,11 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
20
18
|
const DEFAULT_MIN_PRESS_DURATION = exports.DEFAULT_MIN_PRESS_DURATION = 130;
|
|
21
19
|
const DEFAULT_LONG_PRESS_DELAY_MS = exports.DEFAULT_LONG_PRESS_DELAY_MS = 500;
|
|
22
20
|
async function press(element) {
|
|
23
|
-
if (!(0, _componentTree.isHostElement)(element)) {
|
|
24
|
-
throw new _errors.ErrorWithStack(`press() works only with host elements. Passed element has type "${element.type}".`, press);
|
|
25
|
-
}
|
|
26
21
|
await basePress(this.config, element, {
|
|
27
22
|
type: 'press'
|
|
28
23
|
});
|
|
29
24
|
}
|
|
30
25
|
async function longPress(element, options) {
|
|
31
|
-
if (!(0, _componentTree.isHostElement)(element)) {
|
|
32
|
-
throw new _errors.ErrorWithStack(`longPress() works only with host elements. Passed element has type "${element.type}".`, longPress);
|
|
33
|
-
}
|
|
34
26
|
await basePress(this.config, element, {
|
|
35
27
|
type: 'longPress',
|
|
36
28
|
duration: options?.duration ?? DEFAULT_LONG_PRESS_DELAY_MS
|
|
@@ -45,7 +37,7 @@ const basePress = async (config, element, options) => {
|
|
|
45
37
|
await emitPressabilityPressEvents(config, element, options);
|
|
46
38
|
return;
|
|
47
39
|
}
|
|
48
|
-
const hostParentElement =
|
|
40
|
+
const hostParentElement = element.parent;
|
|
49
41
|
if (!hostParentElement) {
|
|
50
42
|
return;
|
|
51
43
|
}
|
|
@@ -59,7 +51,6 @@ function isEnabledHostElement(element) {
|
|
|
59
51
|
return element.props.disabled !== true;
|
|
60
52
|
}
|
|
61
53
|
if ((0, _hostComponentNames.isHostTextInput)(element)) {
|
|
62
|
-
// @ts-expect-error - workaround incorrect ReactTestInstance type
|
|
63
54
|
return element.props.editable !== false;
|
|
64
55
|
}
|
|
65
56
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"press.js","names":["_act","_interopRequireDefault","require","_eventHandler","
|
|
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","hostParentElement","parent","isPointerEventEnabled","isHostText","props","disabled","isHostTextInput","editable","onStartShouldSetResponder","getEventHandler","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 { getEventHandler } from '../../event-handler';\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 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 (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 const hostParentElement = element.parent;\n if (!hostParentElement) {\n return;\n }\n\n await basePress(config, hostParentElement, 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 getEventHandler(element, 'press') ||\n getEventHandler(element, 'longPress') ||\n getEventHandler(element, 'pressIn') ||\n getEventHandler(element, '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 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\nasync function emitPressabilityPressEvents(\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(() => 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,mBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AAA+C,SAAAD,uBAAAO,CAAA,WAAAA,CA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EAE/D;EACA;EACA;EACA;EACA,IAAIrB,OAAO,CAACF,IAAI,KAAK,OAAO,EAAE;IAC5B,IAAAoB,oBAAa,EAACvB,OAAO,EAAE,OAAO,EAAEwB,0BAAY,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,CAAC;EAC9D;AACF;AAEA,eAAef,2BAA2BA,CACxCT,MAAuB,EACvBF,OAAoB,EACpBK,OAAyB,EACzB;EACA,MAAM,IAAAiB,WAAI,EAACpB,MAAM,CAAC;EAElB,IAAAqB,oBAAa,EAACvB,OAAO,EAAE,gBAAgB,EAAEwB,0BAAY,CAACC,MAAM,CAACE,cAAc,CAAC,CAAC,CAAC;EAE9E,MAAMrB,QAAQ,GAAGD,OAAO,CAACC,QAAQ,IAAIV,0BAA0B;EAC/D,MAAM,IAAA0B,WAAI,EAACpB,MAAM,EAAEI,QAAQ,CAAC;EAE5B,IAAAiB,oBAAa,EAACvB,OAAO,EAAE,kBAAkB,EAAEwB,0BAAY,CAACC,MAAM,CAACG,gBAAgB,CAAC,CAAC,CAAC;;EAElF;EACA;EACA;EACA,IAAIhC,0BAA0B,GAAGU,QAAQ,GAAG,CAAC,EAAE;IAC7C,MAAM,IAAAuB,YAAG,EAAC,MAAM,IAAAP,WAAI,EAACpB,MAAM,EAAEN,0BAA0B,GAAGU,QAAQ,CAAC,CAAC;EACtE;AACF","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HostElement } from 'universal-test-renderer';
|
|
2
2
|
import type { Size } from '../../types';
|
|
3
3
|
import type { UserEventInstance } from '../setup';
|
|
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:
|
|
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","_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 type { ReactTestInstance } from 'react-test-renderer';\nimport { stringify } from 'jest-matcher-utils';\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: 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,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,IA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AAK4B,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 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,GAA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AAyC,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 type {
|
|
1
|
+
import type { HostElement } from 'universal-test-renderer';
|
|
2
2
|
import type { PressOptions } from '../press';
|
|
3
3
|
import type { ScrollToOptions } from '../scroll';
|
|
4
4
|
import type { TypeOptions } from '../type';
|
|
@@ -44,8 +44,8 @@ export interface UserEventConfig {
|
|
|
44
44
|
*/
|
|
45
45
|
export interface UserEventInstance {
|
|
46
46
|
config: UserEventConfig;
|
|
47
|
-
press: (element:
|
|
48
|
-
longPress: (element:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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 type {
|
|
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 type { HostElement } from 'universal-test-renderer';\n\nimport { jestFakeTimersAreEnabled } from '../../helpers/timers';\nimport { wrapAsync } from '../../helpers/wrap-async';\nimport { clear } from '../clear';\nimport { paste } from '../paste';\nimport type { PressOptions } from '../press';\nimport { longPress, press } from '../press';\nimport type { ScrollToOptions } from '../scroll';\nimport { scrollTo } from '../scroll';\nimport type { TypeOptions } from '../type';\nimport { 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 never[],\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":";;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,IAAAK,OAAA,GAAAL,OAAA;AAEA,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,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAMA,SAASD,YAAYA,CAAC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|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HostElement } from 'universal-test-renderer';
|
|
2
2
|
import type { UserEventConfig, UserEventInstance } from '../setup';
|
|
3
3
|
export interface TypeOptions {
|
|
4
4
|
skipPress?: boolean;
|
|
5
5
|
submitEditing?: boolean;
|
|
6
6
|
skipBlur?: boolean;
|
|
7
7
|
}
|
|
8
|
-
export declare function type(this: UserEventInstance, element:
|
|
8
|
+
export declare function type(this: UserEventInstance, element: HostElement, text: string, options?: TypeOptions): Promise<void>;
|
|
9
9
|
type EmitTypingEventsContext = {
|
|
10
10
|
config: UserEventConfig;
|
|
11
11
|
key: string;
|
|
12
12
|
text: string;
|
|
13
13
|
isAccepted?: boolean;
|
|
14
14
|
};
|
|
15
|
-
export declare function emitTypingEvents(element:
|
|
15
|
+
export declare function emitTypingEvents(element: HostElement, { config, key, text, isAccepted }: EmitTypingEventsContext): Promise<void>;
|
|
16
16
|
export {};
|
|
@@ -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 {
|
|
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, '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":";;;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,O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|
|
1
|
-
import type {
|
|
1
|
+
import type { 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 type { 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:
|
|
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","_eventHandler","_componentTree","e","__esModule","default","dispatchEvent","element","eventName","event","isElementMounted","handler","getEventHandler","act"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","_eventHandler","_componentTree","e","__esModule","default","dispatchEvent","element","eventName","event","isElementMounted","handler","getEventHandler","act"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\n\nimport act from '../../act';\nimport { getEventHandler } 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 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"],"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,SAASG,aAAaA,CAACC,OAAoB,EAAEC,SAAiB,EAAE,GAAGC,KAAgB,EAAE;EAC1F,IAAI,CAAC,IAAAC,+BAAgB,EAACH,OAAO,CAAC,EAAE;IAC9B;EACF;EAEA,MAAMI,OAAO,GAAG,IAAAC,6BAAe,EAACL,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","ignoreList":[]}
|
package/build/within.d.ts
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function within(instance:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 type { 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
|
@@ -12,19 +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
|
-
var _unsafeProps = require("./queries/unsafe-props");
|
|
16
|
-
var _unsafeType = require("./queries/unsafe-type");
|
|
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,
|
|
27
|
-
...(0,
|
|
22
|
+
...(0, _testId.bindByTestIdQueries)(instance),
|
|
23
|
+
...(0, _text.bindByTextQueries)(instance)
|
|
28
24
|
};
|
|
29
25
|
}
|
|
30
26
|
const getQueriesForElement = exports.getQueriesForElement = within;
|