@testing-library/react-native 13.2.1 → 13.3.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/fire-event.d.ts +7 -0
- package/build/fire-event.js +24 -4
- package/build/fire-event.js.map +1 -1
- package/build/helpers/accessibility.js +3 -0
- package/build/helpers/accessibility.js.map +1 -1
- package/build/pure.d.ts +3 -1
- package/build/pure.js +15 -1
- package/build/pure.js.map +1 -1
- package/build/render-act.d.ts +1 -0
- package/build/render-act.js +13 -0
- package/build/render-act.js.map +1 -1
- package/build/render-async.d.ts +104 -0
- package/build/render-async.js +104 -0
- package/build/render-async.js.map +1 -0
- package/build/render.d.ts +8 -2
- package/build/render.js +24 -11
- package/build/render.js.map +1 -1
- package/build/screen.js +4 -1
- package/build/screen.js.map +1 -1
- package/build/test-utils/console.d.ts +1 -0
- package/build/test-utils/console.js +17 -0
- package/build/test-utils/console.js.map +1 -0
- package/build/tsconfig.release.tsbuildinfo +1 -1
- package/build/user-event/clear.js +4 -4
- package/build/user-event/clear.js.map +1 -1
- package/build/user-event/paste.js +8 -8
- package/build/user-event/paste.js.map +1 -1
- package/build/user-event/press/press.js +6 -6
- package/build/user-event/press/press.js.map +1 -1
- package/build/user-event/scroll/scroll-to.js +7 -7
- package/build/user-event/scroll/scroll-to.js.map +1 -1
- package/build/user-event/type/type.js +11 -11
- package/build/user-event/type/type.js.map +1 -1
- package/build/user-event/utils/dispatch-event.d.ts +1 -1
- package/build/user-event/utils/dispatch-event.js +3 -3
- package/build/user-event/utils/dispatch-event.js.map +1 -1
- package/build/wait-for.js +3 -1
- package/build/wait-for.js.map +1 -1
- package/package.json +3 -3
- package/build/test-utils/index.d.ts +0 -1
- package/build/test-utils/index.js +0 -17
- package/build/test-utils/index.js.map +0 -1
package/build/fire-event.d.ts
CHANGED
|
@@ -13,4 +13,11 @@ declare namespace fireEvent {
|
|
|
13
13
|
var changeText: (element: ReactTestInstance, ...data: unknown[]) => undefined;
|
|
14
14
|
var scroll: (element: ReactTestInstance, ...data: unknown[]) => undefined;
|
|
15
15
|
}
|
|
16
|
+
declare function fireEventAsync(element: ReactTestInstance, eventName: EventName, ...data: unknown[]): Promise<undefined>;
|
|
17
|
+
declare namespace fireEventAsync {
|
|
18
|
+
var press: (element: ReactTestInstance, ...data: unknown[]) => Promise<undefined>;
|
|
19
|
+
var changeText: (element: ReactTestInstance, ...data: unknown[]) => Promise<undefined>;
|
|
20
|
+
var scroll: (element: ReactTestInstance, ...data: unknown[]) => Promise<undefined>;
|
|
21
|
+
}
|
|
22
|
+
export { fireEventAsync };
|
|
16
23
|
export default fireEvent;
|
package/build/fire-event.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
exports.fireEventAsync = fireEventAsync;
|
|
7
8
|
exports.isEventEnabled = isEventEnabled;
|
|
8
9
|
exports.isTouchResponder = isTouchResponder;
|
|
9
10
|
var _act = _interopRequireDefault(require("./act"));
|
|
@@ -55,10 +56,10 @@ function findEventHandler(element, eventName, nearestTouchResponder) {
|
|
|
55
56
|
const handler = (0, _eventHandler.getEventHandler)(element, eventName, {
|
|
56
57
|
loose: true
|
|
57
58
|
});
|
|
58
|
-
if (handler && isEventEnabled(element, eventName, touchResponder))
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (element.parent === null
|
|
59
|
+
if (handler && isEventEnabled(element, eventName, touchResponder)) {
|
|
60
|
+
return handler;
|
|
61
|
+
}
|
|
62
|
+
if (element.parent === null) {
|
|
62
63
|
return null;
|
|
63
64
|
}
|
|
64
65
|
return findEventHandler(element.parent, eventName, touchResponder);
|
|
@@ -84,6 +85,25 @@ function fireEvent(element, eventName, ...data) {
|
|
|
84
85
|
fireEvent.press = (element, ...data) => fireEvent(element, 'press', ...data);
|
|
85
86
|
fireEvent.changeText = (element, ...data) => fireEvent(element, 'changeText', ...data);
|
|
86
87
|
fireEvent.scroll = (element, ...data) => fireEvent(element, 'scroll', ...data);
|
|
88
|
+
async function fireEventAsync(element, eventName, ...data) {
|
|
89
|
+
if (!(0, _componentTree.isElementMounted)(element)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
setNativeStateIfNeeded(element, eventName, data[0]);
|
|
93
|
+
const handler = findEventHandler(element, eventName);
|
|
94
|
+
if (!handler) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
let returnValue;
|
|
98
|
+
// eslint-disable-next-line require-await
|
|
99
|
+
await (0, _act.default)(async () => {
|
|
100
|
+
returnValue = handler(...data);
|
|
101
|
+
});
|
|
102
|
+
return returnValue;
|
|
103
|
+
}
|
|
104
|
+
fireEventAsync.press = async (element, ...data) => await fireEventAsync(element, 'press', ...data);
|
|
105
|
+
fireEventAsync.changeText = async (element, ...data) => await fireEventAsync(element, 'changeText', ...data);
|
|
106
|
+
fireEventAsync.scroll = async (element, ...data) => await fireEventAsync(element, 'scroll', ...data);
|
|
87
107
|
var _default = exports.default = fireEvent;
|
|
88
108
|
const scrollEventNames = new Set(['scroll', 'scrollBeginDrag', 'scrollEndDrag', 'momentumScrollBegin', 'momentumScrollEnd']);
|
|
89
109
|
function setNativeStateIfNeeded(element, eventName, value) {
|
package/build/fire-event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fire-event.js","names":["_act","_interopRequireDefault","require","_eventHandler","_componentTree","_hostComponentNames","_pointerEvents","_textInput","_nativeState","e","__esModule","default","isTouchResponder","element","isHostElement","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","isEditableTextInput","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandler","loose","parent","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 type {\n PressableProps,\n ScrollViewProps,\n TextInputProps,\n TextProps,\n ViewProps,\n} from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\n\nimport act from './act';\nimport { getEventHandler } from './event-handler';\nimport { isElementMounted, isHostElement } from './helpers/component-tree';\nimport { isHostScrollView, isHostTextInput } from './helpers/host-component-names';\nimport { isPointerEventEnabled } from './helpers/pointer-events';\nimport { isEditableTextInput } from './helpers/text-input';\nimport { nativeState } from './native-state';\nimport type { Point, StringWithAutocomplete } from './types';\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 (nearestTouchResponder != null && isHostTextInput(nearestTouchResponder)) {\n return (\n isEditableTextInput(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, { loose: true });\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\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 (eventName === 'changeText' && typeof value === 'string' && isEditableTextInput(element)) {\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":";;;;;;;;AASA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAA6C,SAAAD,uBAAAQ,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAKtC,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,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,CAAC5B,OAA0B,EAAEU,SAAiB,EAAE2B,KAAc,EAAE;EAC7F,IAAI3B,SAAS,KAAK,YAAY,IAAI,OAAO2B,KAAK,KAAK,QAAQ,IAAI,IAAAzB,8BAAmB,EAACZ,OAAO,CAAC,EAAE;IAC3FsC,wBAAW,CAACC,eAAe,CAACC,GAAG,CAACxC,OAAO,EAAEqC,KAAK,CAAC;EACjD;EAEA,IAAID,gBAAgB,CAACvB,GAAG,CAACH,SAAS,CAAC,IAAI,IAAA+B,oCAAgB,EAACzC,OAAO,CAAC,EAAE;IAChE,MAAM0C,aAAa,GAAGC,mBAAmB,CAACN,KAAK,CAAC;IAChD,IAAIK,aAAa,EAAE;MACjBJ,wBAAW,CAACM,uBAAuB,CAACJ,GAAG,CAACxC,OAAO,EAAE0C,aAAa,CAAC;IACjE;EACF;AACF;AAEA,SAASC,mBAAmBA,CAACE,KAAc,EAAgB;EACzD,IAAI;IACF;IACA,MAAMH,aAAa,GAAGG,KAAK,EAAEC,WAAW,EAAEJ,aAAa;IACvD,MAAMK,CAAC,GAAGL,aAAa,EAAEK,CAAC;IAC1B,MAAMC,CAAC,GAAGN,aAAa,EAAEM,CAAC;IAC1B,IAAI,OAAOD,CAAC,KAAK,QAAQ,IAAI,OAAOC,CAAC,KAAK,QAAQ,EAAE;MAClD,OAAO;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","_eventHandler","_componentTree","_hostComponentNames","_pointerEvents","_textInput","_nativeState","e","__esModule","default","isTouchResponder","element","isHostElement","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","isEditableTextInput","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandler","loose","parent","fireEvent","data","isElementMounted","setNativeStateIfNeeded","returnValue","act","press","changeText","scroll","fireEventAsync","_default","exports","scrollEventNames","value","nativeState","valueForElement","set","isHostScrollView","contentOffset","tryGetContentOffset","contentOffsetForElement","event","nativeEvent","x","y","Number","isFinite"],"sources":["../src/fire-event.ts"],"sourcesContent":["import type {\n PressableProps,\n ScrollViewProps,\n TextInputProps,\n TextProps,\n ViewProps,\n} from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\n\nimport act from './act';\nimport { getEventHandler } from './event-handler';\nimport { isElementMounted, isHostElement } from './helpers/component-tree';\nimport { isHostScrollView, isHostTextInput } from './helpers/host-component-names';\nimport { isPointerEventEnabled } from './helpers/pointer-events';\nimport { isEditableTextInput } from './helpers/text-input';\nimport { nativeState } from './native-state';\nimport type { Point, StringWithAutocomplete } from './types';\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 (nearestTouchResponder != null && isHostTextInput(nearestTouchResponder)) {\n return (\n isEditableTextInput(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, { loose: true });\n if (handler && isEventEnabled(element, eventName, touchResponder)) {\n return handler;\n }\n\n if (element.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, touchResponder);\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\nasync function fireEventAsync(\n element: ReactTestInstance,\n eventName: EventName,\n ...data: unknown[]\n) {\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 // eslint-disable-next-line require-await\n await act(async () => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n}\n\nfireEventAsync.press = async (element: ReactTestInstance, ...data: unknown[]) =>\n await fireEventAsync(element, 'press', ...data);\n\nfireEventAsync.changeText = async (element: ReactTestInstance, ...data: unknown[]) =>\n await fireEventAsync(element, 'changeText', ...data);\n\nfireEventAsync.scroll = async (element: ReactTestInstance, ...data: unknown[]) =>\n await fireEventAsync(element, 'scroll', ...data);\n\nexport { fireEventAsync };\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 (eventName === 'changeText' && typeof value === 'string' && isEditableTextInput(element)) {\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":";;;;;;;;;AASA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAA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AC,EAAEC,MAAM,CAACC,QAAQ,CAACF,CAAC,CAAC,GAAGA,CAAC,GAAG;MAC9B,CAAC;IACH;EACF,CAAC,CAAC,MAAM;IACN;EAAA;EAGF,OAAO,IAAI;AACb","ignoreList":[]}
|
|
@@ -197,6 +197,9 @@ function computeAriaDisabled(element) {
|
|
|
197
197
|
const {
|
|
198
198
|
props
|
|
199
199
|
} = element;
|
|
200
|
+
if ((0, _hostComponentNames.isHostText)(element) && props.disabled) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
200
203
|
return props['aria-disabled'] ?? props.accessibilityState?.disabled ?? false;
|
|
201
204
|
}
|
|
202
205
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accessibility.js","names":["_reactNative","require","_componentTree","_findAll","_hostComponentNames","_textContent","_textInput","accessibilityStateKeys","exports","accessibilityValueKeys","isHiddenFromAccessibility","element","cache","current","isCurrentSubtreeInaccessible","get","undefined","isSubtreeInaccessible","set","parent","isInaccessible","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","computeAriaModal","isAccessibilityElement","isHostImage","alt","accessible","isHostText","isHostTextInput","isHostSwitch","getRole","explicitRole","role","accessibilityRole","normalizeRole","accessibilityViewIsModal","computeAriaLabel","labelElementId","accessibilityLabelledBy","rootElement","getUnsafeRootElement","labelElement","findAll","node","isHostElement","nativeID","includeHiddenElements","length","getTextContent","explicitLabel","accessibilityLabel","computeAriaBusy","accessibilityState","busy","computeAriaChecked","value","rolesSupportingCheckedState","checked","computeAriaDisabled","isEditableTextInput","disabled","computeAriaExpanded","expanded","computeAriaSelected","selected","computeAriaValue","accessibilityValue","ariaValueMax","ariaValueMin","ariaValueNow","ariaValueText","max","min","now","text","computeAccessibleName","checkbox","radio","switch"],"sources":["../../src/helpers/accessibility.ts"],"sourcesContent":["import type { AccessibilityRole, AccessibilityState, AccessibilityValue, Role } from 'react-native';\nimport { StyleSheet } from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\n\nimport { getHostSiblings, getUnsafeRootElement, isHostElement } from './component-tree';\nimport { findAll } from './find-all';\nimport { isHostImage, isHostSwitch, isHostText, isHostTextInput } from './host-component-names';\nimport { getTextContent } from './text-content';\nimport { isEditableTextInput } from './text-input';\n\ntype IsInaccessibleOptions = {\n cache?: WeakMap<ReactTestInstance, boolean>;\n};\n\nexport const accessibilityStateKeys: (keyof AccessibilityState)[] = [\n 'disabled',\n 'selected',\n 'checked',\n 'busy',\n 'expanded',\n];\n\nexport const accessibilityValueKeys: (keyof AccessibilityValue)[] = ['min', 'max', 'now', 'text'];\n\nexport function isHiddenFromAccessibility(\n element: ReactTestInstance | null,\n { cache }: IsInaccessibleOptions = {},\n): boolean {\n if (element == null) {\n return true;\n }\n\n let current: ReactTestInstance | null = element;\n while (current) {\n let isCurrentSubtreeInaccessible = cache?.get(current);\n\n if (isCurrentSubtreeInaccessible === undefined) {\n isCurrentSubtreeInaccessible = isSubtreeInaccessible(current);\n cache?.set(current, isCurrentSubtreeInaccessible);\n }\n\n if (isCurrentSubtreeInaccessible) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n}\n\n/** RTL-compatibility alias for `isHiddenFromAccessibility` */\nexport const isInaccessible = isHiddenFromAccessibility;\n\nfunction isSubtreeInaccessible(element: ReactTestInstance): boolean {\n // Null props can happen for React.Fragments\n if (element.props == null) {\n return false;\n }\n\n // See: https://reactnative.dev/docs/accessibility#aria-hidden\n if (element.props['aria-hidden']) {\n return true;\n }\n\n // iOS: accessibilityElementsHidden\n // See: https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios\n if (element.props.accessibilityElementsHidden) {\n return true;\n }\n\n // Android: importantForAccessibility\n // See: https://reactnative.dev/docs/accessibility#importantforaccessibility-android\n if (element.props.importantForAccessibility === 'no-hide-descendants') {\n return true;\n }\n\n // Note that `opacity: 0` is not treated as inaccessible on iOS\n const flatStyle = StyleSheet.flatten(element.props.style) ?? {};\n if (flatStyle.display === 'none') return true;\n\n // iOS: accessibilityViewIsModal or aria-modal\n // See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios\n const hostSiblings = getHostSiblings(element);\n if (hostSiblings.some((sibling) => computeAriaModal(sibling))) {\n return true;\n }\n\n return false;\n}\n\nexport function isAccessibilityElement(element: ReactTestInstance | null): boolean {\n if (element == null) {\n return false;\n }\n\n // https://github.com/facebook/react-native/blob/8dabed60f456e76a9e53273b601446f34de41fb5/packages/react-native/Libraries/Image/Image.ios.js#L172\n if (isHostImage(element) && element.props.alt !== undefined) {\n return true;\n }\n\n if (element.props.accessible !== undefined) {\n return element.props.accessible;\n }\n\n return isHostText(element) || isHostTextInput(element) || isHostSwitch(element);\n}\n\n/**\n * Returns the accessibility role for given element. It will return explicit\n * role from either `role` or `accessibilityRole` props if set.\n *\n * If explicit role is not available, it would try to return default element\n * role:\n * - `text` for `Text` elements\n *\n * In all other cases this functions returns `none`.\n *\n * @param element\n * @returns\n */\nexport function getRole(element: ReactTestInstance): Role | AccessibilityRole {\n const explicitRole = element.props.role ?? element.props.accessibilityRole;\n if (explicitRole) {\n return normalizeRole(explicitRole);\n }\n\n if (isHostText(element)) {\n return 'text';\n }\n\n // Note: host Image elements report \"image\" role in screen reader only on Android, but not on iOS.\n // It's better to require explicit role for Image elements.\n\n return 'none';\n}\n\n/**\n * There are some duplications between (ARIA) `Role` and `AccessibilityRole` types.\n * Resolve them by using ARIA `Role` type where possible.\n *\n * @param role Role to normalize\n * @returns Normalized role\n */\nexport function normalizeRole(role: string): Role | AccessibilityRole {\n if (role === 'image') {\n return 'img';\n }\n\n return role as Role | AccessibilityRole;\n}\n\nexport function computeAriaModal(element: ReactTestInstance): boolean | undefined {\n return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal;\n}\n\nexport function computeAriaLabel(element: ReactTestInstance): string | undefined {\n const labelElementId = element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy;\n if (labelElementId) {\n const rootElement = getUnsafeRootElement(element);\n const labelElement = findAll(\n rootElement,\n (node) => isHostElement(node) && node.props.nativeID === labelElementId,\n { includeHiddenElements: true },\n );\n if (labelElement.length > 0) {\n return getTextContent(labelElement[0]);\n }\n }\n\n const explicitLabel = element.props['aria-label'] ?? element.props.accessibilityLabel;\n if (explicitLabel) {\n return explicitLabel;\n }\n\n //https://github.com/facebook/react-native/blob/8dabed60f456e76a9e53273b601446f34de41fb5/packages/react-native/Libraries/Image/Image.ios.js#L173\n if (isHostImage(element) && element.props.alt) {\n return element.props.alt;\n }\n\n return undefined;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#busy-state\nexport function computeAriaBusy({ props }: ReactTestInstance): boolean {\n return props['aria-busy'] ?? props.accessibilityState?.busy ?? false;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#checked-state\nexport function computeAriaChecked(element: ReactTestInstance): AccessibilityState['checked'] {\n const { props } = element;\n\n if (isHostSwitch(element)) {\n return props.value;\n }\n\n const role = getRole(element);\n if (!rolesSupportingCheckedState[role]) {\n return undefined;\n }\n\n return props['aria-checked'] ?? props.accessibilityState?.checked;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#disabled-state\nexport function computeAriaDisabled(element: ReactTestInstance): boolean {\n if (isHostTextInput(element) && !isEditableTextInput(element)) {\n return true;\n }\n\n const { props } = element;\n return props['aria-disabled'] ?? props.accessibilityState?.disabled ?? false;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#expanded-state\nexport function computeAriaExpanded({ props }: ReactTestInstance): boolean | undefined {\n return props['aria-expanded'] ?? props.accessibilityState?.expanded;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#selected-state\nexport function computeAriaSelected({ props }: ReactTestInstance): boolean {\n return props['aria-selected'] ?? props.accessibilityState?.selected ?? false;\n}\n\nexport function computeAriaValue(element: ReactTestInstance): AccessibilityValue {\n const {\n accessibilityValue,\n 'aria-valuemax': ariaValueMax,\n 'aria-valuemin': ariaValueMin,\n 'aria-valuenow': ariaValueNow,\n 'aria-valuetext': ariaValueText,\n } = element.props;\n\n return {\n max: ariaValueMax ?? accessibilityValue?.max,\n min: ariaValueMin ?? accessibilityValue?.min,\n now: ariaValueNow ?? accessibilityValue?.now,\n text: ariaValueText ?? accessibilityValue?.text,\n };\n}\n\nexport function computeAccessibleName(element: ReactTestInstance): string | undefined {\n return computeAriaLabel(element) ?? getTextContent(element);\n}\n\ntype RoleSupportMap = Partial<Record<Role | AccessibilityRole, true>>;\n\nexport const rolesSupportingCheckedState: RoleSupportMap = {\n checkbox: true,\n radio: true,\n switch: true,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAMO,MAAMM,sBAAoD,GAAAC,OAAA,CAAAD,sBAAA,GAAG,CAClE,UAAU,EACV,UAAU,EACV,SAAS,EACT,MAAM,EACN,UAAU,CACX;AAEM,MAAME,sBAAoD,GAAAD,OAAA,CAAAC,sBAAA,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC;AAE1F,SAASC,yBAAyBA,CACvCC,OAAiC,EACjC;EAAEC;AAA6B,CAAC,GAAG,CAAC,CAAC,EAC5B;EACT,IAAID,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIE,OAAiC,GAAGF,OAAO;EAC/C,OAAOE,OAAO,EAAE;IACd,IAAIC,4BAA4B,GAAGF,KAAK,EAAEG,GAAG,CAACF,OAAO,CAAC;IAEtD,IAAIC,4BAA4B,KAAKE,SAAS,EAAE;MAC9CF,4BAA4B,GAAGG,qBAAqB,CAACJ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C7D;AAIO,MAAMwD,2BAA2C,GAAA3D,OAAA,CAAA2D,2BAAA,GAAG;EACzDoB,QAAQ,EAAE,IAAI;EACdC,KAAK,EAAE,IAAI;EACXC,MAAM,EAAE;AACV,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"accessibility.js","names":["_reactNative","require","_componentTree","_findAll","_hostComponentNames","_textContent","_textInput","accessibilityStateKeys","exports","accessibilityValueKeys","isHiddenFromAccessibility","element","cache","current","isCurrentSubtreeInaccessible","get","undefined","isSubtreeInaccessible","set","parent","isInaccessible","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","computeAriaModal","isAccessibilityElement","isHostImage","alt","accessible","isHostText","isHostTextInput","isHostSwitch","getRole","explicitRole","role","accessibilityRole","normalizeRole","accessibilityViewIsModal","computeAriaLabel","labelElementId","accessibilityLabelledBy","rootElement","getUnsafeRootElement","labelElement","findAll","node","isHostElement","nativeID","includeHiddenElements","length","getTextContent","explicitLabel","accessibilityLabel","computeAriaBusy","accessibilityState","busy","computeAriaChecked","value","rolesSupportingCheckedState","checked","computeAriaDisabled","isEditableTextInput","disabled","computeAriaExpanded","expanded","computeAriaSelected","selected","computeAriaValue","accessibilityValue","ariaValueMax","ariaValueMin","ariaValueNow","ariaValueText","max","min","now","text","computeAccessibleName","checkbox","radio","switch"],"sources":["../../src/helpers/accessibility.ts"],"sourcesContent":["import type { AccessibilityRole, AccessibilityState, AccessibilityValue, Role } from 'react-native';\nimport { StyleSheet } from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\n\nimport { getHostSiblings, getUnsafeRootElement, isHostElement } from './component-tree';\nimport { findAll } from './find-all';\nimport { isHostImage, isHostSwitch, isHostText, isHostTextInput } from './host-component-names';\nimport { getTextContent } from './text-content';\nimport { isEditableTextInput } from './text-input';\n\ntype IsInaccessibleOptions = {\n cache?: WeakMap<ReactTestInstance, boolean>;\n};\n\nexport const accessibilityStateKeys: (keyof AccessibilityState)[] = [\n 'disabled',\n 'selected',\n 'checked',\n 'busy',\n 'expanded',\n];\n\nexport const accessibilityValueKeys: (keyof AccessibilityValue)[] = ['min', 'max', 'now', 'text'];\n\nexport function isHiddenFromAccessibility(\n element: ReactTestInstance | null,\n { cache }: IsInaccessibleOptions = {},\n): boolean {\n if (element == null) {\n return true;\n }\n\n let current: ReactTestInstance | null = element;\n while (current) {\n let isCurrentSubtreeInaccessible = cache?.get(current);\n\n if (isCurrentSubtreeInaccessible === undefined) {\n isCurrentSubtreeInaccessible = isSubtreeInaccessible(current);\n cache?.set(current, isCurrentSubtreeInaccessible);\n }\n\n if (isCurrentSubtreeInaccessible) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n}\n\n/** RTL-compatibility alias for `isHiddenFromAccessibility` */\nexport const isInaccessible = isHiddenFromAccessibility;\n\nfunction isSubtreeInaccessible(element: ReactTestInstance): boolean {\n // Null props can happen for React.Fragments\n if (element.props == null) {\n return false;\n }\n\n // See: https://reactnative.dev/docs/accessibility#aria-hidden\n if (element.props['aria-hidden']) {\n return true;\n }\n\n // iOS: accessibilityElementsHidden\n // See: https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios\n if (element.props.accessibilityElementsHidden) {\n return true;\n }\n\n // Android: importantForAccessibility\n // See: https://reactnative.dev/docs/accessibility#importantforaccessibility-android\n if (element.props.importantForAccessibility === 'no-hide-descendants') {\n return true;\n }\n\n // Note that `opacity: 0` is not treated as inaccessible on iOS\n const flatStyle = StyleSheet.flatten(element.props.style) ?? {};\n if (flatStyle.display === 'none') return true;\n\n // iOS: accessibilityViewIsModal or aria-modal\n // See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios\n const hostSiblings = getHostSiblings(element);\n if (hostSiblings.some((sibling) => computeAriaModal(sibling))) {\n return true;\n }\n\n return false;\n}\n\nexport function isAccessibilityElement(element: ReactTestInstance | null): boolean {\n if (element == null) {\n return false;\n }\n\n // https://github.com/facebook/react-native/blob/8dabed60f456e76a9e53273b601446f34de41fb5/packages/react-native/Libraries/Image/Image.ios.js#L172\n if (isHostImage(element) && element.props.alt !== undefined) {\n return true;\n }\n\n if (element.props.accessible !== undefined) {\n return element.props.accessible;\n }\n\n return isHostText(element) || isHostTextInput(element) || isHostSwitch(element);\n}\n\n/**\n * Returns the accessibility role for given element. It will return explicit\n * role from either `role` or `accessibilityRole` props if set.\n *\n * If explicit role is not available, it would try to return default element\n * role:\n * - `text` for `Text` elements\n *\n * In all other cases this functions returns `none`.\n *\n * @param element\n * @returns\n */\nexport function getRole(element: ReactTestInstance): Role | AccessibilityRole {\n const explicitRole = element.props.role ?? element.props.accessibilityRole;\n if (explicitRole) {\n return normalizeRole(explicitRole);\n }\n\n if (isHostText(element)) {\n return 'text';\n }\n\n // Note: host Image elements report \"image\" role in screen reader only on Android, but not on iOS.\n // It's better to require explicit role for Image elements.\n\n return 'none';\n}\n\n/**\n * There are some duplications between (ARIA) `Role` and `AccessibilityRole` types.\n * Resolve them by using ARIA `Role` type where possible.\n *\n * @param role Role to normalize\n * @returns Normalized role\n */\nexport function normalizeRole(role: string): Role | AccessibilityRole {\n if (role === 'image') {\n return 'img';\n }\n\n return role as Role | AccessibilityRole;\n}\n\nexport function computeAriaModal(element: ReactTestInstance): boolean | undefined {\n return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal;\n}\n\nexport function computeAriaLabel(element: ReactTestInstance): string | undefined {\n const labelElementId = element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy;\n if (labelElementId) {\n const rootElement = getUnsafeRootElement(element);\n const labelElement = findAll(\n rootElement,\n (node) => isHostElement(node) && node.props.nativeID === labelElementId,\n { includeHiddenElements: true },\n );\n if (labelElement.length > 0) {\n return getTextContent(labelElement[0]);\n }\n }\n\n const explicitLabel = element.props['aria-label'] ?? element.props.accessibilityLabel;\n if (explicitLabel) {\n return explicitLabel;\n }\n\n //https://github.com/facebook/react-native/blob/8dabed60f456e76a9e53273b601446f34de41fb5/packages/react-native/Libraries/Image/Image.ios.js#L173\n if (isHostImage(element) && element.props.alt) {\n return element.props.alt;\n }\n\n return undefined;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#busy-state\nexport function computeAriaBusy({ props }: ReactTestInstance): boolean {\n return props['aria-busy'] ?? props.accessibilityState?.busy ?? false;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#checked-state\nexport function computeAriaChecked(element: ReactTestInstance): AccessibilityState['checked'] {\n const { props } = element;\n\n if (isHostSwitch(element)) {\n return props.value;\n }\n\n const role = getRole(element);\n if (!rolesSupportingCheckedState[role]) {\n return undefined;\n }\n\n return props['aria-checked'] ?? props.accessibilityState?.checked;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#disabled-state\nexport function computeAriaDisabled(element: ReactTestInstance): boolean {\n if (isHostTextInput(element) && !isEditableTextInput(element)) {\n return true;\n }\n\n const { props } = element;\n\n if (isHostText(element) && props.disabled) {\n return true;\n }\n\n return props['aria-disabled'] ?? props.accessibilityState?.disabled ?? false;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#expanded-state\nexport function computeAriaExpanded({ props }: ReactTestInstance): boolean | undefined {\n return props['aria-expanded'] ?? props.accessibilityState?.expanded;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#selected-state\nexport function computeAriaSelected({ props }: ReactTestInstance): boolean {\n return props['aria-selected'] ?? props.accessibilityState?.selected ?? false;\n}\n\nexport function computeAriaValue(element: ReactTestInstance): AccessibilityValue {\n const {\n accessibilityValue,\n 'aria-valuemax': ariaValueMax,\n 'aria-valuemin': ariaValueMin,\n 'aria-valuenow': ariaValueNow,\n 'aria-valuetext': ariaValueText,\n } = element.props;\n\n return {\n max: ariaValueMax ?? accessibilityValue?.max,\n min: ariaValueMin ?? accessibilityValue?.min,\n now: ariaValueNow ?? accessibilityValue?.now,\n text: ariaValueText ?? accessibilityValue?.text,\n };\n}\n\nexport function computeAccessibleName(element: ReactTestInstance): string | undefined {\n return computeAriaLabel(element) ?? getTextContent(element);\n}\n\ntype RoleSupportMap = Partial<Record<Role | AccessibilityRole, true>>;\n\nexport const rolesSupportingCheckedState: RoleSupportMap = {\n checkbox: true,\n radio: true,\n switch: true,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAMO,MAAMM,sBAAoD,GAAAC,OAAA,CAAAD,sBAAA,GAAG,CAClE,UAAU,EACV,UAAU,EACV,SAAS,EACT,MAAM,EACN,UAAU,CACX;AAEM,MAAME,sBAAoD,GAAAD,OAAA,CAAAC,sBAAA,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC;AAE1F,SAASC,yBAAyBA,CACvCC,OAAiC,EACjC;EAAEC;AAA6B,CAAC,GAAG,CAAC,CAAC,EAC5B;EACT,IAAID,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIE,OAAiC,GAAGF,OAAO;EAC/C,OAAOE,OAAO,EAAE;IACd,IAAIC,4BAA4B,GAAGF,KAAK,EAAEG,GAAG,CAACF,OAAO,CAAC;IAEtD,IAAIC,4BAA4B,KAAKE,SAAS,EAAE;MAC9CF,4BAA4B,GAAGG,qBAAqB,CAACJ,OAAO,CAAC;MAC7DD,KAAK,EAAEM,GAAG,CAACL,OAAO,EAAEC,4BAA4B,CAAC;IACnD;IAEA,IAAIA,4BAA4B,EAAE;MAChC,OAAO,IAAI;IACb;IAEAD,OAAO,GAAGA,OAAO,CAACM,MAAM;EAC1B;EAEA,OAAO,KAAK;AACd;;AAEA;AACO,MAAMC,cAAc,GAAAZ,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,EAAE;AACV,CAAC","ignoreList":[]}
|
package/build/pure.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { default as act } from './act';
|
|
2
2
|
export { default as cleanup } from './cleanup';
|
|
3
|
-
export { default as fireEvent } from './fire-event';
|
|
3
|
+
export { default as fireEvent, fireEventAsync } from './fire-event';
|
|
4
4
|
export { default as render } from './render';
|
|
5
|
+
export { default as renderAsync } from './render-async';
|
|
5
6
|
export { default as waitFor } from './wait-for';
|
|
6
7
|
export { default as waitForElementToBeRemoved } from './wait-for-element-to-be-removed';
|
|
7
8
|
export { within, getQueriesForElement } from './within';
|
|
@@ -12,6 +13,7 @@ export { renderHook } from './render-hook';
|
|
|
12
13
|
export { screen } from './screen';
|
|
13
14
|
export { userEvent } from './user-event';
|
|
14
15
|
export type { RenderOptions, RenderResult, RenderResult as RenderAPI, DebugFunction, } from './render';
|
|
16
|
+
export type { RenderAsyncOptions, RenderAsyncResult } from './render-async';
|
|
15
17
|
export type { RenderHookOptions, RenderHookResult } from './render-hook';
|
|
16
18
|
export type { Config } from './config';
|
|
17
19
|
export type { UserEventConfig } from './user-event';
|
package/build/pure.js
CHANGED
|
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "fireEvent", {
|
|
|
27
27
|
return _fireEvent.default;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
+
Object.defineProperty(exports, "fireEventAsync", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _fireEvent.fireEventAsync;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
30
36
|
Object.defineProperty(exports, "getDefaultNormalizer", {
|
|
31
37
|
enumerable: true,
|
|
32
38
|
get: function () {
|
|
@@ -57,6 +63,12 @@ Object.defineProperty(exports, "render", {
|
|
|
57
63
|
return _render.default;
|
|
58
64
|
}
|
|
59
65
|
});
|
|
66
|
+
Object.defineProperty(exports, "renderAsync", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _renderAsync.default;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
60
72
|
Object.defineProperty(exports, "renderHook", {
|
|
61
73
|
enumerable: true,
|
|
62
74
|
get: function () {
|
|
@@ -101,8 +113,9 @@ Object.defineProperty(exports, "within", {
|
|
|
101
113
|
});
|
|
102
114
|
var _act = _interopRequireDefault(require("./act"));
|
|
103
115
|
var _cleanup = _interopRequireDefault(require("./cleanup"));
|
|
104
|
-
var _fireEvent =
|
|
116
|
+
var _fireEvent = _interopRequireWildcard(require("./fire-event"));
|
|
105
117
|
var _render = _interopRequireDefault(require("./render"));
|
|
118
|
+
var _renderAsync = _interopRequireDefault(require("./render-async"));
|
|
106
119
|
var _waitFor = _interopRequireDefault(require("./wait-for"));
|
|
107
120
|
var _waitForElementToBeRemoved = _interopRequireDefault(require("./wait-for-element-to-be-removed"));
|
|
108
121
|
var _within = require("./within");
|
|
@@ -112,5 +125,6 @@ var _matches = require("./matches");
|
|
|
112
125
|
var _renderHook = require("./render-hook");
|
|
113
126
|
var _screen = require("./screen");
|
|
114
127
|
var _userEvent = require("./user-event");
|
|
128
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
115
129
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
116
130
|
//# sourceMappingURL=pure.js.map
|
package/build/pure.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pure.js","names":["_act","_interopRequireDefault","require","_cleanup","_fireEvent","_render","_waitFor","_waitForElementToBeRemoved","_within","_config","_accessibility","_matches","_renderHook","_screen","_userEvent","e","__esModule","default"],"sources":["../src/pure.ts"],"sourcesContent":["export { default as act } from './act';\nexport { default as cleanup } from './cleanup';\nexport { default as fireEvent } from './fire-event';\nexport { default as render } from './render';\nexport { default as waitFor } from './wait-for';\nexport { default as waitForElementToBeRemoved } from './wait-for-element-to-be-removed';\nexport { within, getQueriesForElement } from './within';\n\nexport { configure, resetToDefaults } from './config';\nexport { isHiddenFromAccessibility, isInaccessible } from './helpers/accessibility';\nexport { getDefaultNormalizer } from './matches';\nexport { renderHook } from './render-hook';\nexport { screen } from './screen';\nexport { userEvent } from './user-event';\n\nexport type {\n RenderOptions,\n RenderResult,\n RenderResult as RenderAPI,\n DebugFunction,\n} from './render';\nexport type { RenderHookOptions, RenderHookResult } from './render-hook';\nexport type { Config } from './config';\nexport type { UserEventConfig } from './user-event';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"pure.js","names":["_act","_interopRequireDefault","require","_cleanup","_fireEvent","_interopRequireWildcard","_render","_renderAsync","_waitFor","_waitForElementToBeRemoved","_within","_config","_accessibility","_matches","_renderHook","_screen","_userEvent","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor"],"sources":["../src/pure.ts"],"sourcesContent":["export { default as act } from './act';\nexport { default as cleanup } from './cleanup';\nexport { default as fireEvent, fireEventAsync } from './fire-event';\nexport { default as render } from './render';\nexport { default as renderAsync } from './render-async';\nexport { default as waitFor } from './wait-for';\nexport { default as waitForElementToBeRemoved } from './wait-for-element-to-be-removed';\nexport { within, getQueriesForElement } from './within';\n\nexport { configure, resetToDefaults } from './config';\nexport { isHiddenFromAccessibility, isInaccessible } from './helpers/accessibility';\nexport { getDefaultNormalizer } from './matches';\nexport { renderHook } from './render-hook';\nexport { screen } from './screen';\nexport { userEvent } from './user-event';\n\nexport type {\n RenderOptions,\n RenderResult,\n RenderResult as RenderAPI,\n DebugFunction,\n} from './render';\nexport type { RenderAsyncOptions, RenderAsyncResult } from './render-async';\nexport type { RenderHookOptions, RenderHookResult } from './render-hook';\nexport type { Config } from './config';\nexport type { UserEventConfig } from './user-event';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAC,uBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,YAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,QAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,0BAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AAEA,IAAAS,OAAA,GAAAT,OAAA;AACA,IAAAU,cAAA,GAAAV,OAAA;AACA,IAAAW,QAAA,GAAAX,OAAA;AACA,IAAAY,WAAA,GAAAZ,OAAA;AACA,IAAAa,OAAA,GAAAb,OAAA;AACA,IAAAc,UAAA,GAAAd,OAAA;AAAyC,SAAAG,wBAAAY,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAd,uBAAA,YAAAA,CAAAY,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;AAAA,SAAAjB,uBAAAgB,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAK,UAAA,GAAAL,CAAA,KAAAU,OAAA,EAAAV,CAAA","ignoreList":[]}
|
package/build/render-act.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { ReactTestRenderer, TestRendererOptions } from 'react-test-renderer';
|
|
2
2
|
export declare function renderWithAct(component: React.ReactElement, options?: Partial<TestRendererOptions>): ReactTestRenderer;
|
|
3
|
+
export declare function renderWithAsyncAct(component: React.ReactElement, options?: Partial<TestRendererOptions>): Promise<ReactTestRenderer>;
|
package/build/render-act.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.renderWithAct = renderWithAct;
|
|
7
|
+
exports.renderWithAsyncAct = renderWithAsyncAct;
|
|
7
8
|
var _reactTestRenderer = _interopRequireDefault(require("react-test-renderer"));
|
|
8
9
|
var _act = _interopRequireDefault(require("./act"));
|
|
9
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -19,4 +20,16 @@ function renderWithAct(component, options) {
|
|
|
19
20
|
// @ts-expect-error: `act` is synchronous, so `renderer` is already initialized here
|
|
20
21
|
return renderer;
|
|
21
22
|
}
|
|
23
|
+
async function renderWithAsyncAct(component, options) {
|
|
24
|
+
let renderer;
|
|
25
|
+
|
|
26
|
+
// eslint-disable-next-line require-await
|
|
27
|
+
await (0, _act.default)(async () => {
|
|
28
|
+
// @ts-expect-error `TestRenderer.create` is not typed correctly
|
|
29
|
+
renderer = _reactTestRenderer.default.create(component, options);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// @ts-expect-error: `renderer` is already initialized here
|
|
33
|
+
return renderer;
|
|
34
|
+
}
|
|
22
35
|
//# sourceMappingURL=render-act.js.map
|
package/build/render-act.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-act.js","names":["_reactTestRenderer","_interopRequireDefault","require","_act","e","__esModule","default","renderWithAct","component","options","renderer","act","TestRenderer","create"],"sources":["../src/render-act.ts"],"sourcesContent":["import type { ReactTestRenderer, TestRendererOptions } from 'react-test-renderer';\nimport TestRenderer from 'react-test-renderer';\n\nimport act from './act';\n\nexport function renderWithAct(\n component: React.ReactElement,\n options?: Partial<TestRendererOptions>,\n): ReactTestRenderer {\n let renderer: ReactTestRenderer;\n\n // This will be called synchronously.\n void act(() => {\n // @ts-expect-error `TestRenderer.create` is not typed correctly\n renderer = TestRenderer.create(component, options);\n });\n\n // @ts-expect-error: `act` is synchronous, so `renderer` is already initialized here\n return renderer;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"render-act.js","names":["_reactTestRenderer","_interopRequireDefault","require","_act","e","__esModule","default","renderWithAct","component","options","renderer","act","TestRenderer","create","renderWithAsyncAct"],"sources":["../src/render-act.ts"],"sourcesContent":["import type { ReactTestRenderer, TestRendererOptions } from 'react-test-renderer';\nimport TestRenderer from 'react-test-renderer';\n\nimport act from './act';\n\nexport function renderWithAct(\n component: React.ReactElement,\n options?: Partial<TestRendererOptions>,\n): ReactTestRenderer {\n let renderer: ReactTestRenderer;\n\n // This will be called synchronously.\n void act(() => {\n // @ts-expect-error `TestRenderer.create` is not typed correctly\n renderer = TestRenderer.create(component, options);\n });\n\n // @ts-expect-error: `act` is synchronous, so `renderer` is already initialized here\n return renderer;\n}\n\nexport async function renderWithAsyncAct(\n component: React.ReactElement,\n options?: Partial<TestRendererOptions>,\n): Promise<ReactTestRenderer> {\n let renderer: ReactTestRenderer;\n\n // eslint-disable-next-line require-await\n await act(async () => {\n // @ts-expect-error `TestRenderer.create` is not typed correctly\n renderer = TestRenderer.create(component, options);\n });\n\n // @ts-expect-error: `renderer` is already initialized here\n return renderer;\n}\n"],"mappings":";;;;;;;AACA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,IAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAwB,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEjB,SAASG,aAAaA,CAC3BC,SAA6B,EAC7BC,OAAsC,EACnB;EACnB,IAAIC,QAA2B;;EAE/B;EACA,KAAK,IAAAC,YAAG,EAAC,MAAM;IACb;IACAD,QAAQ,GAAGE,0BAAY,CAACC,MAAM,CAACL,SAAS,EAAEC,OAAO,CAAC;EACpD,CAAC,CAAC;;EAEF;EACA,OAAOC,QAAQ;AACjB;AAEO,eAAeI,kBAAkBA,CACtCN,SAA6B,EAC7BC,OAAsC,EACV;EAC5B,IAAIC,QAA2B;;EAE/B;EACA,MAAM,IAAAC,YAAG,EAAC,YAAY;IACpB;IACAD,QAAQ,GAAGE,0BAAY,CAACC,MAAM,CAACL,SAAS,EAAEC,OAAO,CAAC;EACpD,CAAC,CAAC;;EAEF;EACA,OAAOC,QAAQ;AACjB","ignoreList":[]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { ReactTestInstance } from 'react-test-renderer';
|
|
3
|
+
import type { DebugOptions } from './helpers/debug';
|
|
4
|
+
export interface RenderAsyncOptions {
|
|
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
|
+
*/
|
|
9
|
+
wrapper?: React.ComponentType<any>;
|
|
10
|
+
/**
|
|
11
|
+
* Set to `false` to disable concurrent rendering.
|
|
12
|
+
* Otherwise `render` will default to concurrent rendering.
|
|
13
|
+
*/
|
|
14
|
+
concurrentRoot?: boolean;
|
|
15
|
+
createNodeMock?: (element: React.ReactElement) => unknown;
|
|
16
|
+
}
|
|
17
|
+
export type RenderAsyncResult = ReturnType<typeof renderAsync>;
|
|
18
|
+
/**
|
|
19
|
+
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
20
|
+
* to assert on the output.
|
|
21
|
+
*/
|
|
22
|
+
export default function renderAsync<T>(component: React.ReactElement<T>, options?: RenderAsyncOptions): Promise<{
|
|
23
|
+
rerender: (_component: React.ReactElement) => never;
|
|
24
|
+
rerenderAsync: (component: React.ReactElement) => Promise<void>;
|
|
25
|
+
update: (_component: React.ReactElement) => never;
|
|
26
|
+
updateAsync: (component: React.ReactElement) => Promise<void>;
|
|
27
|
+
unmount: () => never;
|
|
28
|
+
unmountAsync: () => Promise<void>;
|
|
29
|
+
toJSON: () => null | import("react-test-renderer").ReactTestRendererJSON | import("react-test-renderer").ReactTestRendererJSON[];
|
|
30
|
+
debug: DebugFunction;
|
|
31
|
+
root: ReactTestInstance;
|
|
32
|
+
UNSAFE_root: ReactTestInstance;
|
|
33
|
+
UNSAFE_getByProps: (props: {
|
|
34
|
+
[x: string]: unknown;
|
|
35
|
+
}) => ReactTestInstance;
|
|
36
|
+
UNSAFE_getAllByProps: (props: {
|
|
37
|
+
[x: string]: unknown;
|
|
38
|
+
}) => Array<ReactTestInstance>;
|
|
39
|
+
UNSAFE_queryByProps: (props: {
|
|
40
|
+
[x: string]: unknown;
|
|
41
|
+
}) => ReactTestInstance | null;
|
|
42
|
+
UNSAFE_queryAllByProps: (props: {
|
|
43
|
+
[x: string]: unknown;
|
|
44
|
+
}) => Array<ReactTestInstance>;
|
|
45
|
+
UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;
|
|
46
|
+
UNSAFE_getAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance>;
|
|
47
|
+
UNSAFE_queryByType: <P>(type: React.ComponentType<P>) => ReactTestInstance | null;
|
|
48
|
+
UNSAFE_queryAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance>;
|
|
49
|
+
getByRole: import("./queries/make-queries").GetByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
|
|
50
|
+
getAllByRole: import("./queries/make-queries").GetAllByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
|
|
51
|
+
queryByRole: import("./queries/make-queries").QueryByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
|
|
52
|
+
queryAllByRole: import("./queries/make-queries").QueryAllByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
|
|
53
|
+
findByRole: import("./queries/make-queries").FindByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
|
|
54
|
+
findAllByRole: import("./queries/make-queries").FindAllByQuery<import("./queries/role").ByRoleMatcher, import("./queries/role").ByRoleOptions>;
|
|
55
|
+
getByHintText: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
56
|
+
getAllByHintText: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
57
|
+
queryByHintText: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
58
|
+
queryAllByHintText: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
59
|
+
findByHintText: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
60
|
+
findAllByHintText: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
61
|
+
getByA11yHint: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
62
|
+
getAllByA11yHint: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
63
|
+
queryByA11yHint: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
64
|
+
queryAllByA11yHint: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
65
|
+
findByA11yHint: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
66
|
+
findAllByA11yHint: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
67
|
+
getByAccessibilityHint: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
68
|
+
getAllByAccessibilityHint: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
69
|
+
queryByAccessibilityHint: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
70
|
+
queryAllByAccessibilityHint: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
71
|
+
findByAccessibilityHint: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
72
|
+
findAllByAccessibilityHint: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
73
|
+
getByLabelText: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
74
|
+
getAllByLabelText: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
75
|
+
queryByLabelText: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
76
|
+
queryAllByLabelText: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
77
|
+
findByLabelText: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
78
|
+
findAllByLabelText: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
79
|
+
getByPlaceholderText: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
80
|
+
getAllByPlaceholderText: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
81
|
+
queryByPlaceholderText: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
82
|
+
queryAllByPlaceholderText: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
83
|
+
findByPlaceholderText: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
84
|
+
findAllByPlaceholderText: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
85
|
+
getByDisplayValue: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
86
|
+
getAllByDisplayValue: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
87
|
+
queryByDisplayValue: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
88
|
+
queryAllByDisplayValue: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
89
|
+
findByDisplayValue: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
90
|
+
findAllByDisplayValue: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
91
|
+
getByTestId: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
92
|
+
getAllByTestId: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
93
|
+
queryByTestId: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
94
|
+
queryAllByTestId: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
95
|
+
findByTestId: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
96
|
+
findAllByTestId: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
97
|
+
getByText: import("./queries/make-queries").GetByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
98
|
+
getAllByText: import("./queries/make-queries").GetAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
99
|
+
queryByText: import("./queries/make-queries").QueryByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
100
|
+
queryAllByText: import("./queries/make-queries").QueryAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
101
|
+
findByText: import("./queries/make-queries").FindByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
102
|
+
findAllByText: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
103
|
+
}>;
|
|
104
|
+
export type DebugFunction = (options?: DebugOptions) => void;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = renderAsync;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _act = _interopRequireDefault(require("./act"));
|
|
9
|
+
var _cleanup = require("./cleanup");
|
|
10
|
+
var _config = require("./config");
|
|
11
|
+
var _componentTree = require("./helpers/component-tree");
|
|
12
|
+
var _debug = require("./helpers/debug");
|
|
13
|
+
var _errors = require("./helpers/errors");
|
|
14
|
+
var _renderAct = require("./render-act");
|
|
15
|
+
var _screen = require("./screen");
|
|
16
|
+
var _within = require("./within");
|
|
17
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
19
|
+
/**
|
|
20
|
+
* Renders test component deeply using React Test Renderer and exposes helpers
|
|
21
|
+
* to assert on the output.
|
|
22
|
+
*/
|
|
23
|
+
async function renderAsync(component, options = {}) {
|
|
24
|
+
const {
|
|
25
|
+
wrapper: Wrapper,
|
|
26
|
+
concurrentRoot,
|
|
27
|
+
...rest
|
|
28
|
+
} = options || {};
|
|
29
|
+
const testRendererOptions = {
|
|
30
|
+
...rest,
|
|
31
|
+
// @ts-expect-error incomplete typing on RTR package
|
|
32
|
+
unstable_isConcurrent: concurrentRoot ?? (0, _config.getConfig)().concurrentRoot
|
|
33
|
+
};
|
|
34
|
+
const wrap = element => Wrapper ? /*#__PURE__*/React.createElement(Wrapper, null, element) : element;
|
|
35
|
+
const renderer = await (0, _renderAct.renderWithAsyncAct)(wrap(component), testRendererOptions);
|
|
36
|
+
return buildRenderResult(renderer, wrap);
|
|
37
|
+
}
|
|
38
|
+
function buildRenderResult(renderer, wrap) {
|
|
39
|
+
const instance = renderer.root;
|
|
40
|
+
const rerender = _component => {
|
|
41
|
+
throw new _errors.ErrorWithStack('"rerender(...)" is not supported when using "renderAsync" use "await rerenderAsync(...)" instead', rerender);
|
|
42
|
+
};
|
|
43
|
+
const rerenderAsync = async component => {
|
|
44
|
+
// eslint-disable-next-line require-await
|
|
45
|
+
await (0, _act.default)(async () => {
|
|
46
|
+
renderer.update(wrap(component));
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const unmount = () => {
|
|
50
|
+
throw new _errors.ErrorWithStack('"unmount()" is not supported when using "renderAsync" use "await unmountAsync()" instead', unmount);
|
|
51
|
+
};
|
|
52
|
+
const unmountAsync = async () => {
|
|
53
|
+
// eslint-disable-next-line require-await
|
|
54
|
+
await (0, _act.default)(async () => {
|
|
55
|
+
renderer.unmount();
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
(0, _cleanup.addToCleanupQueue)(unmountAsync);
|
|
59
|
+
const result = {
|
|
60
|
+
...(0, _within.getQueriesForElement)(instance),
|
|
61
|
+
rerender,
|
|
62
|
+
rerenderAsync,
|
|
63
|
+
update: rerender,
|
|
64
|
+
// alias for `rerender`
|
|
65
|
+
updateAsync: rerenderAsync,
|
|
66
|
+
// alias for `rerenderAsync`
|
|
67
|
+
unmount,
|
|
68
|
+
unmountAsync,
|
|
69
|
+
toJSON: renderer.toJSON,
|
|
70
|
+
debug: makeDebug(renderer),
|
|
71
|
+
get root() {
|
|
72
|
+
return (0, _componentTree.getHostSelves)(instance)[0];
|
|
73
|
+
},
|
|
74
|
+
UNSAFE_root: instance
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Add as non-enumerable property, so that it's safe to enumerate
|
|
78
|
+
// `render` result, e.g. using destructuring rest syntax.
|
|
79
|
+
Object.defineProperty(result, 'container', {
|
|
80
|
+
enumerable: false,
|
|
81
|
+
get() {
|
|
82
|
+
throw new Error("'container' property has been renamed to 'UNSAFE_root'.\n\n" + "Consider using 'root' property which returns root host element.");
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
(0, _screen.setRenderResult)(result);
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
function makeDebug(renderer) {
|
|
89
|
+
function debugImpl(options) {
|
|
90
|
+
const {
|
|
91
|
+
defaultDebugOptions
|
|
92
|
+
} = (0, _config.getConfig)();
|
|
93
|
+
const debugOptions = {
|
|
94
|
+
...defaultDebugOptions,
|
|
95
|
+
...options
|
|
96
|
+
};
|
|
97
|
+
const json = renderer.toJSON();
|
|
98
|
+
if (json) {
|
|
99
|
+
return (0, _debug.debug)(json, debugOptions);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return debugImpl;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=render-async.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-async.js","names":["React","_interopRequireWildcard","require","_act","_interopRequireDefault","_cleanup","_config","_componentTree","_debug","_errors","_renderAct","_screen","_within","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","renderAsync","component","options","wrapper","Wrapper","concurrentRoot","rest","testRendererOptions","unstable_isConcurrent","getConfig","wrap","element","createElement","renderer","renderWithAsyncAct","buildRenderResult","instance","root","rerender","_component","ErrorWithStack","rerenderAsync","act","update","unmount","unmountAsync","addToCleanupQueue","result","getQueriesForElement","updateAsync","toJSON","debug","makeDebug","getHostSelves","UNSAFE_root","enumerable","Error","setRenderResult","debugImpl","defaultDebugOptions","debugOptions","json"],"sources":["../src/render-async.tsx"],"sourcesContent":["import * as React from 'react';\nimport type {\n ReactTestInstance,\n ReactTestRenderer,\n TestRendererOptions,\n} from 'react-test-renderer';\n\nimport act from './act';\nimport { addToCleanupQueue } from './cleanup';\nimport { getConfig } from './config';\nimport { getHostSelves } from './helpers/component-tree';\nimport type { DebugOptions } from './helpers/debug';\nimport { debug } from './helpers/debug';\nimport { ErrorWithStack } from './helpers/errors';\nimport { renderWithAsyncAct } from './render-act';\nimport { setRenderResult } from './screen';\nimport { getQueriesForElement } from './within';\n\nexport interface RenderAsyncOptions {\n /**\n * Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating\n * reusable custom render functions for common data providers.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wrapper?: React.ComponentType<any>;\n\n /**\n * Set to `false` to disable concurrent rendering.\n * Otherwise `render` will default to concurrent rendering.\n */\n // TODO: should we assume concurrentRoot is true for react suspense?\n concurrentRoot?: boolean;\n\n createNodeMock?: (element: React.ReactElement) => unknown;\n}\n\nexport type RenderAsyncResult = ReturnType<typeof renderAsync>;\n\n/**\n * Renders test component deeply using React Test Renderer and exposes helpers\n * to assert on the output.\n */\nexport default async function renderAsync<T>(\n component: React.ReactElement<T>,\n options: RenderAsyncOptions = {},\n) {\n const { wrapper: Wrapper, concurrentRoot, ...rest } = 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 const wrap = (element: React.ReactElement) => (Wrapper ? <Wrapper>{element}</Wrapper> : element);\n const renderer = await renderWithAsyncAct(wrap(component), testRendererOptions);\n return buildRenderResult(renderer, wrap);\n}\n\nfunction buildRenderResult(\n renderer: ReactTestRenderer,\n wrap: (element: React.ReactElement) => React.JSX.Element,\n) {\n const instance = renderer.root;\n\n const rerender = (_component: React.ReactElement) => {\n throw new ErrorWithStack(\n '\"rerender(...)\" is not supported when using \"renderAsync\" use \"await rerenderAsync(...)\" instead',\n rerender,\n );\n };\n const rerenderAsync = async (component: React.ReactElement) => {\n // eslint-disable-next-line require-await\n await act(async () => {\n renderer.update(wrap(component));\n });\n };\n\n const unmount = () => {\n throw new ErrorWithStack(\n '\"unmount()\" is not supported when using \"renderAsync\" use \"await unmountAsync()\" instead',\n unmount,\n );\n };\n const unmountAsync = async () => {\n // eslint-disable-next-line require-await\n await act(async () => {\n renderer.unmount();\n });\n };\n\n addToCleanupQueue(unmountAsync);\n\n const result = {\n ...getQueriesForElement(instance),\n rerender,\n rerenderAsync,\n update: rerender, // alias for `rerender`\n updateAsync: rerenderAsync, // alias for `rerenderAsync`\n unmount,\n unmountAsync,\n toJSON: renderer.toJSON,\n debug: makeDebug(renderer),\n get root(): ReactTestInstance {\n return getHostSelves(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\nexport type DebugFunction = (options?: DebugOptions) => void;\n\nfunction makeDebug(renderer: ReactTestRenderer): DebugFunction {\n function debugImpl(options?: DebugOptions) {\n const { defaultDebugOptions } = getConfig();\n const debugOptions = { ...defaultDebugOptions, ...options };\n const json = renderer.toJSON();\n if (json) {\n return debug(json, debugOptions);\n }\n }\n return debugImpl;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAOA,IAAAC,IAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,UAAA,GAAAR,OAAA;AACA,IAAAS,OAAA,GAAAT,OAAA;AACA,IAAAU,OAAA,GAAAV,OAAA;AAAgD,SAAAE,uBAAAS,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA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AY;IACZK,MAAM,EAAEjB,QAAQ,CAACiB,MAAM;IACvBC,KAAK,EAAEC,SAAS,CAACnB,QAAQ,CAAC;IAC1B,IAAII,IAAIA,CAAA,EAAsB;MAC5B,OAAO,IAAAgB,4BAAa,EAACjB,QAAQ,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IACDkB,WAAW,EAAElB;EACf,CAAC;;EAED;EACA;EACAnB,MAAM,CAACC,cAAc,CAAC6B,MAAM,EAAE,WAAW,EAAE;IACzCQ,UAAU,EAAE,KAAK;IACjB1C,GAAGA,CAAA,EAAG;MACJ,MAAM,IAAI2C,KAAK,CACb,6DAA6D,GAC3D,iEACJ,CAAC;IACH;EACF,CAAC,CAAC;EAEF,IAAAC,uBAAe,EAACV,MAAM,CAAC;EAEvB,OAAOA,MAAM;AACf;AAIA,SAASK,SAASA,CAACnB,QAA2B,EAAiB;EAC7D,SAASyB,SAASA,CAACpC,OAAsB,EAAE;IACzC,MAAM;MAAEqC;IAAoB,CAAC,GAAG,IAAA9B,iBAAS,EAAC,CAAC;IAC3C,MAAM+B,YAAY,GAAG;MAAE,GAAGD,mBAAmB;MAAE,GAAGrC;IAAQ,CAAC;IAC3D,MAAMuC,IAAI,GAAG5B,QAAQ,CAACiB,MAAM,CAAC,CAAC;IAC9B,IAAIW,IAAI,EAAE;MACR,OAAO,IAAAV,YAAK,EAACU,IAAI,EAAED,YAAY,CAAC;IAClC;EACF;EACA,OAAOF,SAAS;AAClB","ignoreList":[]}
|
package/build/render.d.ts
CHANGED
|
@@ -21,9 +21,12 @@ export type RenderResult = ReturnType<typeof render>;
|
|
|
21
21
|
* to assert on the output.
|
|
22
22
|
*/
|
|
23
23
|
export default function render<T>(component: React.ReactElement<T>, options?: RenderOptions): {
|
|
24
|
+
rerender: (component: React.ReactElement) => void;
|
|
25
|
+
rerenderAsync: (component: React.ReactElement) => Promise<void>;
|
|
24
26
|
update: (component: React.ReactElement) => void;
|
|
27
|
+
updateAsync: (component: React.ReactElement) => Promise<void>;
|
|
25
28
|
unmount: () => void;
|
|
26
|
-
|
|
29
|
+
unmountAsync: () => Promise<void>;
|
|
27
30
|
toJSON: () => null | import("react-test-renderer").ReactTestRendererJSON | import("react-test-renderer").ReactTestRendererJSON[];
|
|
28
31
|
debug: DebugFunction;
|
|
29
32
|
root: ReactTestInstance;
|
|
@@ -100,9 +103,12 @@ export default function render<T>(component: React.ReactElement<T>, options?: Re
|
|
|
100
103
|
findAllByText: import("./queries/make-queries").FindAllByQuery<import("./matches").TextMatch, import("./queries/options").CommonQueryOptions & import("./matches").TextMatchOptions>;
|
|
101
104
|
};
|
|
102
105
|
export declare function renderInternal<T>(component: React.ReactElement<T>, options?: RenderOptions): {
|
|
106
|
+
rerender: (component: React.ReactElement) => void;
|
|
107
|
+
rerenderAsync: (component: React.ReactElement) => Promise<void>;
|
|
103
108
|
update: (component: React.ReactElement) => void;
|
|
109
|
+
updateAsync: (component: React.ReactElement) => Promise<void>;
|
|
104
110
|
unmount: () => void;
|
|
105
|
-
|
|
111
|
+
unmountAsync: () => Promise<void>;
|
|
106
112
|
toJSON: () => null | import("react-test-renderer").ReactTestRendererJSON | import("react-test-renderer").ReactTestRendererJSON[];
|
|
107
113
|
debug: DebugFunction;
|
|
108
114
|
root: ReactTestInstance;
|