@testing-library/react-native 12.7.2 → 12.8.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/README.md +1 -2
- package/build/config.d.ts +10 -0
- package/build/config.js +2 -1
- package/build/config.js.map +1 -1
- package/build/fire-event.js +3 -0
- package/build/fire-event.js.map +1 -1
- package/build/helpers/component-tree.d.ts +1 -0
- package/build/helpers/component-tree.js +5 -0
- package/build/helpers/component-tree.js.map +1 -1
- package/build/helpers/host-component-names.js +1 -1
- package/build/helpers/host-component-names.js.map +1 -1
- package/build/render-hook.js +1 -1
- package/build/render-hook.js.map +1 -1
- package/build/render.d.ts +9 -0
- package/build/render.js +7 -1
- package/build/render.js.map +1 -1
- package/build/shallow.js +1 -1
- package/build/shallow.js.map +1 -1
- package/build/tsconfig.release.tsbuildinfo +1 -0
- package/build/user-event/press/press.d.ts +2 -0
- package/build/user-event/press/press.js +24 -10
- package/build/user-event/press/press.js.map +1 -1
- package/build/user-event/utils/dispatch-event.js +4 -0
- package/build/user-event/utils/dispatch-event.js.map +1 -1
- package/build/within.d.ts +4 -4
- package/package.json +18 -17
- package/build/user-event/press/constants.d.ts +0 -2
- package/build/user-event/press/constants.js +0 -14
- package/build/user-event/press/constants.js.map +0 -1
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ import '@testing-library/react-native/extend-expect';
|
|
|
53
53
|
## Example
|
|
54
54
|
|
|
55
55
|
```jsx
|
|
56
|
-
import { render, screen,
|
|
56
|
+
import { render, screen, userEvent } from '@testing-library/react-native';
|
|
57
57
|
import { QuestionsBoard } from '../QuestionsBoard';
|
|
58
58
|
|
|
59
59
|
// It is recommended to use userEvent with fake timers
|
|
@@ -109,7 +109,6 @@ React Native Testing Library consists of following APIs:
|
|
|
109
109
|
- [Migration to 12.0](https://callstack.github.io/react-native-testing-library/docs/migration/v12)
|
|
110
110
|
- [Migration to built-in Jest Matchers](https://callstack.github.io/react-native-testing-library/docs/migration/jest-matchers)
|
|
111
111
|
|
|
112
|
-
|
|
113
112
|
## Troubleshooting
|
|
114
113
|
|
|
115
114
|
- [Troubleshooting guide](https://callstack.github.io/react-native-testing-library/docs/guides/troubleshooting)
|
package/build/config.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ export type Config = {
|
|
|
9
9
|
defaultIncludeHiddenElements: boolean;
|
|
10
10
|
/** Default options for `debug` helper. */
|
|
11
11
|
defaultDebugOptions?: Partial<DebugOptions>;
|
|
12
|
+
/**
|
|
13
|
+
* Set to `true` to enable concurrent rendering.
|
|
14
|
+
* Otherwise `render` will default to legacy synchronous rendering.
|
|
15
|
+
*/
|
|
16
|
+
concurrentRoot: boolean;
|
|
12
17
|
};
|
|
13
18
|
export type ConfigAliasOptions = {
|
|
14
19
|
/** RTL-compatibility alias to `defaultIncludeHiddenElements` */
|
|
@@ -39,6 +44,11 @@ export declare function getConfig(): {
|
|
|
39
44
|
defaultIncludeHiddenElements: boolean;
|
|
40
45
|
/** Default options for `debug` helper. */
|
|
41
46
|
defaultDebugOptions?: Partial<DebugOptions>;
|
|
47
|
+
/**
|
|
48
|
+
* Set to `true` to enable concurrent rendering.
|
|
49
|
+
* Otherwise `render` will default to legacy synchronous rendering.
|
|
50
|
+
*/
|
|
51
|
+
concurrentRoot: boolean;
|
|
42
52
|
/** Names for key React Native host components. */
|
|
43
53
|
hostComponentNames?: HostComponentNames;
|
|
44
54
|
};
|
package/build/config.js
CHANGED
package/build/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","names":["defaultConfig","asyncUtilTimeout","defaultIncludeHiddenElements","config","configure","options","defaultHidden","restOptions","configureInternal","option","resetToDefaults","getConfig"],"sources":["../src/config.ts"],"sourcesContent":["import { DebugOptions } from './helpers/debug-deep';\n\n/**\n * Global configuration options for React Native Testing Library.\n */\n\nexport type Config = {\n /** Default timeout, in ms, for `waitFor` and `findBy*` queries. */\n asyncUtilTimeout: number;\n\n /** Default value for `includeHiddenElements` query option. */\n defaultIncludeHiddenElements: boolean;\n\n /** Default options for `debug` helper. */\n defaultDebugOptions?: Partial<DebugOptions>;\n};\n\nexport type ConfigAliasOptions = {\n /** RTL-compatibility alias to `defaultIncludeHiddenElements` */\n defaultHidden: boolean;\n};\n\nexport type HostComponentNames = {\n text: string;\n textInput: string;\n image: string;\n switch: string;\n scrollView: string;\n modal: string;\n};\n\nexport type InternalConfig = Config & {\n /** Names for key React Native host components. */\n hostComponentNames?: HostComponentNames;\n};\n\nconst defaultConfig: InternalConfig = {\n asyncUtilTimeout: 1000,\n defaultIncludeHiddenElements: false,\n};\n\nlet config = { ...defaultConfig };\n\n/**\n * Configure global options for React Native Testing Library.\n */\nexport function configure(options: Partial<Config & ConfigAliasOptions>) {\n const { defaultHidden, ...restOptions } = options;\n\n const defaultIncludeHiddenElements =\n restOptions.defaultIncludeHiddenElements ??\n defaultHidden ??\n config.defaultIncludeHiddenElements;\n\n config = {\n ...config,\n ...restOptions,\n defaultIncludeHiddenElements,\n };\n}\n\nexport function configureInternal(option: Partial<InternalConfig>) {\n config = {\n ...config,\n ...option,\n };\n}\n\nexport function resetToDefaults() {\n config = { ...defaultConfig };\n}\n\nexport function getConfig() {\n return config;\n}\n"],"mappings":";;;;;;;;;AAEA;AACA;AACA;;
|
|
1
|
+
{"version":3,"file":"config.js","names":["defaultConfig","asyncUtilTimeout","defaultIncludeHiddenElements","concurrentRoot","config","configure","options","defaultHidden","restOptions","configureInternal","option","resetToDefaults","getConfig"],"sources":["../src/config.ts"],"sourcesContent":["import { DebugOptions } from './helpers/debug-deep';\n\n/**\n * Global configuration options for React Native Testing Library.\n */\n\nexport type Config = {\n /** Default timeout, in ms, for `waitFor` and `findBy*` queries. */\n asyncUtilTimeout: number;\n\n /** Default value for `includeHiddenElements` query option. */\n defaultIncludeHiddenElements: boolean;\n\n /** Default options for `debug` helper. */\n defaultDebugOptions?: Partial<DebugOptions>;\n\n /**\n * Set to `true` to enable concurrent rendering.\n * Otherwise `render` will default to legacy synchronous rendering.\n */\n concurrentRoot: boolean;\n};\n\nexport type ConfigAliasOptions = {\n /** RTL-compatibility alias to `defaultIncludeHiddenElements` */\n defaultHidden: boolean;\n};\n\nexport type HostComponentNames = {\n text: string;\n textInput: string;\n image: string;\n switch: string;\n scrollView: string;\n modal: string;\n};\n\nexport type InternalConfig = Config & {\n /** Names for key React Native host components. */\n hostComponentNames?: HostComponentNames;\n};\n\nconst defaultConfig: InternalConfig = {\n asyncUtilTimeout: 1000,\n defaultIncludeHiddenElements: false,\n concurrentRoot: false,\n};\n\nlet config = { ...defaultConfig };\n\n/**\n * Configure global options for React Native Testing Library.\n */\nexport function configure(options: Partial<Config & ConfigAliasOptions>) {\n const { defaultHidden, ...restOptions } = options;\n\n const defaultIncludeHiddenElements =\n restOptions.defaultIncludeHiddenElements ??\n defaultHidden ??\n config.defaultIncludeHiddenElements;\n\n config = {\n ...config,\n ...restOptions,\n defaultIncludeHiddenElements,\n };\n}\n\nexport function configureInternal(option: Partial<InternalConfig>) {\n config = {\n ...config,\n ...option,\n };\n}\n\nexport function resetToDefaults() {\n config = { ...defaultConfig };\n}\n\nexport function getConfig() {\n return config;\n}\n"],"mappings":";;;;;;;;;AAEA;AACA;AACA;;AAsCA,MAAMA,aAA6B,GAAG;EACpCC,gBAAgB,EAAE,IAAI;EACtBC,4BAA4B,EAAE,KAAK;EACnCC,cAAc,EAAE;AAClB,CAAC;AAED,IAAIC,MAAM,GAAG;EAAE,GAAGJ;AAAc,CAAC;;AAEjC;AACA;AACA;AACO,SAASK,SAASA,CAACC,OAA6C,EAAE;EACvE,MAAM;IAAEC,aAAa;IAAE,GAAGC;EAAY,CAAC,GAAGF,OAAO;EAEjD,MAAMJ,4BAA4B,GAChCM,WAAW,CAACN,4BAA4B,IACxCK,aAAa,IACbH,MAAM,CAACF,4BAA4B;EAErCE,MAAM,GAAG;IACP,GAAGA,MAAM;IACT,GAAGI,WAAW;IACdN;EACF,CAAC;AACH;AAEO,SAASO,iBAAiBA,CAACC,MAA+B,EAAE;EACjEN,MAAM,GAAG;IACP,GAAGA,MAAM;IACT,GAAGM;EACL,CAAC;AACH;AAEO,SAASC,eAAeA,CAAA,EAAG;EAChCP,MAAM,GAAG;IAAE,GAAGJ;EAAc,CAAC;AAC/B;AAEO,SAASY,SAASA,CAAA,EAAG;EAC1B,OAAOR,MAAM;AACf","ignoreList":[]}
|
package/build/fire-event.js
CHANGED
|
@@ -77,6 +77,9 @@ function getEventHandlerName(eventName) {
|
|
|
77
77
|
// String union type of keys of T that start with on, stripped of 'on'
|
|
78
78
|
|
|
79
79
|
function fireEvent(element, eventName, ...data) {
|
|
80
|
+
if (!(0, _componentTree.isElementMounted)(element)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
80
83
|
setNativeStateIfNeeded(element, eventName, data[0]);
|
|
81
84
|
const handler = findEventHandler(element, eventName);
|
|
82
85
|
if (!handler) {
|
package/build/fire-event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fire-event.js","names":["_act","_interopRequireDefault","require","_componentTree","_hostComponentNames","_pointerEvents","_textInput","_nativeState","e","__esModule","default","isTouchResponder","element","isHostElement","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","isTextInputEditable","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandler","parent","eventHandlerName","getEventHandlerName","charAt","toUpperCase","slice","fireEvent","data","setNativeStateIfNeeded","returnValue","act","press","changeText","scroll","_default","exports","scrollEventNames","value","nativeState","valueForElement","set","isHostScrollView","contentOffset","tryGetContentOffset","contentOffsetForElement","event","nativeEvent","x","y","Number","isFinite"],"sources":["../src/fire-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport {\n ViewProps,\n TextProps,\n TextInputProps,\n PressableProps,\n ScrollViewProps,\n} from 'react-native';\nimport act from './act';\nimport { isHostElement } from './helpers/component-tree';\nimport { isHostScrollView, isHostTextInput } from './helpers/host-component-names';\nimport { isPointerEventEnabled } from './helpers/pointer-events';\nimport { isTextInputEditable } from './helpers/text-input';\nimport { Point, StringWithAutocomplete } from './types';\nimport { nativeState } from './native-state';\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nexport function isTouchResponder(element: ReactTestInstance) {\n if (!isHostElement(element)) {\n return false;\n }\n\n return Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element);\n}\n\n/**\n * List of events affected by `pointerEvents` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst eventsAffectedByPointerEventsProp = new Set(['press', 'onPress']);\n\n/**\n * List of `TextInput` events not affected by `editable` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst textInputEventsIgnoringEditableProp = new Set([\n 'contentSizeChange',\n 'onContentSizeChange',\n 'layout',\n 'onLayout',\n 'scroll',\n 'onScroll',\n]);\n\nexport function isEventEnabled(\n element: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance,\n) {\n if (isHostTextInput(nearestTouchResponder)) {\n return (\n isTextInputEditable(nearestTouchResponder) ||\n textInputEventsIgnoringEditableProp.has(eventName)\n );\n }\n\n if (eventsAffectedByPointerEventsProp.has(eventName) && !isPointerEventEnabled(element)) {\n return false;\n }\n\n const touchStart = nearestTouchResponder?.props.onStartShouldSetResponder?.();\n const touchMove = nearestTouchResponder?.props.onMoveShouldSetResponder?.();\n if (touchStart || touchMove) {\n return true;\n }\n\n return touchStart === undefined && touchMove === undefined;\n}\n\nfunction findEventHandler(\n element: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance,\n): EventHandler | null {\n const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder;\n\n const handler = getEventHandler(element, eventName);\n if (handler && isEventEnabled(element, eventName, touchResponder)) return handler;\n\n // eslint-disable-next-line @typescript-eslint/prefer-optional-chain\n if (element.parent === null || element.parent.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, touchResponder);\n}\n\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const eventHandlerName = getEventHandlerName(eventName);\n if (typeof element.props[eventHandlerName] === 'function') {\n return element.props[eventHandlerName];\n }\n\n if (typeof element.props[eventName] === 'function') {\n return element.props[eventName];\n }\n\n return undefined;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n}\n\n// String union type of keys of T that start with on, stripped of 'on'\ntype EventNameExtractor<T> = keyof {\n [K in keyof T as K extends `on${infer Rest}` ? Uncapitalize<Rest> : never]: T[K];\n};\n\ntype EventName = StringWithAutocomplete<\n | EventNameExtractor<ViewProps>\n | EventNameExtractor<TextProps>\n | EventNameExtractor<TextInputProps>\n | EventNameExtractor<PressableProps>\n | EventNameExtractor<ScrollViewProps>\n>;\n\nfunction fireEvent(element: ReactTestInstance, eventName: EventName, ...data: unknown[]) {\n setNativeStateIfNeeded(element, eventName, data[0]);\n\n const handler = findEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n let returnValue;\n void act(() => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n}\n\nfireEvent.press = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'press', ...data);\n\nfireEvent.changeText = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'changeText', ...data);\n\nfireEvent.scroll = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'scroll', ...data);\n\nexport default fireEvent;\n\nconst scrollEventNames = new Set([\n 'scroll',\n 'scrollBeginDrag',\n 'scrollEndDrag',\n 'momentumScrollBegin',\n 'momentumScrollEnd',\n]);\n\nfunction setNativeStateIfNeeded(element: ReactTestInstance, eventName: string, value: unknown) {\n if (\n eventName === 'changeText' &&\n typeof value === 'string' &&\n isHostTextInput(element) &&\n isTextInputEditable(element)\n ) {\n nativeState.valueForElement.set(element, value);\n }\n\n if (scrollEventNames.has(eventName) && isHostScrollView(element)) {\n const contentOffset = tryGetContentOffset(value);\n if (contentOffset) {\n nativeState.contentOffsetForElement.set(element, contentOffset);\n }\n }\n}\n\nfunction tryGetContentOffset(event: unknown): Point | null {\n try {\n // @ts-expect-error: try to extract contentOffset from the event value\n const contentOffset = event?.nativeEvent?.contentOffset;\n const x = contentOffset?.x;\n const y = contentOffset?.y;\n if (typeof x === 'number' || typeof y === 'number') {\n return {\n x: Number.isFinite(x) ? x : 0,\n y: Number.isFinite(y) ? y : 0,\n };\n }\n } catch {\n // Do nothing\n }\n\n return null;\n}\n"],"mappings":";;;;;;;;AAQA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAEA,IAAAK,YAAA,GAAAL,OAAA;AAA6C,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAItC,SAASG,gBAAgBA,CAACC,OAA0B,EAAE;EAC3D,IAAI,CAAC,IAAAC,4BAAa,EAACD,OAAO,CAAC,EAAE;IAC3B,OAAO,KAAK;EACd;EAEA,OAAOE,OAAO,CAACF,OAAO,CAACG,KAAK,CAACC,yBAAyB,CAAC,IAAI,IAAAC,mCAAe,EAACL,OAAO,CAAC;AACrF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMM,iCAAiC,GAAG,IAAIC,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;;AAEvE;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mCAAmC,GAAG,IAAID,GAAG,CAAC,CAClD,mBAAmB,EACnB,qBAAqB,EACrB,QAAQ,EACR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QACLD,CAAC,EAAEE,MAAM,CAACC,QAAQ,CAACH,CAAC,CAAC,GAAGA,CAAC,GAAG,CAAC;QAC7BC,CAAC,EAAEC,MAAM,CAACC,QAAQ,CAACF,CAAC,CAAC,GAAGA,CAAC,GAAG;MAC9B,CAAC;IACH;EACF,CAAC,CAAC,MAAM;IACN;EAAA;EAGF,OAAO,IAAI;AACb","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"fire-event.js","names":["_act","_interopRequireDefault","require","_componentTree","_hostComponentNames","_pointerEvents","_textInput","_nativeState","e","__esModule","default","isTouchResponder","element","isHostElement","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","isTextInputEditable","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandler","parent","eventHandlerName","getEventHandlerName","charAt","toUpperCase","slice","fireEvent","data","isElementMounted","setNativeStateIfNeeded","returnValue","act","press","changeText","scroll","_default","exports","scrollEventNames","value","nativeState","valueForElement","set","isHostScrollView","contentOffset","tryGetContentOffset","contentOffsetForElement","event","nativeEvent","x","y","Number","isFinite"],"sources":["../src/fire-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport {\n ViewProps,\n TextProps,\n TextInputProps,\n PressableProps,\n ScrollViewProps,\n} from 'react-native';\nimport act from './act';\nimport { isElementMounted, isHostElement } from './helpers/component-tree';\nimport { isHostScrollView, isHostTextInput } from './helpers/host-component-names';\nimport { isPointerEventEnabled } from './helpers/pointer-events';\nimport { isTextInputEditable } from './helpers/text-input';\nimport { Point, StringWithAutocomplete } from './types';\nimport { nativeState } from './native-state';\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nexport function isTouchResponder(element: ReactTestInstance) {\n if (!isHostElement(element)) {\n return false;\n }\n\n return Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element);\n}\n\n/**\n * List of events affected by `pointerEvents` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst eventsAffectedByPointerEventsProp = new Set(['press', 'onPress']);\n\n/**\n * List of `TextInput` events not affected by `editable` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst textInputEventsIgnoringEditableProp = new Set([\n 'contentSizeChange',\n 'onContentSizeChange',\n 'layout',\n 'onLayout',\n 'scroll',\n 'onScroll',\n]);\n\nexport function isEventEnabled(\n element: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance,\n) {\n if (isHostTextInput(nearestTouchResponder)) {\n return (\n isTextInputEditable(nearestTouchResponder) ||\n textInputEventsIgnoringEditableProp.has(eventName)\n );\n }\n\n if (eventsAffectedByPointerEventsProp.has(eventName) && !isPointerEventEnabled(element)) {\n return false;\n }\n\n const touchStart = nearestTouchResponder?.props.onStartShouldSetResponder?.();\n const touchMove = nearestTouchResponder?.props.onMoveShouldSetResponder?.();\n if (touchStart || touchMove) {\n return true;\n }\n\n return touchStart === undefined && touchMove === undefined;\n}\n\nfunction findEventHandler(\n element: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance,\n): EventHandler | null {\n const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder;\n\n const handler = getEventHandler(element, eventName);\n if (handler && isEventEnabled(element, eventName, touchResponder)) return handler;\n\n // eslint-disable-next-line @typescript-eslint/prefer-optional-chain\n if (element.parent === null || element.parent.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, touchResponder);\n}\n\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const eventHandlerName = getEventHandlerName(eventName);\n if (typeof element.props[eventHandlerName] === 'function') {\n return element.props[eventHandlerName];\n }\n\n if (typeof element.props[eventName] === 'function') {\n return element.props[eventName];\n }\n\n return undefined;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n}\n\n// String union type of keys of T that start with on, stripped of 'on'\ntype EventNameExtractor<T> = keyof {\n [K in keyof T as K extends `on${infer Rest}` ? Uncapitalize<Rest> : never]: T[K];\n};\n\ntype EventName = StringWithAutocomplete<\n | EventNameExtractor<ViewProps>\n | EventNameExtractor<TextProps>\n | EventNameExtractor<TextInputProps>\n | EventNameExtractor<PressableProps>\n | EventNameExtractor<ScrollViewProps>\n>;\n\nfunction fireEvent(element: ReactTestInstance, eventName: EventName, ...data: unknown[]) {\n if (!isElementMounted(element)) {\n return;\n }\n\n setNativeStateIfNeeded(element, eventName, data[0]);\n\n const handler = findEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n let returnValue;\n void act(() => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n}\n\nfireEvent.press = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'press', ...data);\n\nfireEvent.changeText = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'changeText', ...data);\n\nfireEvent.scroll = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'scroll', ...data);\n\nexport default fireEvent;\n\nconst scrollEventNames = new Set([\n 'scroll',\n 'scrollBeginDrag',\n 'scrollEndDrag',\n 'momentumScrollBegin',\n 'momentumScrollEnd',\n]);\n\nfunction setNativeStateIfNeeded(element: ReactTestInstance, eventName: string, value: unknown) {\n if (\n eventName === 'changeText' &&\n typeof value === 'string' &&\n isHostTextInput(element) &&\n isTextInputEditable(element)\n ) {\n nativeState.valueForElement.set(element, value);\n }\n\n if (scrollEventNames.has(eventName) && isHostScrollView(element)) {\n const contentOffset = tryGetContentOffset(value);\n if (contentOffset) {\n nativeState.contentOffsetForElement.set(element, contentOffset);\n }\n }\n}\n\nfunction tryGetContentOffset(event: unknown): Point | null {\n try {\n // @ts-expect-error: try to extract contentOffset from the event value\n const contentOffset = event?.nativeEvent?.contentOffset;\n const x = contentOffset?.x;\n const y = contentOffset?.y;\n if (typeof x === 'number' || typeof y === 'number') {\n return {\n x: Number.isFinite(x) ? x : 0,\n y: Number.isFinite(y) ? y : 0,\n };\n }\n } catch {\n // Do nothing\n }\n\n return null;\n}\n"],"mappings":";;;;;;;;AAQA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAEA,IAAAK,YAAA,GAAAL,OAAA;AAA6C,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAItC,SAASG,gBAAgBA,CAACC,OAA0B,EAAE;EAC3D,IAAI,CAAC,IAAAC,4BAAa,EAACD,OAAO,CAAC,EAAE;IAC3B,OAAO,KAAK;EACd;EAEA,OAAOE,OAAO,CAACF,OAAO,CAACG,KAAK,CAACC,yBAAyB,CAAC,IAAI,IAAAC,mCAAe,EAACL,OAAO,CAAC;AACrF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMM,iCAAiC,GAAG,IAAIC,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;;AAEvE;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mCAAmC,GAAG,IAAID,GAAG,CAAC,CAClD,mBAAmB,EACnB,qBAAqB,EACrB,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,UAAU,CACX,CAAC;AAEK,SAASE,cAAcA,CAC5BT,OAA0B,EAC1BU,SAAiB,EACjBC,qBAAyC,EACzC;EACA,IAAI,IAAAN,mCAAe,EAACM,qBAAqB,CAAC,EAAE;IAC1C,OACE,IAAAC,8BAAmB,EAACD,qBAAqB,CAAC,IAC1CH,mCAAmC,CAACK,GAAG,CAACH,SAAS,CAAC;EAEtD;EAEA,IAAIJ,iCAAiC,CAACO,GAAG,CAACH,SA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ignoreList":[]}
|
|
@@ -10,6 +10,7 @@ export type HostTestInstance = ReactTestInstance & {
|
|
|
10
10
|
* @param element The element to check.
|
|
11
11
|
*/
|
|
12
12
|
export declare function isHostElement(element?: ReactTestInstance | null): element is HostTestInstance;
|
|
13
|
+
export declare function isElementMounted(element: ReactTestInstance | null): boolean;
|
|
13
14
|
/**
|
|
14
15
|
* Returns first host ancestor for given element.
|
|
15
16
|
* @param element The element start traversing from.
|
|
@@ -8,7 +8,9 @@ exports.getHostParent = getHostParent;
|
|
|
8
8
|
exports.getHostSelves = getHostSelves;
|
|
9
9
|
exports.getHostSiblings = getHostSiblings;
|
|
10
10
|
exports.getUnsafeRootElement = getUnsafeRootElement;
|
|
11
|
+
exports.isElementMounted = isElementMounted;
|
|
11
12
|
exports.isHostElement = isHostElement;
|
|
13
|
+
var _screen = require("../screen");
|
|
12
14
|
/**
|
|
13
15
|
* ReactTestInstance referring to host element.
|
|
14
16
|
*/
|
|
@@ -20,6 +22,9 @@ exports.isHostElement = isHostElement;
|
|
|
20
22
|
function isHostElement(element) {
|
|
21
23
|
return typeof element?.type === 'string';
|
|
22
24
|
}
|
|
25
|
+
function isElementMounted(element) {
|
|
26
|
+
return getUnsafeRootElement(element) === _screen.screen.UNSAFE_root;
|
|
27
|
+
}
|
|
23
28
|
|
|
24
29
|
/**
|
|
25
30
|
* Returns first host ancestor for given element.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-tree.js","names":["isHostElement","element","type","getHostParent","current","parent","getHostChildren","hostChildren","children","forEach","child","push","getHostSelves","getHostSiblings","hostParent","hostSelves","filter","sibling","includes"
|
|
1
|
+
{"version":3,"file":"component-tree.js","names":["_screen","require","isHostElement","element","type","isElementMounted","getUnsafeRootElement","screen","UNSAFE_root","getHostParent","current","parent","getHostChildren","hostChildren","children","forEach","child","push","getHostSelves","getHostSiblings","hostParent","hostSelves","filter","sibling","includes"],"sources":["../../src/helpers/component-tree.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { screen } from '../screen';\n/**\n * ReactTestInstance referring to host element.\n */\nexport type HostTestInstance = ReactTestInstance & { type: string };\n\n/**\n * Checks if the given element is a host element.\n * @param element The element to check.\n */\nexport function isHostElement(element?: ReactTestInstance | null): element is HostTestInstance {\n return typeof element?.type === 'string';\n}\n\nexport function isElementMounted(element: ReactTestInstance | null) {\n return getUnsafeRootElement(element) === screen.UNSAFE_root;\n}\n\n/**\n * Returns first host ancestor for given element.\n * @param element The element start traversing from.\n */\nexport function getHostParent(element: ReactTestInstance | null): HostTestInstance | null {\n if (element == null) {\n return null;\n }\n\n let current = element.parent;\n while (current) {\n if (isHostElement(current)) {\n return current;\n }\n\n current = current.parent;\n }\n\n return null;\n}\n\n/**\n * Returns host children for given element.\n * @param element The element start traversing from.\n */\nexport function getHostChildren(element: ReactTestInstance | null): HostTestInstance[] {\n if (element == null) {\n return [];\n }\n\n const hostChildren: HostTestInstance[] = [];\n\n element.children.forEach((child) => {\n if (typeof child !== 'object') {\n return;\n }\n\n if (isHostElement(child)) {\n hostChildren.push(child);\n } else {\n hostChildren.push(...getHostChildren(child));\n }\n });\n\n return hostChildren;\n}\n\n/**\n * Return the array of host elements that represent the passed element.\n *\n * @param element The element start traversing from.\n * @returns If the passed element is a host element, it will return an array containing only that element,\n * if the passed element is a composite element, it will return an array containing its host children (zero, one or many).\n */\nexport function getHostSelves(element: ReactTestInstance | null): HostTestInstance[] {\n return isHostElement(element) ? [element] : getHostChildren(element);\n}\n\n/**\n * Returns host siblings for given element.\n * @param element The element start traversing from.\n */\nexport function getHostSiblings(element: ReactTestInstance | null): HostTestInstance[] {\n const hostParent = getHostParent(element);\n const hostSelves = getHostSelves(element);\n return getHostChildren(hostParent).filter((sibling) => !hostSelves.includes(sibling));\n}\n\n/**\n * Returns the unsafe root element of the tree (probably composite).\n *\n * @param element The element start traversing from.\n * @returns The root element of the tree (host or composite).\n */\nexport function getUnsafeRootElement(element: ReactTestInstance | null) {\n if (element == null) {\n return null;\n }\n\n let current = element;\n while (current.parent) {\n current = current.parent;\n }\n\n return current;\n}\n"],"mappings":";;;;;;;;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAACC,OAAkC,EAA+B;EAC7F,OAAO,OAAOA,OAAO,EAAEC,IAAI,KAAK,QAAQ;AAC1C;AAEO,SAASC,gBAAgBA,CAACF,OAAiC,EAAE;EAClE,OAAOG,oBAAoB,CAACH,OAAO,CAAC,KAAKI,cAAM,CAACC,WAAW;AAC7D;;AAEA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAACN,OAAiC,EAA2B;EACxF,IAAIA,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIO,OAAO,GAAGP,OAAO,CAACQ,MAAM;EAC5B,OAAOD,OAAO,EAAE;IACd,IAAIR,aAAa,CAACQ,OAAO,CAAC,EAAE;MAC1B,OAAOA,OAAO;IAChB;IAEAA,OAAO,GAAGA,OAAO,CAACC,MAAM;EAC1B;EAEA,OAAO,IAAI;AACb;;AAEA;AACA;AACA;AACA;AACO,SAASC,eAAeA,CAACT,OAAiC,EAAsB;EACrF,IAAIA,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,EAAE;EACX;EAEA,MAAMU,YAAgC,GAAG,EAAE;EAE3CV,OAAO,CAACW,QAAQ,CAACC,OAAO,CAAEC,KAAK,IAAK;IAClC,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7B;IACF;IAEA,IAAId,aAAa,CAACc,KAAK,CAAC,EAAE;MACxBH,YAAY,CAACI,IAAI,CAACD,KAAK,CAAC;IAC1B,CAAC,MAAM;MACLH,YAAY,CAACI,IAAI,CAAC,GAAGL,eAAe,CAACI,KAAK,CAAC,CAAC;IAC9C;EACF,CAAC,CAAC;EAEF,OAAOH,YAAY;AACrB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASK,aAAaA,CAACf,OAAiC,EAAsB;EACnF,OAAOD,aAAa,CAACC,OAAO,CAAC,GAAG,CAACA,OAAO,CAAC,GAAGS,eAAe,CAACT,OAAO,CAAC;AACtE;;AAEA;AACA;AACA;AACA;AACO,SAASgB,eAAeA,CAAChB,OAAiC,EAAsB;EACrF,MAAMiB,UAAU,GAAGX,aAAa,CAACN,OAAO,CAAC;EACzC,MAAMkB,UAAU,GAAGH,aAAa,CAACf,OAAO,CAAC;EACzC,OAAOS,eAAe,CAACQ,UAAU,CAAC,CAACE,MAAM,CAAEC,OAAO,IAAK,CAACF,UAAU,CAACG,QAAQ,CAACD,OAAO,CAAC,CAAC;AACvF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASjB,oBAAoBA,CAACH,OAAiC,EAAE;EACtE,IAAIA,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIO,OAAO,GAAGP,OAAO;EACrB,OAAOO,OAAO,CAACC,MAAM,EAAE;IACrBD,OAAO,GAAGA,OAAO,CAACC,MAAM;EAC1B;EAEA,OAAOD,OAAO;AAChB","ignoreList":[]}
|
|
@@ -41,7 +41,7 @@ function configureHostComponentNamesIfNeeded() {
|
|
|
41
41
|
}
|
|
42
42
|
function detectHostComponentNames() {
|
|
43
43
|
try {
|
|
44
|
-
const renderer = (0, _renderAct.renderWithAct)(
|
|
44
|
+
const renderer = (0, _renderAct.renderWithAct)(/*#__PURE__*/React.createElement(_reactNative.View, null, /*#__PURE__*/React.createElement(_reactNative.Text, {
|
|
45
45
|
testID: "text"
|
|
46
46
|
}, "Hello"), /*#__PURE__*/React.createElement(_reactNative.TextInput, {
|
|
47
47
|
testID: "textInput"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-component-names.js","names":["React","_interopRequireWildcard","require","_reactNative","_config","_renderAct","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","userConfigErrorMessage","getHostComponentNames","hostComponentNames","getConfig","detectHostComponentNames","configureInternal","configureHostComponentNamesIfNeeded","configHostComponentNames","renderer","renderWithAct","createElement","View","Text","testID","TextInput","Image","Switch","ScrollView","Modal","text","getByTestId","root","type","textInput","image","switch","scrollView","modal","error","errorMessage","message","Error","instance","nodes","findAll","node","props","length","isHostText","element","isHostTextInput","isHostImage","isHostSwitch","isHostScrollView","isHostModal"],"sources":["../../src/helpers/host-component-names.tsx"],"sourcesContent":["import * as React from 'react';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { Image, Modal, ScrollView, Switch, Text, TextInput, View } from 'react-native';\nimport { configureInternal, getConfig, HostComponentNames } from '../config';\nimport { renderWithAct } from '../render-act';\nimport { HostTestInstance } from './component-tree';\n\nconst userConfigErrorMessage = `There seems to be an issue with your configuration that prevents React Native Testing Library from working correctly.\nPlease check if you are using compatible versions of React Native and React Native Testing Library.`;\n\nexport function getHostComponentNames(): HostComponentNames {\n let hostComponentNames = getConfig().hostComponentNames;\n if (!hostComponentNames) {\n hostComponentNames = detectHostComponentNames();\n configureInternal({ hostComponentNames });\n }\n\n return hostComponentNames;\n}\n\nexport function configureHostComponentNamesIfNeeded() {\n const configHostComponentNames = getConfig().hostComponentNames;\n if (configHostComponentNames) {\n return;\n }\n\n const hostComponentNames = detectHostComponentNames();\n configureInternal({ hostComponentNames });\n}\n\nfunction detectHostComponentNames(): HostComponentNames {\n try {\n const renderer = renderWithAct(\n <View>\n <Text testID=\"text\">Hello</Text>\n <TextInput testID=\"textInput\" />\n <Image testID=\"image\" />\n <Switch testID=\"switch\" />\n <ScrollView testID=\"scrollView\" />\n <Modal testID=\"modal\" />\n </View>,\n );\n\n return {\n text: getByTestId(renderer.root, 'text').type as string,\n textInput: getByTestId(renderer.root, 'textInput').type as string,\n image: getByTestId(renderer.root, 'image').type as string,\n switch: getByTestId(renderer.root, 'switch').type as string,\n scrollView: getByTestId(renderer.root, 'scrollView').type as string,\n modal: getByTestId(renderer.root, 'modal').type as string,\n };\n } catch (error) {\n const errorMessage =\n error && typeof error === 'object' && 'message' in error ? error.message : null;\n\n throw new Error(\n `Trying to detect host component names triggered the following error:\\n\\n${errorMessage}\\n\\n${userConfigErrorMessage}`,\n );\n }\n}\n\nfunction getByTestId(instance: ReactTestInstance, testID: string) {\n const nodes = instance.findAll(\n (node) => typeof node.type === 'string' && node.props.testID === testID,\n );\n\n if (nodes.length === 0) {\n throw new Error(`Unable to find an element with testID: ${testID}`);\n }\n\n return nodes[0];\n}\n\n/**\n * Checks if the given element is a host Text element.\n * @param element The element to check.\n */\nexport function isHostText(element?: ReactTestInstance | null): element is HostTestInstance {\n return element?.type === getHostComponentNames().text;\n}\n\n/**\n * Checks if the given element is a host TextInput element.\n * @param element The element to check.\n */\nexport function isHostTextInput(element?: ReactTestInstance | null): element is HostTestInstance {\n return element?.type === getHostComponentNames().textInput;\n}\n\n/**\n * Checks if the given element is a host Image element.\n * @param element The element to check.\n */\nexport function isHostImage(element?: ReactTestInstance | null): element is HostTestInstance {\n return element?.type === getHostComponentNames().image;\n}\n\n/**\n * Checks if the given element is a host Switch element.\n * @param element The element to check.\n */\nexport function isHostSwitch(element?: ReactTestInstance | null): element is HostTestInstance {\n return element?.type === getHostComponentNames().switch;\n}\n\n/**\n * Checks if the given element is a host ScrollView element.\n * @param element The element to check.\n */\nexport function isHostScrollView(element?: ReactTestInstance | null): element is HostTestInstance {\n return element?.type === getHostComponentNames().scrollView;\n}\n\n/**\n * Checks if the given element is a host Modal element.\n * @param element The element to check.\n */\nexport function isHostModal(element?: ReactTestInstance | null): element is HostTestInstance {\n return element?.type === getHostComponentNames().modal;\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAA8C,SAAAI,yBAAAC,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AE;IACvBA,kBAAkB,GAAGE,wBAAwB,CAAC,CAAC;IAC/C,IAAAC,yBAAiB,EAAC;MAAEH;IAAmB,CAAC,CAAC;EAC3C;EAEA,OAAOA,kBAAkB;AAC3B;AAEO,SAASI,mCAAmCA,CAAA,EAAG;EACpD,MAAMC,wBAAwB,GAAG,IAAAJ,iBAAS,EAAC,CAAC,CAACD,kBAAkB;EAC/D,IAAIK,wBAAwB,EAAE;IAC5B;EACF;EAEA,MAAML,kBAAkB,GAAGE,wBAAwB,CAAC,CAAC;EACrD,IAAAC,yBAAiB,EAAC;IAAEH;EAAmB,CAAC,CAAC;AAC3C;AAEA,SAASE,wBAAwBA,CAAA,EAAuB;EACtD,IAAI;IACF,MAAMI,QAAQ,GAAG,IAAAC,wBAAa,
|
|
1
|
+
{"version":3,"file":"host-component-names.js","names":["React","_interopRequireWildcard","require","_reactNative","_config","_renderAct","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","userConfigErrorMessage","getHostComponentNames","hostComponentNames","getConfig","detectHostComponentNames","configureInternal","configureHostComponentNamesIfNeeded","configHostComponentNames","renderer","renderWithAct","createElement","View","Text","testID","TextInput","Image","Switch","ScrollView","Modal","text","getByTestId","root","type","textInput","image","switch","scrollView","modal","error","errorMessage","message","Error","instance","nodes","findAll","node","props","length","isHostText","element","isHostTextInput","isHostImage","isHostSwitch","isHostScrollView","isHostModal"],"sources":["../../src/helpers/host-component-names.tsx"],"sourcesContent":["import * as React from 'react';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { Image, Modal, ScrollView, Switch, Text, TextInput, View } from 'react-native';\nimport { configureInternal, getConfig, HostComponentNames } from '../config';\nimport { renderWithAct } from '../render-act';\nimport { HostTestInstance } from './component-tree';\n\nconst userConfigErrorMessage = `There seems to be an issue with your configuration that prevents React Native Testing Library from working correctly.\nPlease check if you are using compatible versions of React Native and React Native Testing Library.`;\n\nexport function getHostComponentNames(): HostComponentNames {\n let hostComponentNames = getConfig().hostComponentNames;\n if (!hostComponentNames) {\n hostComponentNames = detectHostComponentNames();\n configureInternal({ hostComponentNames });\n }\n\n return hostComponentNames;\n}\n\nexport function configureHostComponentNamesIfNeeded() {\n const configHostComponentNames = getConfig().hostComponentNames;\n if (configHostComponentNames) {\n return;\n }\n\n const hostComponentNames = detectHostComponentNames();\n configureInternal({ hostComponentNames });\n}\n\nfunction detectHostComponentNames(): HostComponentNames {\n try {\n const renderer = renderWithAct(\n <View>\n <Text testID=\"text\">Hello</Text>\n <TextInput testID=\"textInput\" />\n <Image testID=\"image\" />\n <Switch testID=\"switch\" />\n <ScrollView testID=\"scrollView\" />\n <Modal testID=\"modal\" />\n </View>,\n );\n\n return {\n text: getByTestId(renderer.root, 'text').type as string,\n textInput: getByTestId(renderer.root, 'textInput').type as string,\n image: getByTestId(renderer.root, 'image').type as string,\n switch: getByTestId(renderer.root, 'switch').type as string,\n scrollView: getByTestId(renderer.root, 'scrollView').type as string,\n modal: getByTestId(renderer.root, 'modal').type as string,\n };\n } catch (error) {\n const errorMessage =\n error && typeof error === 'object' && 'message' in error ? error.message : null;\n\n throw new Error(\n `Trying to detect host component names triggered the following error:\\n\\n${errorMessage}\\n\\n${userConfigErrorMessage}`,\n );\n }\n}\n\nfunction getByTestId(instance: ReactTestInstance, testID: string) {\n const nodes = instance.findAll(\n (node) => typeof node.type === 'string' && node.props.testID === testID,\n );\n\n if (nodes.length === 0) {\n throw new Error(`Unable to find an element with testID: ${testID}`);\n }\n\n return nodes[0];\n}\n\n/**\n * Checks if the given element is a host Text element.\n * @param element The element to check.\n */\nexport function isHostText(element?: ReactTestInstance | null): element is HostTestInstance {\n return element?.type === getHostComponentNames().text;\n}\n\n/**\n * Checks if the given element is a host TextInput element.\n * @param element The element to check.\n */\nexport function isHostTextInput(element?: ReactTestInstance | null): element is HostTestInstance {\n return element?.type === getHostComponentNames().textInput;\n}\n\n/**\n * Checks if the given element is a host Image element.\n * @param element The element to check.\n */\nexport function isHostImage(element?: ReactTestInstance | null): element is HostTestInstance {\n return element?.type === getHostComponentNames().image;\n}\n\n/**\n * Checks if the given element is a host Switch element.\n * @param element The element to check.\n */\nexport function isHostSwitch(element?: ReactTestInstance | null): element is HostTestInstance {\n return element?.type === getHostComponentNames().switch;\n}\n\n/**\n * Checks if the given element is a host ScrollView element.\n * @param element The element to check.\n */\nexport function isHostScrollView(element?: ReactTestInstance | null): element is HostTestInstance {\n return element?.type === getHostComponentNames().scrollView;\n}\n\n/**\n * Checks if the given element is a host Modal element.\n * @param element The element to check.\n */\nexport function isHostModal(element?: ReactTestInstance | null): element is HostTestInstance {\n return element?.type === getHostComponentNames().modal;\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAA8C,SAAAI,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAN,wBAAAM,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA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OAAO,EAAEjB,IAAI,KAAKrB,qBAAqB,CAAC,CAAC,CAAC0B,KAAK;AACxD","ignoreList":[]}
|
package/build/render-hook.js
CHANGED
|
@@ -33,7 +33,7 @@ function renderHook(renderCallback, options) {
|
|
|
33
33
|
detectHostComponentNames: false
|
|
34
34
|
});
|
|
35
35
|
function rerender(rerenderCallbackProps) {
|
|
36
|
-
return baseRerender(
|
|
36
|
+
return baseRerender(/*#__PURE__*/_react.default.createElement(TestComponent, {
|
|
37
37
|
renderCallbackProps: rerenderCallbackProps
|
|
38
38
|
}));
|
|
39
39
|
}
|
package/build/render-hook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-hook.js","names":["_react","_interopRequireDefault","require","_render","e","__esModule","default","renderHook","renderCallback","options","initialProps","wrapper","result","React","createRef","TestComponent","renderCallbackProps","renderResult","useEffect","current","rerender","baseRerender","unmount","renderInternal","createElement","detectHostComponentNames","rerenderCallbackProps"],"sources":["../src/render-hook.tsx"],"sourcesContent":["import React from 'react';\nimport type { ComponentType } from 'react';\nimport { renderInternal } from './render';\n\nexport type RenderHookResult<Result, Props> = {\n rerender: (props: Props) => void;\n result: { current: Result };\n unmount: () => void;\n};\n\nexport type RenderHookOptions<Props> = {\n initialProps?: Props;\n wrapper?: ComponentType<any>;\n};\n\nexport function renderHook<Result, Props>(\n renderCallback: (props: Props) => Result,\n options?: RenderHookOptions<Props>,\n): RenderHookResult<Result, Props> {\n const initialProps = options?.initialProps;\n const wrapper = options?.wrapper;\n\n const result: React.MutableRefObject<Result | null> = React.createRef();\n\n function TestComponent({ renderCallbackProps }: { renderCallbackProps: Props }) {\n const renderResult = renderCallback(renderCallbackProps);\n\n React.useEffect(() => {\n result.current = renderResult;\n });\n\n return null;\n }\n\n const { rerender: baseRerender, unmount } = renderInternal(\n // @ts-expect-error since option can be undefined, initialProps can be undefined when it should'nt\n <TestComponent renderCallbackProps={initialProps} />,\n {\n wrapper,\n detectHostComponentNames: false,\n },\n );\n\n function rerender(rerenderCallbackProps: Props) {\n return baseRerender(<TestComponent renderCallbackProps={rerenderCallbackProps} />);\n }\n\n // @ts-expect-error result is ill typed because ref is initialized to null\n return { result, rerender, unmount };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAA0C,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAanC,SAASG,UAAUA,CACxBC,cAAwC,EACxCC,OAAkC,EACD;EACjC,MAAMC,YAAY,GAAGD,OAAO,EAAEC,YAAY;EAC1C,MAAMC,OAAO,GAAGF,OAAO,EAAEE,OAAO;EAEhC,MAAMC,MAA6C,gBAAGC,cAAK,CAACC,SAAS,CAAC,CAAC;EAEvE,SAASC,aAAaA,CAAC;IAAEC;EAAoD,CAAC,EAAE;IAC9E,MAAMC,YAAY,GAAGT,cAAc,CAACQ,mBAAmB,CAAC;IAExDH,cAAK,CAACK,SAAS,CAAC,MAAM;MACpBN,MAAM,CAACO,OAAO,GAAGF,YAAY;IAC/B,CAAC,CAAC;IAEF,OAAO,IAAI;EACb;EAEA,MAAM;IAAEG,QAAQ,EAAEC,YAAY;IAAEC;EAAQ,CAAC,GAAG,IAAAC,sBAAc;EAAA;EACxD;EACAvB,MAAA,CAAAM,OAAA,CAAAkB,aAAA,CAACT,aAAa;IAACC,mBAAmB,EAAEN;EAAa,CAAE,CAAC,EACpD;IACEC,OAAO;IACPc,wBAAwB,EAAE;EAC5B,CACF,CAAC;EAED,SAASL,QAAQA,CAACM,qBAA4B,EAAE;IAC9C,OAAOL,YAAY,
|
|
1
|
+
{"version":3,"file":"render-hook.js","names":["_react","_interopRequireDefault","require","_render","e","__esModule","default","renderHook","renderCallback","options","initialProps","wrapper","result","React","createRef","TestComponent","renderCallbackProps","renderResult","useEffect","current","rerender","baseRerender","unmount","renderInternal","createElement","detectHostComponentNames","rerenderCallbackProps"],"sources":["../src/render-hook.tsx"],"sourcesContent":["import React from 'react';\nimport type { ComponentType } from 'react';\nimport { renderInternal } from './render';\n\nexport type RenderHookResult<Result, Props> = {\n rerender: (props: Props) => void;\n result: { current: Result };\n unmount: () => void;\n};\n\nexport type RenderHookOptions<Props> = {\n initialProps?: Props;\n wrapper?: ComponentType<any>;\n};\n\nexport function renderHook<Result, Props>(\n renderCallback: (props: Props) => Result,\n options?: RenderHookOptions<Props>,\n): RenderHookResult<Result, Props> {\n const initialProps = options?.initialProps;\n const wrapper = options?.wrapper;\n\n const result: React.MutableRefObject<Result | null> = React.createRef();\n\n function TestComponent({ renderCallbackProps }: { renderCallbackProps: Props }) {\n const renderResult = renderCallback(renderCallbackProps);\n\n React.useEffect(() => {\n result.current = renderResult;\n });\n\n return null;\n }\n\n const { rerender: baseRerender, unmount } = renderInternal(\n // @ts-expect-error since option can be undefined, initialProps can be undefined when it should'nt\n <TestComponent renderCallbackProps={initialProps} />,\n {\n wrapper,\n detectHostComponentNames: false,\n },\n );\n\n function rerender(rerenderCallbackProps: Props) {\n return baseRerender(<TestComponent renderCallbackProps={rerenderCallbackProps} />);\n }\n\n // @ts-expect-error result is ill typed because ref is initialized to null\n return { result, rerender, unmount };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAA0C,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAanC,SAASG,UAAUA,CACxBC,cAAwC,EACxCC,OAAkC,EACD;EACjC,MAAMC,YAAY,GAAGD,OAAO,EAAEC,YAAY;EAC1C,MAAMC,OAAO,GAAGF,OAAO,EAAEE,OAAO;EAEhC,MAAMC,MAA6C,gBAAGC,cAAK,CAACC,SAAS,CAAC,CAAC;EAEvE,SAASC,aAAaA,CAAC;IAAEC;EAAoD,CAAC,EAAE;IAC9E,MAAMC,YAAY,GAAGT,cAAc,CAACQ,mBAAmB,CAAC;IAExDH,cAAK,CAACK,SAAS,CAAC,MAAM;MACpBN,MAAM,CAACO,OAAO,GAAGF,YAAY;IAC/B,CAAC,CAAC;IAEF,OAAO,IAAI;EACb;EAEA,MAAM;IAAEG,QAAQ,EAAEC,YAAY;IAAEC;EAAQ,CAAC,GAAG,IAAAC,sBAAc;EAAA;EACxD;EACAvB,MAAA,CAAAM,OAAA,CAAAkB,aAAA,CAACT,aAAa;IAACC,mBAAmB,EAAEN;EAAa,CAAE,CAAC,EACpD;IACEC,OAAO;IACPc,wBAAwB,EAAE;EAC5B,CACF,CAAC;EAED,SAASL,QAAQA,CAACM,qBAA4B,EAAE;IAC9C,OAAOL,YAAY,cAACrB,MAAA,CAAAM,OAAA,CAAAkB,aAAA,CAACT,aAAa;MAACC,mBAAmB,EAAEU;IAAsB,CAAE,CAAC,CAAC;EACpF;;EAEA;EACA,OAAO;IAAEd,MAAM;IAAEQ,QAAQ;IAAEE;EAAQ,CAAC;AACtC","ignoreList":[]}
|
package/build/render.d.ts
CHANGED
|
@@ -2,7 +2,16 @@ import type { ReactTestInstance } from 'react-test-renderer';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { DebugOptions } from './helpers/debug-deep';
|
|
4
4
|
export interface RenderOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating
|
|
7
|
+
* reusable custom render functions for common data providers.
|
|
8
|
+
*/
|
|
5
9
|
wrapper?: React.ComponentType<any>;
|
|
10
|
+
/**
|
|
11
|
+
* Set to `true` to enable concurrent rendering.
|
|
12
|
+
* Otherwise `render` will default to legacy synchronous rendering.
|
|
13
|
+
*/
|
|
14
|
+
concurrentRoot?: boolean | undefined;
|
|
6
15
|
createNodeMock?: (element: React.ReactElement) => unknown;
|
|
7
16
|
unstable_validateStringsRenderedWithinText?: boolean;
|
|
8
17
|
}
|
package/build/render.js
CHANGED
|
@@ -31,10 +31,16 @@ function render(component, options = {}) {
|
|
|
31
31
|
function renderInternal(component, options) {
|
|
32
32
|
const {
|
|
33
33
|
wrapper: Wrapper,
|
|
34
|
+
concurrentRoot,
|
|
34
35
|
detectHostComponentNames = true,
|
|
35
36
|
unstable_validateStringsRenderedWithinText,
|
|
36
|
-
...
|
|
37
|
+
...rest
|
|
37
38
|
} = options || {};
|
|
39
|
+
const testRendererOptions = {
|
|
40
|
+
...rest,
|
|
41
|
+
// @ts-expect-error incomplete typing on RTR package
|
|
42
|
+
unstable_isConcurrent: concurrentRoot ?? (0, _config.getConfig)().concurrentRoot
|
|
43
|
+
};
|
|
38
44
|
if (detectHostComponentNames) {
|
|
39
45
|
(0, _hostComponentNames.configureHostComponentNamesIfNeeded)();
|
|
40
46
|
}
|
package/build/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","names":["_react","_interopRequireWildcard","require","React","_act","_interopRequireDefault","_cleanup","_config","_componentTree","_debugDeep","_debugShallow","_hostComponentNames","_stringValidation","_renderAct","_screen","_within","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","render","component","options","renderInternal","wrapper","Wrapper","detectHostComponentNames","unstable_validateStringsRenderedWithinText","testRendererOptions","configureHostComponentNamesIfNeeded","renderWithStringValidation","wrap","element","createElement","renderer","renderWithAct","buildRenderResult","handleRender","_","phase","validateStringsRenderedWithinText","toJSON","Profiler","id","onRender","update","updateWithAct","instance","root","unmount","act","addToCleanupQueue","result","getQueriesForElement","rerender","debug","getHostChildren","UNSAFE_root","enumerable","Error","setRenderResult","debugImpl","defaultDebugOptions","getConfig","debugOptions","message","console","warn","json","debugDeep","shallow","debugShallow"],"sources":["../src/render.tsx"],"sourcesContent":["import type { ReactTestInstance, ReactTestRenderer } from 'react-test-renderer';\nimport * as React from 'react';\nimport { Profiler } from 'react';\nimport act from './act';\nimport { addToCleanupQueue } from './cleanup';\nimport { getConfig } from './config';\nimport { getHostChildren } from './helpers/component-tree';\nimport debugDeep, { DebugOptions } from './helpers/debug-deep';\nimport debugShallow from './helpers/debug-shallow';\nimport { configureHostComponentNamesIfNeeded } from './helpers/host-component-names';\nimport { validateStringsRenderedWithinText } from './helpers/string-validation';\nimport { renderWithAct } from './render-act';\nimport { setRenderResult } from './screen';\nimport { getQueriesForElement } from './within';\n\nexport interface RenderOptions {\n wrapper?: React.ComponentType<any>;\n createNodeMock?: (element: React.ReactElement) => unknown;\n unstable_validateStringsRenderedWithinText?: boolean;\n}\n\nexport type RenderResult = ReturnType<typeof render>;\n\n/**\n * Renders test component deeply using React Test Renderer and exposes helpers\n * to assert on the output.\n */\nexport default function render<T>(component: React.ReactElement<T>, options: RenderOptions = {}) {\n return renderInternal(component, options);\n}\n\nexport interface RenderInternalOptions extends RenderOptions {\n detectHostComponentNames?: boolean;\n}\n\nexport function renderInternal<T>(\n component: React.ReactElement<T>,\n options?: RenderInternalOptions,\n) {\n const {\n wrapper: Wrapper,\n detectHostComponentNames = true,\n unstable_validateStringsRenderedWithinText,\n ...testRendererOptions\n } = options || {};\n\n if (detectHostComponentNames) {\n configureHostComponentNamesIfNeeded();\n }\n\n if (unstable_validateStringsRenderedWithinText) {\n return renderWithStringValidation(component, {\n wrapper: Wrapper,\n ...testRendererOptions,\n });\n }\n\n const wrap = (element: React.ReactElement) => (Wrapper ? <Wrapper>{element}</Wrapper> : element);\n const renderer = renderWithAct(wrap(component), testRendererOptions);\n return buildRenderResult(renderer, wrap);\n}\n\nfunction renderWithStringValidation<T>(\n component: React.ReactElement<T>,\n options: Omit<RenderOptions, 'unstable_validateStringsRenderedWithinText'> = {},\n) {\n let renderer: ReactTestRenderer;\n const { wrapper: Wrapper, ...testRendererOptions } = options ?? {};\n\n const handleRender: React.ProfilerOnRenderCallback = (_, phase) => {\n if (renderer && phase === 'update') {\n validateStringsRenderedWithinText(renderer.toJSON());\n }\n };\n\n const wrap = (element: React.ReactElement) => (\n <Profiler id=\"renderProfiler\" onRender={handleRender}>\n {Wrapper ? <Wrapper>{element}</Wrapper> : element}\n </Profiler>\n );\n\n renderer = renderWithAct(wrap(component), testRendererOptions);\n\n validateStringsRenderedWithinText(renderer.toJSON());\n\n return buildRenderResult(renderer, wrap);\n}\n\nfunction buildRenderResult(\n renderer: ReactTestRenderer,\n wrap: (element: React.ReactElement) => JSX.Element,\n) {\n const update = updateWithAct(renderer, wrap);\n const instance = renderer.root;\n\n const unmount = () => {\n void act(() => {\n renderer.unmount();\n });\n };\n\n addToCleanupQueue(unmount);\n\n const result = {\n ...getQueriesForElement(instance),\n update,\n unmount,\n rerender: update, // alias for `update`\n toJSON: renderer.toJSON,\n debug: debug(instance, renderer),\n get root(): ReactTestInstance {\n return getHostChildren(instance)[0];\n },\n UNSAFE_root: instance,\n };\n\n // Add as non-enumerable property, so that it's safe to enumerate\n // `render` result, e.g. using destructuring rest syntax.\n Object.defineProperty(result, 'container', {\n enumerable: false,\n get() {\n throw new Error(\n \"'container' property has been renamed to 'UNSAFE_root'.\\n\\n\" +\n \"Consider using 'root' property which returns root host element.\",\n );\n },\n });\n\n setRenderResult(result);\n\n return result;\n}\n\nfunction updateWithAct(\n renderer: ReactTestRenderer,\n wrap: (innerElement: React.ReactElement) => React.ReactElement,\n) {\n return function (component: React.ReactElement) {\n void act(() => {\n renderer.update(wrap(component));\n });\n };\n}\n\nexport interface DebugFunction {\n (options?: DebugOptions | string): void;\n shallow: (message?: string) => void;\n}\n\nfunction debug(instance: ReactTestInstance, renderer: ReactTestRenderer): DebugFunction {\n function debugImpl(options?: DebugOptions | string) {\n const { defaultDebugOptions } = getConfig();\n const debugOptions =\n typeof options === 'string'\n ? { ...defaultDebugOptions, message: options }\n : { ...defaultDebugOptions, ...options };\n\n if (typeof options === 'string') {\n // eslint-disable-next-line no-console\n console.warn(\n 'Using debug(\"message\") is deprecated and will be removed in future release, please use debug({ message; \"message\" }) instead.',\n );\n }\n\n const json = renderer.toJSON();\n if (json) {\n return debugDeep(json, debugOptions);\n }\n }\n debugImpl.shallow = (message?: string) => debugShallow(instance, message);\n return debugImpl;\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA+B,IAAAC,KAAA,GAAAH,MAAA;AAE/B,IAAAI,IAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AACA,IAAAO,UAAA,GAAAJ,sBAAA,CAAAH,OAAA;AACA,IAAAQ,aAAA,GAAAL,sBAAA,CAAAH,OAAA;AACA,IAAAS,mBAAA,GAAAT,OAAA;AACA,IAAAU,iBAAA,GAAAV,OAAA;AACA,IAAAW,UAAA,GAAAX,OAAA;AACA,IAAAY,OAAA,GAAAZ,OAAA;AACA,IAAAa,OAAA,GAAAb,OAAA;AAAgD,SAAAG,uBAAAW,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,yBAAAH,CAAA,6BAAAI,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAD,wBAAA,YAAAA,CAAAH,CAAA,WAAAA,CAAA,GAAAM,CAAA,GAAAD,CAAA,KAAAL,CAAA;AAAA,SAAAf,wBAAAe,CAAA,EAAAK,CAAA,SAAAA,CAAA,IAAAL,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAE,OAAA,EAAAF,CAAA,QAAAM,CAAA,GAAAH,wBAAA,CAAAE,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAC,GAAA,CAAAP,CAAA,UAAAM,CAAA,CAAAE,GAAA,CA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MAAE,GAAGwC,mBAAmB;MAAEG,OAAO,EAAE3C;IAAQ,CAAC,GAC5C;MAAE,GAAGwC,mBAAmB;MAAE,GAAGxC;IAAQ,CAAC;IAE5C,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;MAC/B;MACA4C,OAAO,CAACC,IAAI,CACV,+HACF,CAAC;IACH;IAEA,MAAMC,IAAI,GAAGlC,QAAQ,CAACO,MAAM,CAAC,CAAC;IAC9B,IAAI2B,IAAI,EAAE;MACR,OAAO,IAAAC,kBAAS,EAACD,IAAI,EAAEJ,YAAY,CAAC;IACtC;EACF;EACAH,SAAS,CAACS,OAAO,GAAIL,OAAgB,IAAK,IAAAM,qBAAY,EAACxB,QAAQ,EAAEkB,OAAO,CAAC;EACzE,OAAOJ,SAAS;AAClB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"render.js","names":["_react","_interopRequireWildcard","require","React","_act","_interopRequireDefault","_cleanup","_config","_componentTree","_debugDeep","_debugShallow","_hostComponentNames","_stringValidation","_renderAct","_screen","_within","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","render","component","options","renderInternal","wrapper","Wrapper","concurrentRoot","detectHostComponentNames","unstable_validateStringsRenderedWithinText","rest","testRendererOptions","unstable_isConcurrent","getConfig","configureHostComponentNamesIfNeeded","renderWithStringValidation","wrap","element","createElement","renderer","renderWithAct","buildRenderResult","handleRender","_","phase","validateStringsRenderedWithinText","toJSON","Profiler","id","onRender","update","updateWithAct","instance","root","unmount","act","addToCleanupQueue","result","getQueriesForElement","rerender","debug","getHostChildren","UNSAFE_root","enumerable","Error","setRenderResult","debugImpl","defaultDebugOptions","debugOptions","message","console","warn","json","debugDeep","shallow","debugShallow"],"sources":["../src/render.tsx"],"sourcesContent":["import type {\n ReactTestInstance,\n ReactTestRenderer,\n TestRendererOptions,\n} from 'react-test-renderer';\nimport * as React from 'react';\nimport { Profiler } from 'react';\nimport act from './act';\nimport { addToCleanupQueue } from './cleanup';\nimport { getConfig } from './config';\nimport { getHostChildren } from './helpers/component-tree';\nimport debugDeep, { DebugOptions } from './helpers/debug-deep';\nimport debugShallow from './helpers/debug-shallow';\nimport { configureHostComponentNamesIfNeeded } from './helpers/host-component-names';\nimport { validateStringsRenderedWithinText } from './helpers/string-validation';\nimport { renderWithAct } from './render-act';\nimport { setRenderResult } from './screen';\nimport { getQueriesForElement } from './within';\n\nexport interface RenderOptions {\n /**\n * Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating\n * reusable custom render functions for common data providers.\n */\n wrapper?: React.ComponentType<any>;\n\n /**\n * Set to `true` to enable concurrent rendering.\n * Otherwise `render` will default to legacy synchronous rendering.\n */\n concurrentRoot?: boolean | undefined;\n\n createNodeMock?: (element: React.ReactElement) => unknown;\n unstable_validateStringsRenderedWithinText?: boolean;\n}\n\nexport type RenderResult = ReturnType<typeof render>;\n\n/**\n * Renders test component deeply using React Test Renderer and exposes helpers\n * to assert on the output.\n */\nexport default function render<T>(component: React.ReactElement<T>, options: RenderOptions = {}) {\n return renderInternal(component, options);\n}\n\nexport interface RenderInternalOptions extends RenderOptions {\n detectHostComponentNames?: boolean;\n}\n\nexport function renderInternal<T>(\n component: React.ReactElement<T>,\n options?: RenderInternalOptions,\n) {\n const {\n wrapper: Wrapper,\n concurrentRoot,\n detectHostComponentNames = true,\n unstable_validateStringsRenderedWithinText,\n ...rest\n } = options || {};\n\n const testRendererOptions: TestRendererOptions = {\n ...rest,\n // @ts-expect-error incomplete typing on RTR package\n unstable_isConcurrent: concurrentRoot ?? getConfig().concurrentRoot,\n };\n\n if (detectHostComponentNames) {\n configureHostComponentNamesIfNeeded();\n }\n\n if (unstable_validateStringsRenderedWithinText) {\n return renderWithStringValidation(component, {\n wrapper: Wrapper,\n ...testRendererOptions,\n });\n }\n\n const wrap = (element: React.ReactElement) => (Wrapper ? <Wrapper>{element}</Wrapper> : element);\n const renderer = renderWithAct(wrap(component), testRendererOptions);\n return buildRenderResult(renderer, wrap);\n}\n\nfunction renderWithStringValidation<T>(\n component: React.ReactElement<T>,\n options: Omit<RenderOptions, 'unstable_validateStringsRenderedWithinText'> = {},\n) {\n let renderer: ReactTestRenderer;\n const { wrapper: Wrapper, ...testRendererOptions } = options ?? {};\n\n const handleRender: React.ProfilerOnRenderCallback = (_, phase) => {\n if (renderer && phase === 'update') {\n validateStringsRenderedWithinText(renderer.toJSON());\n }\n };\n\n const wrap = (element: React.ReactElement) => (\n <Profiler id=\"renderProfiler\" onRender={handleRender}>\n {Wrapper ? <Wrapper>{element}</Wrapper> : element}\n </Profiler>\n );\n\n renderer = renderWithAct(wrap(component), testRendererOptions);\n\n validateStringsRenderedWithinText(renderer.toJSON());\n\n return buildRenderResult(renderer, wrap);\n}\n\nfunction buildRenderResult(\n renderer: ReactTestRenderer,\n wrap: (element: React.ReactElement) => JSX.Element,\n) {\n const update = updateWithAct(renderer, wrap);\n const instance = renderer.root;\n\n const unmount = () => {\n void act(() => {\n renderer.unmount();\n });\n };\n\n addToCleanupQueue(unmount);\n\n const result = {\n ...getQueriesForElement(instance),\n update,\n unmount,\n rerender: update, // alias for `update`\n toJSON: renderer.toJSON,\n debug: debug(instance, renderer),\n get root(): ReactTestInstance {\n return getHostChildren(instance)[0];\n },\n UNSAFE_root: instance,\n };\n\n // Add as non-enumerable property, so that it's safe to enumerate\n // `render` result, e.g. using destructuring rest syntax.\n Object.defineProperty(result, 'container', {\n enumerable: false,\n get() {\n throw new Error(\n \"'container' property has been renamed to 'UNSAFE_root'.\\n\\n\" +\n \"Consider using 'root' property which returns root host element.\",\n );\n },\n });\n\n setRenderResult(result);\n\n return result;\n}\n\nfunction updateWithAct(\n renderer: ReactTestRenderer,\n wrap: (innerElement: React.ReactElement) => React.ReactElement,\n) {\n return function (component: React.ReactElement) {\n void act(() => {\n renderer.update(wrap(component));\n });\n };\n}\n\nexport interface DebugFunction {\n (options?: DebugOptions | string): void;\n shallow: (message?: string) => void;\n}\n\nfunction debug(instance: ReactTestInstance, renderer: ReactTestRenderer): DebugFunction {\n function debugImpl(options?: DebugOptions | string) {\n const { defaultDebugOptions } = getConfig();\n const debugOptions =\n typeof options === 'string'\n ? { ...defaultDebugOptions, message: options }\n : { ...defaultDebugOptions, ...options };\n\n if (typeof options === 'string') {\n // eslint-disable-next-line no-console\n console.warn(\n 'Using debug(\"message\") is deprecated and will be removed in future release, please use debug({ message; \"message\" }) instead.',\n );\n }\n\n const json = renderer.toJSON();\n if (json) {\n return debugDeep(json, debugOptions);\n }\n }\n debugImpl.shallow = (message?: string) => debugShallow(instance, message);\n return debugImpl;\n}\n"],"mappings":";;;;;;;AAKA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA+B,IAAAC,KAAA,GAAAH,MAAA;AAE/B,IAAAI,IAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AACA,IAAAO,UAAA,GAAAJ,sBAAA,CAAAH,OAAA;AACA,IAAAQ,aAAA,GAAAL,sBAAA,CAAAH,OAAA;AACA,IAAAS,mBAAA,GAAAT,OAAA;AACA,IAAAU,iBAAA,GAAAV,OAAA;AACA,IAAAW,UAAA,GAAAX,OAAA;AACA,IAAAY,OAAA,GAAAZ,OAAA;AACA,IAAAa,OAAA,GAAAb,OAAA;AAAgD,SAAAG,uBAAAW,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,yBAAAH,CAAA,6BAAAI,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAD,wBAAA,YAAAA,CAAAH,CAAA,WAAAA,CAAA,GAAAM,CAAA,GAAAD,CAAA,KAAAL,CAAA;AAAA,SAAAf,wBAAAe,CAAA,EAAAK,CAAA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H,IAA8D,EAC9D;EACA,OAAO,UAAUd,SAA6B,EAAE;IAC9C,KAAK,IAAAiC,YAAG,EAAC,MAAM;MACbhB,QAAQ,CAACW,MAAM,CAACd,IAAI,CAACd,SAAS,CAAC,CAAC;IAClC,CAAC,CAAC;EACJ,CAAC;AACH;AAOA,SAASsC,KAAKA,CAACR,QAA2B,EAAEb,QAA2B,EAAiB;EACtF,SAAS2B,SAASA,CAAC3C,OAA+B,EAAE;IAClD,MAAM;MAAE4C;IAAoB,CAAC,GAAG,IAAAlC,iBAAS,EAAC,CAAC;IAC3C,MAAMmC,YAAY,GAChB,OAAO7C,OAAO,KAAK,QAAQ,GACvB;MAAE,GAAG4C,mBAAmB;MAAEE,OAAO,EAAE9C;IAAQ,CAAC,GAC5C;MAAE,GAAG4C,mBAAmB;MAAE,GAAG5C;IAAQ,CAAC;IAE5C,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;MAC/B;MACA+C,OAAO,CAACC,IAAI,CACV,+HACF,CAAC;IACH;IAEA,MAAMC,IAAI,GAAGjC,QAAQ,CAACO,MAAM,CAAC,CAAC;IAC9B,IAAI0B,IAAI,EAAE;MACR,OAAO,IAAAC,kBAAS,EAACD,IAAI,EAAEJ,YAAY,CAAC;IACtC;EACF;EACAF,SAAS,CAACQ,OAAO,GAAIL,OAAgB,IAAK,IAAAM,qBAAY,EAACvB,QAAQ,EAAEiB,OAAO,CAAC;EACzE,OAAOH,SAAS;AAClB","ignoreList":[]}
|
package/build/shallow.js
CHANGED
|
@@ -16,7 +16,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
16
16
|
*/
|
|
17
17
|
function shallowInternal(instance) {
|
|
18
18
|
const renderer = new _shallow.default();
|
|
19
|
-
renderer.render(
|
|
19
|
+
renderer.render(/*#__PURE__*/React.createElement(instance.type, instance.props));
|
|
20
20
|
return {
|
|
21
21
|
output: renderer.getRenderOutput()
|
|
22
22
|
};
|
package/build/shallow.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shallow.js","names":["React","_interopRequireWildcard","require","_shallow","_interopRequireDefault","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","shallowInternal","instance","renderer","ShallowRenderer","render","createElement","type","props","output","getRenderOutput"],"sources":["../src/shallow.ts"],"sourcesContent":["import * as React from 'react';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport ShallowRenderer from 'react-test-renderer/shallow'; // eslint-disable-line import/no-extraneous-dependencies\n\n/**\n * Renders test component shallowly using react-test-renderer/shallow\n */\nexport function shallowInternal(instance: ReactTestInstance | React.ReactElement<any>): {\n output: any;\n} {\n const renderer = new (ShallowRenderer as any)();\n\n renderer.render(React.createElement(instance.type, instance.props));\n\n return {\n output: renderer.getRenderOutput(),\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AAA0D,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,yBAAAH,CAAA,6BAAAI,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAD,wBAAA,YAAAA,CAAAH,CAAA,WAAAA,CAAA,GAAAM,CAAA,GAAAD,CAAA,KAAAL,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAK,CAAA,SAAAA,CAAA,IAAAL,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAE,OAAA,EAAAF,CAAA,QAAAM,CAAA,GAAAH,wBAAA,CAAAE,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAC,GAAA,CAAAP,CAAA,UAAAM,CAAA,CAAAE,GAAA,CAAAR,CAAA,OAAAS,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAf,CAAA,oBAAAe,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAe,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAd,CAAA,EAAAe,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAG,CAAA,IAAAT,CAAA,CAAAM,CAAA,IAAAf,CAAA,CAAAe,CAAA,YAAAN,CAAA,CAAAP,OAAA,GAAAF,CAAA,EAAAM,CAAA,IAAAA,CAAA,CAAAa,GAAA,CAAAnB,CAAA,EAAAS,CAAA,GAAAA,CAAA;AAAC;;AAE3D;AACA;AACA;AACO,SAASW,eAAeA,CAACC,QAAqD,EAEnF;EACA,MAAMC,QAAQ,GAAG,IAAKC,gBAAe,CAAS,CAAC;EAE/CD,QAAQ,CAACE,MAAM,
|
|
1
|
+
{"version":3,"file":"shallow.js","names":["React","_interopRequireWildcard","require","_shallow","_interopRequireDefault","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","shallowInternal","instance","renderer","ShallowRenderer","render","createElement","type","props","output","getRenderOutput"],"sources":["../src/shallow.ts"],"sourcesContent":["import * as React from 'react';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport ShallowRenderer from 'react-test-renderer/shallow'; // eslint-disable-line import/no-extraneous-dependencies\n\n/**\n * Renders test component shallowly using react-test-renderer/shallow\n */\nexport function shallowInternal(instance: ReactTestInstance | React.ReactElement<any>): {\n output: any;\n} {\n const renderer = new (ShallowRen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AAAe,CAAA,YAAAN,CAAA,CAAAP,OAAA,GAAAF,CAAA,EAAAM,CAAA,IAAAA,CAAA,CAAAa,GAAA,CAAAnB,CAAA,EAAAS,CAAA,GAAAA,CAAA;AAAC;;AAE3D;AACA;AACA;AACO,SAASW,eAAeA,CAACC,QAAqD,EAEnF;EACA,MAAMC,QAAQ,GAAG,IAAKC,gBAAe,CAAS,CAAC;EAE/CD,QAAQ,CAACE,MAAM,cAAC7B,KAAK,CAAC8B,aAAa,CAACJ,QAAQ,CAACK,IAAI,EAAEL,QAAQ,CAACM,KAAK,CAAC,CAAC;EAEnE,OAAO;IACLC,MAAM,EAAEN,QAAQ,CAACO,eAAe,CAAC;EACnC,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/act.ts","../src/cleanup.ts","../src/config.ts","../src/fire-event.ts","../src/flush-micro-tasks.ts","../src/index.ts","../src/matches.ts","../src/native-state.ts","../src/pure.ts","../src/react-versions.ts","../src/render-act.ts","../src/render-hook.tsx","../src/render.tsx","../src/screen.ts","../src/shallow.ts","../src/types.ts","../src/wait-for-element-to-be-removed.ts","../src/wait-for.ts","../src/within.ts","../src/helpers/accessibility.ts","../src/helpers/component-tree.ts","../src/helpers/debug-deep.ts","../src/helpers/debug-shallow.ts","../src/helpers/deprecation.ts","../src/helpers/errors.ts","../src/helpers/find-all.ts","../src/helpers/format-default.ts","../src/helpers/format.ts","../src/helpers/host-component-names.tsx","../src/helpers/object.ts","../src/helpers/pointer-events.ts","../src/helpers/query-name.ts","../src/helpers/string-validation.ts","../src/helpers/text-content.ts","../src/helpers/text-input.ts","../src/helpers/timers.ts","../src/helpers/wrap-async.ts","../src/helpers/matchers/match-accessibility-state.ts","../src/helpers/matchers/match-accessibility-value.ts","../src/helpers/matchers/match-array-prop.ts","../src/helpers/matchers/match-label-text.ts","../src/helpers/matchers/match-object-prop.ts","../src/helpers/matchers/match-string-prop.ts","../src/helpers/matchers/match-text-content.ts","../src/matchers/extend-expect.ts","../src/matchers/index.ts","../src/matchers/to-be-busy.tsx","../src/matchers/to-be-checked.tsx","../src/matchers/to-be-disabled.tsx","../src/matchers/to-be-empty-element.tsx","../src/matchers/to-be-expanded.tsx","../src/matchers/to-be-on-the-screen.tsx","../src/matchers/to-be-partially-checked.tsx","../src/matchers/to-be-selected.ts","../src/matchers/to-be-visible.tsx","../src/matchers/to-contain-element.tsx","../src/matchers/to-have-accessibility-value.tsx","../src/matchers/to-have-accessible-name.tsx","../src/matchers/to-have-display-value.tsx","../src/matchers/to-have-prop.ts","../src/matchers/to-have-style.tsx","../src/matchers/to-have-text-content.tsx","../src/matchers/types.ts","../src/matchers/utils.tsx","../src/queries/accessibility-state.ts","../src/queries/accessibility-value.ts","../src/queries/display-value.ts","../src/queries/hint-text.ts","../src/queries/label-text.ts","../src/queries/make-queries.ts","../src/queries/options.ts","../src/queries/placeholder-text.ts","../src/queries/role.ts","../src/queries/test-id.ts","../src/queries/text.ts","../src/queries/unsafe-props.ts","../src/queries/unsafe-type.ts","../src/test-utils/events.ts","../src/test-utils/index.ts","../src/user-event/clear.ts","../src/user-event/index.ts","../src/user-event/paste.ts","../src/user-event/event-builder/base.ts","../src/user-event/event-builder/common.ts","../src/user-event/event-builder/index.ts","../src/user-event/event-builder/scroll-view.ts","../src/user-event/event-builder/text-input.ts","../src/user-event/press/index.ts","../src/user-event/press/press.ts","../src/user-event/scroll/index.ts","../src/user-event/scroll/scroll-to.ts","../src/user-event/scroll/utils.ts","../src/user-event/setup/index.ts","../src/user-event/setup/setup.ts","../src/user-event/type/index.ts","../src/user-event/type/parse-keys.ts","../src/user-event/type/type.ts","../src/user-event/utils/content-size.ts","../src/user-event/utils/dispatch-event.ts","../src/user-event/utils/index.ts","../src/user-event/utils/text-range.ts","../src/user-event/utils/wait.ts"],"version":"5.6.3"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ReactTestInstance } from 'react-test-renderer';
|
|
2
2
|
import { UserEventInstance } from '../setup';
|
|
3
|
+
export declare const DEFAULT_MIN_PRESS_DURATION = 130;
|
|
4
|
+
export declare const DEFAULT_LONG_PRESS_DELAY_MS = 500;
|
|
3
5
|
export interface PressOptions {
|
|
4
6
|
duration?: number;
|
|
5
7
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.DEFAULT_MIN_PRESS_DURATION = exports.DEFAULT_LONG_PRESS_DELAY_MS = void 0;
|
|
6
7
|
exports.longPress = longPress;
|
|
7
8
|
exports.press = press;
|
|
8
9
|
var _act = _interopRequireDefault(require("../../act"));
|
|
@@ -12,18 +13,20 @@ var _pointerEvents = require("../../helpers/pointer-events");
|
|
|
12
13
|
var _hostComponentNames = require("../../helpers/host-component-names");
|
|
13
14
|
var _eventBuilder = require("../event-builder");
|
|
14
15
|
var _utils = require("../utils");
|
|
15
|
-
var _constants = require("./constants");
|
|
16
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
// These are constants defined in the React Native repo
|
|
18
|
+
// See: https://github.com/facebook/react-native/blob/50e38cc9f1e6713228a91ad50f426c4f65e65e1a/packages/react-native/Libraries/Pressability/Pressability.js#L264
|
|
19
|
+
const DEFAULT_MIN_PRESS_DURATION = exports.DEFAULT_MIN_PRESS_DURATION = 130;
|
|
20
|
+
const DEFAULT_LONG_PRESS_DELAY_MS = exports.DEFAULT_LONG_PRESS_DELAY_MS = 500;
|
|
17
21
|
async function press(element) {
|
|
18
22
|
await basePress(this.config, element, {
|
|
19
|
-
type: 'press'
|
|
20
|
-
duration: 0
|
|
23
|
+
type: 'press'
|
|
21
24
|
});
|
|
22
25
|
}
|
|
23
26
|
async function longPress(element, options) {
|
|
24
27
|
await basePress(this.config, element, {
|
|
25
28
|
type: 'longPress',
|
|
26
|
-
duration: options?.duration ??
|
|
29
|
+
duration: options?.duration ?? DEFAULT_LONG_PRESS_DELAY_MS
|
|
27
30
|
});
|
|
28
31
|
}
|
|
29
32
|
const basePress = async (config, element, options) => {
|
|
@@ -48,15 +51,16 @@ const basePress = async (config, element, options) => {
|
|
|
48
51
|
const emitPressablePressEvents = async (config, element, options) => {
|
|
49
52
|
await (0, _utils.wait)(config);
|
|
50
53
|
(0, _utils.dispatchEvent)(element, 'responderGrant', _eventBuilder.EventBuilder.Common.responderGrant());
|
|
51
|
-
|
|
54
|
+
const duration = options.duration ?? DEFAULT_MIN_PRESS_DURATION;
|
|
55
|
+
await (0, _utils.wait)(config, duration);
|
|
52
56
|
(0, _utils.dispatchEvent)(element, 'responderRelease', _eventBuilder.EventBuilder.Common.responderRelease());
|
|
53
57
|
|
|
54
58
|
// React Native will wait for minimal delay of DEFAULT_MIN_PRESS_DURATION
|
|
55
59
|
// before emitting the `pressOut` event. We need to wait here, so that
|
|
56
60
|
// `press()` function does not return before that.
|
|
57
|
-
if (
|
|
61
|
+
if (DEFAULT_MIN_PRESS_DURATION - duration > 0) {
|
|
58
62
|
await (0, _act.default)(async () => {
|
|
59
|
-
await (0, _utils.wait)(config,
|
|
63
|
+
await (0, _utils.wait)(config, DEFAULT_MIN_PRESS_DURATION - duration);
|
|
60
64
|
});
|
|
61
65
|
}
|
|
62
66
|
};
|
|
@@ -74,11 +78,21 @@ const isPressableText = element => {
|
|
|
74
78
|
async function emitTextPressEvents(config, element, options) {
|
|
75
79
|
await (0, _utils.wait)(config);
|
|
76
80
|
(0, _utils.dispatchEvent)(element, 'pressIn', _eventBuilder.EventBuilder.Common.touch());
|
|
77
|
-
|
|
78
|
-
// Emit either `press` or `longPress`.
|
|
79
|
-
(0, _utils.dispatchEvent)(element, options.type, _eventBuilder.EventBuilder.Common.touch());
|
|
80
81
|
await (0, _utils.wait)(config, options.duration);
|
|
82
|
+
|
|
83
|
+
// Long press events are emitted before `pressOut`.
|
|
84
|
+
if (options.type === 'longPress') {
|
|
85
|
+
(0, _utils.dispatchEvent)(element, 'longPress', _eventBuilder.EventBuilder.Common.touch());
|
|
86
|
+
}
|
|
81
87
|
(0, _utils.dispatchEvent)(element, 'pressOut', _eventBuilder.EventBuilder.Common.touch());
|
|
88
|
+
|
|
89
|
+
// Regular press events are emitted after `pressOut` according to the React Native docs.
|
|
90
|
+
// See: https://reactnative.dev/docs/pressable#onpress
|
|
91
|
+
// Experimentally for very short presses (< 130ms) `press` events are actually emitted before `onPressOut`, but
|
|
92
|
+
// we will ignore that as in reality most pressed would be above the 130ms threshold.
|
|
93
|
+
if (options.type === 'press') {
|
|
94
|
+
(0, _utils.dispatchEvent)(element, 'press', _eventBuilder.EventBuilder.Common.touch());
|
|
95
|
+
}
|
|
82
96
|
}
|
|
83
97
|
|
|
84
98
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"press.js","names":["_act","_interopRequireDefault","require","_componentTree","_textInput","_pointerEvents","_hostComponentNames","_eventBuilder","_utils","
|
|
1
|
+
{"version":3,"file":"press.js","names":["_act","_interopRequireDefault","require","_componentTree","_textInput","_pointerEvents","_hostComponentNames","_eventBuilder","_utils","e","__esModule","default","DEFAULT_MIN_PRESS_DURATION","exports","DEFAULT_LONG_PRESS_DELAY_MS","press","element","basePress","config","type","longPress","options","duration","isPressableText","emitTextPressEvents","isHostTextInput","isTextInputEditable","isPointerEventEnabled","emitTextInputPressEvents","isEnabledTouchResponder","emitPressablePressEvents","hostParentElement","getHostParent","wait","dispatchEvent","EventBuilder","Common","responderGrant","responderRelease","act","props","onStartShouldSetResponder","hasPressEventHandler","Boolean","onPress","onLongPress","onPressIn","onPressOut","isHostText","disabled","touch"],"sources":["../../../src/user-event/press/press.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport act from '../../act';\nimport { getHostParent } from '../../helpers/component-tree';\nimport { isTextInputEditable } from '../../helpers/text-input';\nimport { isPointerEventEnabled } from '../../helpers/pointer-events';\nimport { isHostText, isHostTextInput } from '../../helpers/host-component-names';\nimport { EventBuilder } from '../event-builder';\nimport { UserEventConfig, UserEventInstance } from '../setup';\nimport { dispatchEvent, wait } from '../utils';\n\n// These are constants defined in the React Native repo\n// See: https://github.com/facebook/react-native/blob/50e38cc9f1e6713228a91ad50f426c4f65e65e1a/packages/react-native/Libraries/Pressability/Pressability.js#L264\nexport const DEFAULT_MIN_PRESS_DURATION = 130;\nexport const DEFAULT_LONG_PRESS_DELAY_MS = 500;\n\nexport interface PressOptions {\n duration?: number;\n}\n\nexport async function press(this: UserEventInstance, element: ReactTestInstance): Promise<void> {\n await basePress(this.config, element, {\n type: 'press',\n });\n}\n\nexport async function longPress(\n this: UserEventInstance,\n element: ReactTestInstance,\n options?: PressOptions,\n): Promise<void> {\n await basePress(this.config, element, {\n type: 'longPress',\n duration: options?.duration ?? DEFAULT_LONG_PRESS_DELAY_MS,\n });\n}\n\ninterface BasePressOptions {\n type: 'press' | 'longPress';\n duration?: number;\n}\n\nconst basePress = async (\n config: UserEventConfig,\n element: ReactTestInstance,\n options: BasePressOptions,\n): Promise<void> => {\n if (isPressableText(element)) {\n await emitTextPressEvents(config, element, options);\n return;\n }\n\n if (isHostTextInput(element) && isTextInputEditable(element) && isPointerEventEnabled(element)) {\n await emitTextInputPressEvents(config, element, options);\n return;\n }\n\n if (isEnabledTouchResponder(element)) {\n await emitPressablePressEvents(config, element, options);\n return;\n }\n\n const hostParentElement = getHostParent(element);\n if (!hostParentElement) {\n return;\n }\n\n await basePress(config, hostParentElement, options);\n};\n\nconst emitPressablePressEvents = async (\n config: UserEventConfig,\n element: ReactTestInstance,\n options: BasePressOptions,\n) => {\n await wait(config);\n\n dispatchEvent(element, 'responderGrant', EventBuilder.Common.responderGrant());\n\n const duration = options.duration ?? DEFAULT_MIN_PRESS_DURATION;\n await wait(config, duration);\n\n dispatchEvent(element, 'responderRelease', EventBuilder.Common.responderRelease());\n\n // React Native will wait for minimal delay of DEFAULT_MIN_PRESS_DURATION\n // before emitting the `pressOut` event. We need to wait here, so that\n // `press()` function does not return before that.\n if (DEFAULT_MIN_PRESS_DURATION - duration > 0) {\n await act(async () => {\n await wait(config, DEFAULT_MIN_PRESS_DURATION - duration);\n });\n }\n};\n\nconst isEnabledTouchResponder = (element: ReactTestInstance) => {\n return isPointerEventEnabled(element) && element.props.onStartShouldSetResponder?.();\n};\n\nconst isPressableText = (element: ReactTestInstance) => {\n const hasPressEventHandler = Boolean(\n element.props.onPress ||\n element.props.onLongPress ||\n element.props.onPressIn ||\n element.props.onPressOut,\n );\n\n return (\n isHostText(element) &&\n isPointerEventEnabled(element) &&\n !element.props.disabled &&\n hasPressEventHandler\n );\n};\n\n/**\n * Dispatches a press event sequence for Text.\n */\nasync function emitTextPressEvents(\n config: UserEventConfig,\n element: ReactTestInstance,\n options: BasePressOptions,\n) {\n await wait(config);\n dispatchEvent(element, 'pressIn', EventBuilder.Common.touch());\n\n await wait(config, options.duration);\n\n // Long press events are emitted before `pressOut`.\n if (options.type === 'longPress') {\n dispatchEvent(element, 'longPress', EventBuilder.Common.touch());\n }\n\n dispatchEvent(element, 'pressOut', EventBuilder.Common.touch());\n\n // Regular press events are emitted after `pressOut` according to the React Native docs.\n // See: https://reactnative.dev/docs/pressable#onpress\n // Experimentally for very short presses (< 130ms) `press` events are actually emitted before `onPressOut`, but\n // we will ignore that as in reality most pressed would be above the 130ms threshold.\n if (options.type === 'press') {\n dispatchEvent(element, 'press', EventBuilder.Common.touch());\n }\n}\n\n/**\n * Dispatches a press event sequence for TextInput.\n */\nasync function emitTextInputPressEvents(\n config: UserEventConfig,\n element: ReactTestInstance,\n options: BasePressOptions,\n) {\n await wait(config);\n dispatchEvent(element, 'pressIn', EventBuilder.Common.touch());\n\n // Note: TextInput does not have `onPress`/`onLongPress` props.\n\n await wait(config, options.duration);\n dispatchEvent(element, 'pressOut', EventBuilder.Common.touch());\n}\n"],"mappings":";;;;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAA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AAC,CAAC;;EAE9D;;EAEA,MAAM,IAAAjB,WAAI,EAACf,MAAM,EAAEG,OAAO,CAACC,QAAQ,CAAC;EACpC,IAAAY,oBAAa,EAAClB,OAAO,EAAE,UAAU,EAAEmB,0BAAY,CAACC,MAAM,CAACc,KAAK,CAAC,CAAC,CAAC;AACjE","ignoreList":[]}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.dispatchEvent = dispatchEvent;
|
|
7
7
|
var _act = _interopRequireDefault(require("../../act"));
|
|
8
|
+
var _componentTree = require("../../helpers/component-tree");
|
|
8
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
10
|
/**
|
|
10
11
|
* Basic dispatch event function used by User Event module.
|
|
@@ -14,6 +15,9 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
14
15
|
* @param event event payload(s)
|
|
15
16
|
*/
|
|
16
17
|
function dispatchEvent(element, eventName, ...event) {
|
|
18
|
+
if (!(0, _componentTree.isElementMounted)(element)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
17
21
|
const handler = getEventHandler(element, eventName);
|
|
18
22
|
if (!handler) {
|
|
19
23
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","e","__esModule","default","dispatchEvent","element","eventName","event","handler","getEventHandler","act","handleName","getEventHandlerName","handle","props","undefined","charAt","toUpperCase","slice"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport act from '../../act';\n\n/**\n * Basic dispatch event function used by User Event module.\n *\n * @param element element trigger event on\n * @param eventName name of the event\n * @param event event payload(s)\n */\nexport function dispatchEvent(element: ReactTestInstance, eventName: string, ...event: unknown[]) {\n const handler = getEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n // This will be called synchronously.\n void act(() => {\n handler(...event);\n });\n}\n\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const handleName = getEventHandlerName(eventName);\n const handle = element.props[handleName] as unknown;\n if (typeof handle !== 'function') {\n return undefined;\n }\n\n return handle;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n}\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;
|
|
1
|
+
{"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","_componentTree","e","__esModule","default","dispatchEvent","element","eventName","event","isElementMounted","handler","getEventHandler","act","handleName","getEventHandlerName","handle","props","undefined","charAt","toUpperCase","slice"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport act from '../../act';\nimport { isElementMounted } from '../../helpers/component-tree';\n\n/**\n * Basic dispatch event function used by User Event module.\n *\n * @param element element trigger event on\n * @param eventName name of the event\n * @param event event payload(s)\n */\nexport function dispatchEvent(element: ReactTestInstance, eventName: string, ...event: unknown[]) {\n if (!isElementMounted(element)) {\n return;\n }\n\n const handler = getEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n // This will be called synchronously.\n void act(() => {\n handler(...event);\n });\n}\n\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const handleName = getEventHandlerName(eventName);\n const handle = element.props[handleName] as unknown;\n if (typeof handle !== 'function') {\n return undefined;\n }\n\n return handle;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n}\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAAgE,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAaA,CAACC,OAA0B,EAAEC,SAAiB,EAAE,GAAGC,KAAgB,EAAE;EAChG,IAAI,CAAC,IAAAC,+BAAgB,EAACH,OAAO,CAAC,EAAE;IAC9B;EACF;EAEA,MAAMI,OAAO,GAAGC,eAAe,CAACL,OAAO,EAAEC,SAAS,CAAC;EACnD,IAAI,CAACG,OAAO,EAAE;IACZ;EACF;;EAEA;EACA,KAAK,IAAAE,YAAG,EAAC,MAAM;IACbF,OAAO,CAAC,GAAGF,KAAK,CAAC;EACnB,CAAC,CAAC;AACJ;AAEA,SAASG,eAAeA,CAACL,OAA0B,EAAEC,SAAiB,EAAE;EACtE,MAAMM,UAAU,GAAGC,mBAAmB,CAACP,SAAS,CAAC;EACjD,MAAMQ,MAAM,GAAGT,OAAO,CAACU,KAAK,CAACH,UAAU,CAAY;EACnD,IAAI,OAAOE,MAAM,KAAK,UAAU,EAAE;IAChC,OAAOE,SAAS;EAClB;EAEA,OAAOF,MAAM;AACf;AAEA,SAASD,mBAAmBA,CAACP,SAAiB,EAAE;EAC9C,OAAO,KAAKA,SAAS,CAACW,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,GAAGZ,SAAS,CAACa,KAAK,CAAC,CAAC,CAAC,EAAE;AACtE","ignoreList":[]}
|
package/build/within.d.ts
CHANGED
|
@@ -12,10 +12,10 @@ export declare function within(instance: ReactTestInstance): {
|
|
|
12
12
|
UNSAFE_queryAllByProps: (props: {
|
|
13
13
|
[key: string]: any;
|
|
14
14
|
}) => Array<ReactTestInstance>;
|
|
15
|
-
UNSAFE_getByType: <P>(type:
|
|
16
|
-
UNSAFE_getAllByType: <P>(type:
|
|
17
|
-
UNSAFE_queryByType: <P>(type:
|
|
18
|
-
UNSAFE_queryAllByType: <P>(type:
|
|
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>;
|
|
19
19
|
getByA11yValue: import("./queries/make-queries").GetByQuery<import("./helpers/matchers/match-accessibility-value").AccessibilityValueMatcher, import("./queries/options").CommonQueryOptions>;
|
|
20
20
|
getAllByA11yValue: import("./queries/make-queries").GetAllByQuery<import("./helpers/matchers/match-accessibility-value").AccessibilityValueMatcher, import("./queries/options").CommonQueryOptions>;
|
|
21
21
|
queryByA11yValue: import("./queries/make-queries").QueryByQuery<import("./helpers/matchers/match-accessibility-value").AccessibilityValueMatcher, import("./queries/options").CommonQueryOptions>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testing-library/react-native",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.8.1",
|
|
4
4
|
"description": "Simple and complete React Native testing utilities that encourage good testing practices.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"clean": "del build",
|
|
27
27
|
"test": "jest",
|
|
28
|
-
"test:ci": "jest --maxWorkers=2
|
|
28
|
+
"test:ci": "jest --maxWorkers=2",
|
|
29
|
+
"test:ci:coverage": "jest --maxWorkers=2 --collectCoverage=true --coverage-provider=v8",
|
|
29
30
|
"typecheck": "tsc",
|
|
30
31
|
"copy-flowtypes": "cp typings/index.flow.js build",
|
|
31
32
|
"lint": "eslint src --cache",
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
"build:js": "babel src --out-dir build --extensions \".js,.ts,.jsx,.tsx\" --source-maps --ignore \"**/__tests__/**\"",
|
|
34
35
|
"build:ts": "tsc --build tsconfig.release.json",
|
|
35
36
|
"build": "yarn clean && yarn build:js && yarn build:ts && yarn copy-flowtypes",
|
|
36
|
-
"
|
|
37
|
+
"release": "release-it"
|
|
37
38
|
},
|
|
38
39
|
"files": [
|
|
39
40
|
"build/",
|
|
@@ -62,31 +63,31 @@
|
|
|
62
63
|
}
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
|
-
"@babel/cli": "^7.
|
|
66
|
-
"@babel/core": "^7.25.
|
|
67
|
-
"@babel/plugin-transform-flow-strip-types": "^7.25.
|
|
68
|
-
"@babel/preset-env": "^7.25.
|
|
69
|
-
"@babel/preset-flow": "^7.
|
|
70
|
-
"@babel/preset-react": "^7.
|
|
71
|
-
"@babel/preset-typescript": "^7.
|
|
66
|
+
"@babel/cli": "^7.25.9",
|
|
67
|
+
"@babel/core": "^7.25.9",
|
|
68
|
+
"@babel/plugin-transform-flow-strip-types": "^7.25.9",
|
|
69
|
+
"@babel/preset-env": "^7.25.9",
|
|
70
|
+
"@babel/preset-flow": "^7.25.9",
|
|
71
|
+
"@babel/preset-react": "^7.25.9",
|
|
72
|
+
"@babel/preset-typescript": "^7.25.9",
|
|
72
73
|
"@callstack/eslint-config": "^15.0.0",
|
|
73
|
-
"@release-it/conventional-changelog": "^
|
|
74
|
+
"@release-it/conventional-changelog": "^9.0.1",
|
|
74
75
|
"@relmify/jest-serializer-strip-ansi": "^1.0.2",
|
|
75
|
-
"@types/jest": "^29.5.
|
|
76
|
-
"@types/react": "^18.3.
|
|
76
|
+
"@types/jest": "^29.5.14",
|
|
77
|
+
"@types/react": "^18.3.12",
|
|
77
78
|
"@types/react-test-renderer": "^18.3.0",
|
|
78
79
|
"babel-jest": "^29.7.0",
|
|
79
|
-
"del-cli": "^
|
|
80
|
-
"eslint": "^8.57.
|
|
80
|
+
"del-cli": "^6.0.0",
|
|
81
|
+
"eslint": "^8.57.1",
|
|
81
82
|
"eslint-plugin-flowtype": "^8.0.3",
|
|
82
83
|
"eslint-plugin-prettier": "^4.2.1",
|
|
83
84
|
"flow-bin": "~0.170.0",
|
|
84
85
|
"jest": "^29.7.0",
|
|
85
86
|
"prettier": "^2.8.8",
|
|
86
87
|
"react": "18.3.1",
|
|
87
|
-
"react-native": "0.
|
|
88
|
+
"react-native": "0.76.0",
|
|
88
89
|
"react-test-renderer": "18.3.1",
|
|
89
|
-
"release-it": "^17.
|
|
90
|
+
"release-it": "^17.10.0",
|
|
90
91
|
"strip-ansi": "^6.0.1",
|
|
91
92
|
"typescript": "^5.5.4"
|
|
92
93
|
},
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.DEFAULT_MIN_PRESS_DURATION = exports.DEFAULT_LONG_PRESS_DELAY_MS = void 0;
|
|
7
|
-
// These are constants defined in the React Native repo
|
|
8
|
-
|
|
9
|
-
// Used to define the delay before calling onPressOut after a press
|
|
10
|
-
const DEFAULT_MIN_PRESS_DURATION = exports.DEFAULT_MIN_PRESS_DURATION = 130;
|
|
11
|
-
|
|
12
|
-
// Default minimum press duration to trigger a long press
|
|
13
|
-
const DEFAULT_LONG_PRESS_DELAY_MS = exports.DEFAULT_LONG_PRESS_DELAY_MS = 500;
|
|
14
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["DEFAULT_MIN_PRESS_DURATION","exports","DEFAULT_LONG_PRESS_DELAY_MS"],"sources":["../../../src/user-event/press/constants.ts"],"sourcesContent":["// These are constants defined in the React Native repo\n\n// Used to define the delay before calling onPressOut after a press\nexport const DEFAULT_MIN_PRESS_DURATION = 130;\n\n// Default minimum press duration to trigger a long press\nexport const DEFAULT_LONG_PRESS_DELAY_MS = 500;\n"],"mappings":";;;;;;AAAA;;AAEA;AACO,MAAMA,0BAA0B,GAAAC,OAAA,CAAAD,0BAAA,GAAG,GAAG;;AAE7C;AACO,MAAME,2BAA2B,GAAAD,OAAA,CAAAC,2BAAA,GAAG,GAAG","ignoreList":[]}
|