@testing-library/react-native 12.1.1 → 12.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/config.d.ts +1 -0
- package/build/config.js.map +1 -1
- package/build/fireEvent.d.ts +6 -6
- package/build/fireEvent.js +63 -48
- package/build/fireEvent.js.map +1 -1
- package/build/helpers/accessiblity.js +3 -1
- package/build/helpers/accessiblity.js.map +1 -1
- package/build/helpers/component-tree.d.ts +0 -15
- package/build/helpers/component-tree.js +0 -45
- package/build/helpers/component-tree.js.map +1 -1
- package/build/helpers/deprecation.d.ts +1 -0
- package/build/helpers/deprecation.js +16 -0
- package/build/helpers/deprecation.js.map +1 -1
- package/build/helpers/errors.d.ts +0 -4
- package/build/helpers/errors.js +1 -25
- package/build/helpers/errors.js.map +1 -1
- package/build/helpers/host-component-names.js +4 -1
- package/build/helpers/host-component-names.js.map +1 -1
- package/package.json +1 -1
package/build/config.d.ts
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/debugDeep';\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};\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","config","configure","options","defaultHidden","restOptions","configureInternal","option","resetToDefaults","getConfig"],"sources":["../src/config.ts"],"sourcesContent":["import { DebugOptions } from './helpers/debugDeep';\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 switch: 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;;AA6BA,MAAMA,aAA6B,GAAG;EACpCC,gBAAgB,EAAE,IAAI;EACtBC,4BAA4B,EAAE;AAChC,CAAC;AAED,IAAIC,MAAM,GAAG;EAAE,GAAGH;AAAc,CAAC;;AAEjC;AACA;AACA;AACO,SAASI,SAASA,CAACC,OAA6C,EAAE;EACvE,MAAM;IAAEC,aAAa;IAAE,GAAGC;EAAY,CAAC,GAAGF,OAAO;EAEjD,MAAMH,4BAA4B,GAChCK,WAAW,CAACL,4BAA4B,IACxCI,aAAa,IACbH,MAAM,CAACD,4BAA4B;EAErCC,MAAM,GAAG;IACP,GAAGA,MAAM;IACT,GAAGI,WAAW;IACdL;EACF,CAAC;AACH;AAEO,SAASM,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,GAAGH;EAAc,CAAC;AAC/B;AAEO,SAASW,SAASA,CAAA,EAAG;EAC1B,OAAOR,MAAM;AACf"}
|
package/build/fireEvent.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
-
declare
|
|
3
|
-
|
|
4
|
-
press: (element: ReactTestInstance, ...data:
|
|
5
|
-
changeText: (element: ReactTestInstance, ...data:
|
|
6
|
-
scroll: (element: ReactTestInstance, ...data:
|
|
7
|
-
}
|
|
2
|
+
declare function fireEvent(element: ReactTestInstance, eventName: string, ...data: unknown[]): undefined;
|
|
3
|
+
declare namespace fireEvent {
|
|
4
|
+
var press: (element: ReactTestInstance, ...data: unknown[]) => undefined;
|
|
5
|
+
var changeText: (element: ReactTestInstance, ...data: unknown[]) => undefined;
|
|
6
|
+
var scroll: (element: ReactTestInstance, ...data: unknown[]) => undefined;
|
|
7
|
+
}
|
|
8
8
|
export default fireEvent;
|
package/build/fireEvent.js
CHANGED
|
@@ -4,57 +4,74 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _reactNative = require("react-native");
|
|
8
7
|
var _act = _interopRequireDefault(require("./act"));
|
|
9
8
|
var _componentTree = require("./helpers/component-tree");
|
|
10
|
-
var _filterNodeByType = require("./helpers/filterNodeByType");
|
|
11
9
|
var _hostComponentNames = require("./helpers/host-component-names");
|
|
12
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
const
|
|
14
|
-
|
|
11
|
+
const isHostTextInput = element => {
|
|
12
|
+
return element?.type === (0, _hostComponentNames.getHostComponentNames)().textInput;
|
|
13
|
+
};
|
|
14
|
+
function isTouchResponder(element) {
|
|
15
|
+
if (!(0, _componentTree.isHostElement)(element)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element);
|
|
19
|
+
}
|
|
20
|
+
function isPointerEventEnabled(element, isParent) {
|
|
21
|
+
const pointerEvents = element.props.pointerEvents;
|
|
22
|
+
if (pointerEvents === 'none') {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (isParent ? pointerEvents === 'box-only' : pointerEvents === 'box-none') {
|
|
15
26
|
return false;
|
|
16
27
|
}
|
|
28
|
+
const parent = (0, _componentTree.getHostParent)(element);
|
|
29
|
+
if (!parent) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return isPointerEventEnabled(parent, true);
|
|
33
|
+
}
|
|
17
34
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
/**
|
|
36
|
+
* List of events affected by `pointerEvents` prop.
|
|
37
|
+
*
|
|
38
|
+
* Note: `fireEvent` is accepting both `press` and `onPress` for event names,
|
|
39
|
+
* so we need cover both forms.
|
|
40
|
+
*/
|
|
41
|
+
const eventsAffectedByPointerEventsProp = new Set(['press', 'onPress']);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* List of `TextInput` events not affected by `editable` prop.
|
|
45
|
+
*
|
|
46
|
+
* Note: `fireEvent` is accepting both `press` and `onPress` for event names,
|
|
47
|
+
* so we need cover both forms.
|
|
48
|
+
*/
|
|
49
|
+
const textInputEventsIgnoringEditableProp = new Set(['contentSizeChange', 'onContentSizeChange', 'layout', 'onLayout', 'scroll', 'onScroll']);
|
|
50
|
+
function isEventEnabled(element, eventName, nearestTouchResponder) {
|
|
51
|
+
if (isHostTextInput(nearestTouchResponder)) {
|
|
52
|
+
return nearestTouchResponder?.props.editable !== false || textInputEventsIgnoringEditableProp.has(eventName);
|
|
53
|
+
}
|
|
54
|
+
if (eventsAffectedByPointerEventsProp.has(eventName) && !isPointerEventEnabled(element)) {
|
|
31
55
|
return false;
|
|
32
56
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
const isEventEnabled = (element, touchResponder, eventName) => {
|
|
40
|
-
if (isTextInput(element)) return element?.props.editable !== false;
|
|
41
|
-
if (!isPointerEventEnabled(element) && isTouchEvent(eventName)) return false;
|
|
42
|
-
const touchStart = touchResponder?.props.onStartShouldSetResponder?.();
|
|
43
|
-
const touchMove = touchResponder?.props.onMoveShouldSetResponder?.();
|
|
44
|
-
if (touchStart || touchMove) return true;
|
|
57
|
+
const touchStart = nearestTouchResponder?.props.onStartShouldSetResponder?.();
|
|
58
|
+
const touchMove = nearestTouchResponder?.props.onMoveShouldSetResponder?.();
|
|
59
|
+
if (touchStart || touchMove) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
45
62
|
return touchStart === undefined && touchMove === undefined;
|
|
46
|
-
}
|
|
47
|
-
|
|
63
|
+
}
|
|
64
|
+
function findEventHandler(element, eventName, nearestTouchResponder) {
|
|
48
65
|
const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder;
|
|
49
66
|
const handler = getEventHandler(element, eventName);
|
|
50
|
-
if (handler && isEventEnabled(element,
|
|
67
|
+
if (handler && isEventEnabled(element, eventName, touchResponder)) return handler;
|
|
51
68
|
if (element.parent === null || element.parent.parent === null) {
|
|
52
69
|
return null;
|
|
53
70
|
}
|
|
54
|
-
return findEventHandler(element.parent, eventName,
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const eventHandlerName =
|
|
71
|
+
return findEventHandler(element.parent, eventName, touchResponder);
|
|
72
|
+
}
|
|
73
|
+
function getEventHandler(element, eventName) {
|
|
74
|
+
const eventHandlerName = getEventHandlerName(eventName);
|
|
58
75
|
if (typeof element.props[eventHandlerName] === 'function') {
|
|
59
76
|
return element.props[eventHandlerName];
|
|
60
77
|
}
|
|
@@ -62,9 +79,12 @@ const getEventHandler = (element, eventName) => {
|
|
|
62
79
|
return element.props[eventName];
|
|
63
80
|
}
|
|
64
81
|
return undefined;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
82
|
+
}
|
|
83
|
+
function getEventHandlerName(eventName) {
|
|
84
|
+
return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;
|
|
85
|
+
}
|
|
86
|
+
function fireEvent(element, eventName, ...data) {
|
|
87
|
+
const handler = findEventHandler(element, eventName);
|
|
68
88
|
if (!handler) {
|
|
69
89
|
return;
|
|
70
90
|
}
|
|
@@ -73,15 +93,10 @@ const invokeEvent = (element, eventName, callsite, ...data) => {
|
|
|
73
93
|
returnValue = handler(...data);
|
|
74
94
|
});
|
|
75
95
|
return returnValue;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const scrollHandler = (element, ...data) => invokeEvent(element, 'scroll', scrollHandler, ...data);
|
|
81
|
-
const fireEvent = (element, eventName, ...data) => invokeEvent(element, eventName, fireEvent, ...data);
|
|
82
|
-
fireEvent.press = pressHandler;
|
|
83
|
-
fireEvent.changeText = changeTextHandler;
|
|
84
|
-
fireEvent.scroll = scrollHandler;
|
|
96
|
+
}
|
|
97
|
+
fireEvent.press = (element, ...data) => fireEvent(element, 'press', ...data);
|
|
98
|
+
fireEvent.changeText = (element, ...data) => fireEvent(element, 'changeText', ...data);
|
|
99
|
+
fireEvent.scroll = (element, ...data) => fireEvent(element, 'scroll', ...data);
|
|
85
100
|
var _default = fireEvent;
|
|
86
101
|
exports.default = _default;
|
|
87
102
|
//# sourceMappingURL=fireEvent.js.map
|
package/build/fireEvent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fireEvent.js","names":["
|
|
1
|
+
{"version":3,"file":"fireEvent.js","names":["_act","_interopRequireDefault","require","_componentTree","_hostComponentNames","obj","__esModule","default","isHostTextInput","element","type","getHostComponentNames","textInput","isTouchResponder","isHostElement","Boolean","props","onStartShouldSetResponder","isPointerEventEnabled","isParent","pointerEvents","parent","getHostParent","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","editable","has","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandler","eventHandlerName","getEventHandlerName","charAt","toUpperCase","slice","fireEvent","data","returnValue","act","press","changeText","scroll","_default","exports"],"sources":["../src/fireEvent.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport act from './act';\nimport { getHostParent, isHostElement } from './helpers/component-tree';\nimport { getHostComponentNames } from './helpers/host-component-names';\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nconst isHostTextInput = (element?: ReactTestInstance) => {\n return element?.type === getHostComponentNames().textInput;\n};\n\nfunction isTouchResponder(element: ReactTestInstance) {\n if (!isHostElement(element)) {\n return false;\n }\n\n return (\n Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element)\n );\n}\n\nfunction isPointerEventEnabled(\n element: ReactTestInstance,\n isParent?: boolean\n): boolean {\n const pointerEvents = element.props.pointerEvents;\n if (pointerEvents === 'none') {\n return false;\n }\n\n if (isParent ? pointerEvents === 'box-only' : pointerEvents === 'box-none') {\n return false;\n }\n\n const parent = getHostParent(element);\n if (!parent) {\n return true;\n }\n\n return isPointerEventEnabled(parent, true);\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\nfunction isEventEnabled(\n element: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance\n) {\n if (isHostTextInput(nearestTouchResponder)) {\n return (\n nearestTouchResponder?.props.editable !== false ||\n textInputEventsIgnoringEditableProp.has(eventName)\n );\n }\n\n if (\n eventsAffectedByPointerEventsProp.has(eventName) &&\n !isPointerEventEnabled(element)\n ) {\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)\n ? element\n : nearestTouchResponder;\n\n const handler = getEventHandler(element, eventName);\n if (handler && isEventEnabled(element, eventName, touchResponder))\n return handler;\n\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\nfunction fireEvent(\n element: ReactTestInstance,\n eventName: string,\n ...data: unknown[]\n) {\n const handler = findEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n let returnValue;\n 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"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAAuE,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAIvE,MAAMG,eAAe,GAAIC,OAA2B,IAAK;EACvD,OAAOA,OAAO,EAAEC,IAAI,KAAK,IA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KAAK,UAAU,EAAE;IAClD,OAAOlB,OAAO,CAACO,KAAK,CAACW,SAAS,CAAC;EACjC;EAEA,OAAOO,SAAS;AAClB;AAEA,SAASM,mBAAmBA,CAACb,SAAiB,EAAE;EAC9C,OAAQ,KAAIA,SAAS,CAACc,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,EAAG,GAAEf,SAAS,CAACgB,KAAK,CAAC,CAAC,CAAE,EAAC;AACtE;AAEA,SAASC,SAASA,CAChBnC,OAA0B,EAC1BkB,SAAiB,EACjB,GAAGkB,IAAe,EAClB;EACA,MAAMR,OAAO,GAAGF,gBAAgB,CAAC1B,OAAO,EAAEkB,SAAS,CAAC;EACpD,IAAI,CAACU,OAAO,EAAE;IACZ;EACF;EAEA,IAAIS,WAAW;EACf,IAAAC,YAAG,EAAC,MAAM;IACRD,WAAW,GAAGT,OAAO,CAAC,GAAGQ,IAAI,CAAC;EAChC,CAAC,CAAC;EAEF,OAAOC,WAAW;AACpB;AAEAF,SAAS,CAACI,KAAK,GAAG,CAACvC,OAA0B,EAAE,GAAGoC,IAAe,KAC/DD,SAAS,CAACnC,OAAO,EAAE,OAAO,EAAE,GAAGoC,IAAI,CAAC;AAEtCD,SAAS,CAACK,UAAU,GAAG,CAACxC,OAA0B,EAAE,GAAGoC,IAAe,KACpED,SAAS,CAACnC,OAAO,EAAE,YAAY,EAAE,GAAGoC,IAAI,CAAC;AAE3CD,SAAS,CAACM,MAAM,GAAG,CAACzC,OAA0B,EAAE,GAAGoC,IAAe,KAChED,SAAS,CAACnC,OAAO,EAAE,QAAQ,EAAE,GAAGoC,IAAI,CAAC;AAAC,IAAAM,QAAA,GAEzBP,SAAS;AAAAQ,OAAA,CAAA7C,OAAA,GAAA4C,QAAA"}
|
|
@@ -8,6 +8,7 @@ exports.isAccessibilityElement = isAccessibilityElement;
|
|
|
8
8
|
exports.isHiddenFromAccessibility = isHiddenFromAccessibility;
|
|
9
9
|
exports.isInaccessible = void 0;
|
|
10
10
|
var _reactNative = require("react-native");
|
|
11
|
+
var _config = require("../config");
|
|
11
12
|
var _componentTree = require("./component-tree");
|
|
12
13
|
const accessibilityStateKeys = ['disabled', 'selected', 'checked', 'busy', 'expanded'];
|
|
13
14
|
exports.accessibilityStateKeys = accessibilityStateKeys;
|
|
@@ -74,6 +75,7 @@ function isAccessibilityElement(element) {
|
|
|
74
75
|
if (element.props.accessible !== undefined) {
|
|
75
76
|
return element.props.accessible;
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
+
const hostComponentNames = (0, _config.getConfig)().hostComponentNames;
|
|
79
|
+
return element?.type === hostComponentNames?.text || element?.type === hostComponentNames?.textInput || element?.type === hostComponentNames?.switch;
|
|
78
80
|
}
|
|
79
81
|
//# sourceMappingURL=accessiblity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accessiblity.js","names":["_reactNative","require","_componentTree","accessibilityStateKeys","exports","accessiblityValueKeys","isHiddenFromAccessibility","element","cache","current","isCurrentSubtreeInaccessible","get","undefined","isSubtreeInaccessible","set","parent","isInaccessible","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","accessibilityViewIsModal","isAccessibilityElement","accessible","
|
|
1
|
+
{"version":3,"file":"accessiblity.js","names":["_reactNative","require","_config","_componentTree","accessibilityStateKeys","exports","accessiblityValueKeys","isHiddenFromAccessibility","element","cache","current","isCurrentSubtreeInaccessible","get","undefined","isSubtreeInaccessible","set","parent","isInaccessible","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","accessibilityViewIsModal","isAccessibilityElement","accessible","hostComponentNames","getConfig","type","text","textInput","switch"],"sources":["../../src/helpers/accessiblity.ts"],"sourcesContent":["import {\n AccessibilityState,\n AccessibilityValue,\n StyleSheet,\n} from 'react-native';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { getConfig } from '../config';\nimport { getHostSiblings } from './component-tree';\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 accessiblityValueKeys: (keyof AccessibilityValue)[] = [\n 'min',\n 'max',\n 'now',\n 'text',\n];\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-compatitibility 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 // 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\n // See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios\n const hostSiblings = getHostSiblings(element);\n if (hostSiblings.some((sibling) => sibling.props.accessibilityViewIsModal)) {\n return true;\n }\n\n return false;\n}\n\nexport function isAccessibilityElement(\n element: ReactTestInstance | null\n): boolean {\n if (element == null) {\n return false;\n }\n\n if (element.props.accessible !== undefined) {\n return element.props.accessible;\n }\n\n const hostComponentNames = getConfig().hostComponentNames;\n\n return (\n element?.type === hostComponentNames?.text ||\n element?.type === hostComponentNames?.textInput ||\n element?.type === hostComponentNames?.switch\n );\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAMA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAMO,MAAMG,sBAAoD,GAAG,CAClE,UAAU,EACV,UAAU,EACV,SAAS,EACT,MAAM,EACN,UAAU,CACX;AAACC,OAAA,CAAAD,sBAAA,GAAAA,sBAAA;AAEK,MAAME,qBAAmD,GAAG,CACjE,KAAK,EACL,KAAK,EACL,KAAK,EACL,MAAM,CACP;AAACD,OAAA,CAAAC,qBAAA,GAAAA,qBAAA;AAEK,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,GAAGV,yBAAyB;AAACF,OAAA,CAAAY,cAAA,GAAAA,cAAA;AAExD,SAASH,qBAAqBA,CAACN,OAA0B,EAAW;EAClE;EACA,IAAIA,OAAO,CAACU,KAAK,IAAI,IAAI,EAAE;IACzB,OAAO,KAAK;EACd;;EAEA;EACA;EACA,IAAIV,OAAO,CAACU,KAAK,CAACC,2BAA2B,EAAE;IAC7C,OAAO,IAAI;EACb;;EAEA;EACA;EACA,IAAIX,OAAO,CAACU,KAAK,CAACE,yBAAyB,KAAK,qBAAqB,EAAE;IACrE,OAAO,IAAI;EACb;;EAEA;EACA,MAAMC,SAAS,GAAGC,uBAAU,CAACC,OAAO,CAACf,OAAO,CAACU,KAAK,CAACM,KAAK,CAAC,IAAI,CAAC,CAAC;EAC/D,IAAIH,SAAS,CAACI,OAAO,KAAK,MAAM,EAAE,OAAO,IAAI;;EAE7C;EACA;EACA,MAAMC,YAAY,GAAG,IAAAC,8BAAe,EAACnB,OAAO,CAAC;EAC7C,IAAIkB,YAAY,CAACE,IAAI,CAAEC,OAAO,IAAKA,OAAO,CAACX,KAAK,CAACY,wBAAwB,CAAC,EAAE;IAC1E,OAAO,IAAI;EACb;EAEA,OAAO,KAAK;AACd;AAEO,SAASC,sBAAsBA,CACpCvB,OAAiC,EACxB;EACT,IAAIA,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,KAAK;EACd;EAEA,IAAIA,OAAO,CAACU,KAAK,CAACc,UAAU,KAAKnB,SAAS,EAAE;IAC1C,OAAOL,OAAO,CAACU,KAAK,CAACc,UAAU;EACjC;EAEA,MAAMC,kBAAkB,GAAG,IAAAC,iBAAS,GAAE,CAACD,kBAAkB;EAEzD,OACEzB,OAAO,EAAE2B,IAAI,KAAKF,kBAAkB,EAAEG,IAAI,IAC1C5B,OAAO,EAAE2B,IAAI,KAAKF,kBAAkB,EAAEI,SAAS,IAC/C7B,OAAO,EAAE2B,IAAI,KAAKF,kBAAkB,EAAEK,MAAM;AAEhD"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { ReactTestInstance } from 'react-test-renderer';
|
|
3
2
|
/**
|
|
4
3
|
* Checks if the given element is a host element.
|
|
@@ -15,15 +14,6 @@ export declare function getHostParent(element: ReactTestInstance | null): ReactT
|
|
|
15
14
|
* @param element The element start traversing from.
|
|
16
15
|
*/
|
|
17
16
|
export declare function getHostChildren(element: ReactTestInstance | null): ReactTestInstance[];
|
|
18
|
-
/**
|
|
19
|
-
* Return a single host element that represent the passed host or composite element.
|
|
20
|
-
*
|
|
21
|
-
* @param element The element start traversing from.
|
|
22
|
-
* @throws Error if the passed element is a composite element and has no host children or has more than one host child.
|
|
23
|
-
* @returns If the passed element is a host element, it will return itself, if the passed element is a composite
|
|
24
|
-
* element, it will return a single host descendant.
|
|
25
|
-
*/
|
|
26
|
-
export declare function getHostSelf(element: ReactTestInstance | null): ReactTestInstance;
|
|
27
17
|
/**
|
|
28
18
|
* Return the array of host elements that represent the passed element.
|
|
29
19
|
*
|
|
@@ -37,8 +27,3 @@ export declare function getHostSelves(element: ReactTestInstance | null): ReactT
|
|
|
37
27
|
* @param element The element start traversing from.
|
|
38
28
|
*/
|
|
39
29
|
export declare function getHostSiblings(element: ReactTestInstance | null): ReactTestInstance[];
|
|
40
|
-
export declare function getCompositeParentOfType(element: ReactTestInstance, type: React.ComponentType): ReactTestInstance | null;
|
|
41
|
-
/**
|
|
42
|
-
* Note: this function should be generally used for core React Native types like `View`, `Text`, `TextInput`, etc.
|
|
43
|
-
*/
|
|
44
|
-
export declare function isHostElementForType(element: ReactTestInstance, type: React.ComponentType): boolean;
|
|
@@ -3,14 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getCompositeParentOfType = getCompositeParentOfType;
|
|
7
6
|
exports.getHostChildren = getHostChildren;
|
|
8
7
|
exports.getHostParent = getHostParent;
|
|
9
|
-
exports.getHostSelf = getHostSelf;
|
|
10
8
|
exports.getHostSelves = getHostSelves;
|
|
11
9
|
exports.getHostSiblings = getHostSiblings;
|
|
12
10
|
exports.isHostElement = isHostElement;
|
|
13
|
-
exports.isHostElementForType = isHostElementForType;
|
|
14
11
|
/**
|
|
15
12
|
* Checks if the given element is a host element.
|
|
16
13
|
* @param element The element to check.
|
|
@@ -59,25 +56,6 @@ function getHostChildren(element) {
|
|
|
59
56
|
return hostChildren;
|
|
60
57
|
}
|
|
61
58
|
|
|
62
|
-
/**
|
|
63
|
-
* Return a single host element that represent the passed host or composite element.
|
|
64
|
-
*
|
|
65
|
-
* @param element The element start traversing from.
|
|
66
|
-
* @throws Error if the passed element is a composite element and has no host children or has more than one host child.
|
|
67
|
-
* @returns If the passed element is a host element, it will return itself, if the passed element is a composite
|
|
68
|
-
* element, it will return a single host descendant.
|
|
69
|
-
*/
|
|
70
|
-
function getHostSelf(element) {
|
|
71
|
-
const hostSelves = getHostSelves(element);
|
|
72
|
-
if (hostSelves.length === 0) {
|
|
73
|
-
throw new Error(`Expected exactly one host element, but found none.`);
|
|
74
|
-
}
|
|
75
|
-
if (hostSelves.length > 1) {
|
|
76
|
-
throw new Error(`Expected exactly one host element, but found ${hostSelves.length}.`);
|
|
77
|
-
}
|
|
78
|
-
return hostSelves[0];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
59
|
/**
|
|
82
60
|
* Return the array of host elements that represent the passed element.
|
|
83
61
|
*
|
|
@@ -98,27 +76,4 @@ function getHostSiblings(element) {
|
|
|
98
76
|
const hostSelves = getHostSelves(element);
|
|
99
77
|
return getHostChildren(hostParent).filter(sibling => !hostSelves.includes(sibling));
|
|
100
78
|
}
|
|
101
|
-
function getCompositeParentOfType(element, type) {
|
|
102
|
-
let current = element.parent;
|
|
103
|
-
while (!isHostElement(current)) {
|
|
104
|
-
// We're at the root of the tree
|
|
105
|
-
if (!current) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
if (current.type === type) {
|
|
109
|
-
return current;
|
|
110
|
-
}
|
|
111
|
-
current = current.parent;
|
|
112
|
-
}
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Note: this function should be generally used for core React Native types like `View`, `Text`, `TextInput`, etc.
|
|
118
|
-
*/
|
|
119
|
-
function isHostElementForType(element, type) {
|
|
120
|
-
// Not a host element
|
|
121
|
-
if (!isHostElement(element)) return false;
|
|
122
|
-
return getCompositeParentOfType(element, type) !== null;
|
|
123
|
-
}
|
|
124
79
|
//# sourceMappingURL=component-tree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-tree.js","names":["isHostElement","element","type","getHostParent","current","parent","getHostChildren","hostChildren","children","forEach","child","push","
|
|
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"],"sources":["../../src/helpers/component-tree.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\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) {\n return typeof element?.type === 'string';\n}\n\n/**\n * Returns first host ancestor for given element.\n * @param element The element start traversing from.\n */\nexport function getHostParent(\n element: ReactTestInstance | null\n): ReactTestInstance | 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(\n element: ReactTestInstance | null\n): ReactTestInstance[] {\n if (element == null) {\n return [];\n }\n\n const hostChildren: ReactTestInstance[] = [];\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(\n element: ReactTestInstance | null\n): ReactTestInstance[] {\n return typeof element?.type === 'string'\n ? [element]\n : getHostChildren(element);\n}\n\n/**\n * Returns host siblings for given element.\n * @param element The element start traversing from.\n */\nexport function getHostSiblings(\n element: ReactTestInstance | null\n): ReactTestInstance[] {\n const hostParent = getHostParent(element);\n const hostSelves = getHostSelves(element);\n return getHostChildren(hostParent).filter(\n (sibling) => !hostSelves.includes(sibling)\n );\n}\n"],"mappings":";;;;;;;;;;AAEA;AACA;AACA;AACA;AACO,SAASA,aAAaA,CAACC,OAAkC,EAAE;EAChE,OAAO,OAAOA,OAAO,EAAEC,IAAI,KAAK,QAAQ;AAC1C;;AAEA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAC3BF,OAAiC,EACP;EAC1B,IAAIA,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIG,OAAO,GAAGH,OAAO,CAACI,MAAM;EAC5B,OAAOD,OAAO,EAAE;IACd,IAAIJ,aAAa,CAACI,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,CAC7BL,OAAiC,EACZ;EACrB,IAAIA,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,EAAE;EACX;EAEA,MAAMM,YAAiC,GAAG,EAAE;EAE5CN,OAAO,CAACO,QAAQ,CAACC,OAAO,CAAEC,KAAK,IAAK;IAClC,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7B;IACF;IAEA,IAAIV,aAAa,CAACU,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,CAC3BX,OAAiC,EACZ;EACrB,OAAO,OAAOA,OAAO,EAAEC,IAAI,KAAK,QAAQ,GACpC,CAACD,OAAO,CAAC,GACTK,eAAe,CAACL,OAAO,CAAC;AAC9B;;AAEA;AACA;AACA;AACA;AACO,SAASY,eAAeA,CAC7BZ,OAAiC,EACZ;EACrB,MAAMa,UAAU,GAAGX,aAAa,CAACF,OAAO,CAAC;EACzC,MAAMc,UAAU,GAAGH,aAAa,CAACX,OAAO,CAAC;EACzC,OAAOK,eAAe,CAACQ,UAAU,CAAC,CAACE,MAAM,CACtCC,OAAO,IAAK,CAACF,UAAU,CAACG,QAAQ,CAACD,OAAO,CAAC,CAC3C;AACH"}
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.deprecateQueries = deprecateQueries;
|
|
7
|
+
exports.printDeprecationWarning = printDeprecationWarning;
|
|
7
8
|
var _queryName = require("./query-name");
|
|
8
9
|
function deprecateQueries(queriesObject, recommendation) {
|
|
9
10
|
const result = {};
|
|
@@ -26,4 +27,19 @@ function deprecateQuery(queryFn, queryName, recommendation) {
|
|
|
26
27
|
};
|
|
27
28
|
return wrapper;
|
|
28
29
|
}
|
|
30
|
+
const warned = {};
|
|
31
|
+
|
|
32
|
+
// istambul ignore next: Occasionally used
|
|
33
|
+
function printDeprecationWarning(functionName) {
|
|
34
|
+
if (warned[functionName]) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
39
|
+
console.warn(`
|
|
40
|
+
Deprecation Warning:
|
|
41
|
+
Use of ${functionName} is not recommended and will be deleted in future versions of @testing-library/react-native.
|
|
42
|
+
`);
|
|
43
|
+
warned[functionName] = true;
|
|
44
|
+
}
|
|
29
45
|
//# sourceMappingURL=deprecation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deprecation.js","names":["_queryName","require","deprecateQueries","queriesObject","recommendation","result","Object","keys","forEach","queryName","queryFn","deprecateQuery","formattedRecommendation","replace","getQueryPrefix","wrapper","args","errorMessage","console","warn"],"sources":["../../src/helpers/deprecation.ts"],"sourcesContent":["import { getQueryPrefix } from './query-name';\n\nexport function deprecateQueries<Queries extends Record<string, any>>(\n queriesObject: Queries,\n recommendation: string\n): Queries {\n const result = {} as Queries;\n Object.keys(queriesObject).forEach((queryName) => {\n const queryFn = queriesObject[queryName];\n // @ts-expect-error: generic typing is hard\n result[queryName] = deprecateQuery(queryFn, queryName, recommendation);\n });\n\n return result;\n}\n\nfunction deprecateQuery<QueryFn extends (...args: any) => any>(\n queryFn: QueryFn,\n queryName: string,\n recommendation: string\n): QueryFn {\n const formattedRecommendation = recommendation.replace(\n /{queryPrefix}/g,\n getQueryPrefix(queryName)\n );\n\n // @ts-expect-error: generic typing is hard\n const wrapper: QueryFn = (...args: any) => {\n const errorMessage = `${queryName}(...) is deprecated and will be removed in the future.\\n\\n${formattedRecommendation}`;\n // eslint-disable-next-line no-console\n console.warn(errorMessage);\n return queryFn(...args);\n };\n\n return wrapper;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"deprecation.js","names":["_queryName","require","deprecateQueries","queriesObject","recommendation","result","Object","keys","forEach","queryName","queryFn","deprecateQuery","formattedRecommendation","replace","getQueryPrefix","wrapper","args","errorMessage","console","warn","warned","printDeprecationWarning","functionName"],"sources":["../../src/helpers/deprecation.ts"],"sourcesContent":["import { getQueryPrefix } from './query-name';\n\nexport function deprecateQueries<Queries extends Record<string, any>>(\n queriesObject: Queries,\n recommendation: string\n): Queries {\n const result = {} as Queries;\n Object.keys(queriesObject).forEach((queryName) => {\n const queryFn = queriesObject[queryName];\n // @ts-expect-error: generic typing is hard\n result[queryName] = deprecateQuery(queryFn, queryName, recommendation);\n });\n\n return result;\n}\n\nfunction deprecateQuery<QueryFn extends (...args: any) => any>(\n queryFn: QueryFn,\n queryName: string,\n recommendation: string\n): QueryFn {\n const formattedRecommendation = recommendation.replace(\n /{queryPrefix}/g,\n getQueryPrefix(queryName)\n );\n\n // @ts-expect-error: generic typing is hard\n const wrapper: QueryFn = (...args: any) => {\n const errorMessage = `${queryName}(...) is deprecated and will be removed in the future.\\n\\n${formattedRecommendation}`;\n // eslint-disable-next-line no-console\n console.warn(errorMessage);\n return queryFn(...args);\n };\n\n return wrapper;\n}\n\nconst warned: { [functionName: string]: boolean } = {};\n\n// istambul ignore next: Occasionally used\nexport function printDeprecationWarning(functionName: string) {\n if (warned[functionName]) {\n return;\n }\n\n // eslint-disable-next-line no-console\n console.warn(`\n Deprecation Warning:\n Use of ${functionName} is not recommended and will be deleted in future versions of @testing-library/react-native.\n `);\n\n warned[functionName] = true;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAEO,SAASC,gBAAgBA,CAC9BC,aAAsB,EACtBC,cAAsB,EACb;EACT,MAAMC,MAAM,GAAG,CAAC,CAAY;EAC5BC,MAAM,CAACC,IAAI,CAACJ,aAAa,CAAC,CAACK,OAAO,CAAEC,SAAS,IAAK;IAChD,MAAMC,OAAO,GAAGP,aAAa,CAACM,SAAS,CAAC;IACxC;IACAJ,MAAM,CAACI,SAAS,CAAC,GAAGE,cAAc,CAACD,OAAO,EAAED,SAAS,EAAEL,cAAc,CAAC;EACxE,CAAC,CAAC;EAEF,OAAOC,MAAM;AACf;AAEA,SAASM,cAAcA,CACrBD,OAAgB,EAChBD,SAAiB,EACjBL,cAAsB,EACb;EACT,MAAMQ,uBAAuB,GAAGR,cAAc,CAACS,OAAO,CACpD,gBAAgB,EAChB,IAAAC,yBAAc,EAACL,SAAS,CAAC,CAC1B;;EAED;EACA,MAAMM,OAAgB,GAAGA,CAAC,GAAGC,IAAS,KAAK;IACzC,MAAMC,YAAY,GAAI,GAAER,SAAU,6DAA4DG,uBAAwB,EAAC;IACvH;IACAM,OAAO,CAACC,IAAI,CAACF,YAAY,CAAC;IAC1B,OAAOP,OAAO,CAAC,GAAGM,IAAI,CAAC;EACzB,CAAC;EAED,OAAOD,OAAO;AAChB;AAEA,MAAMK,MAA2C,GAAG,CAAC,CAAC;;AAEtD;AACO,SAASC,uBAAuBA,CAACC,YAAoB,EAAE;EAC5D,IAAIF,MAAM,CAACE,YAAY,CAAC,EAAE;IACxB;EACF;;EAEA;EACAJ,OAAO,CAACC,IAAI,CAAE;AAChB;AACA,WAAWG,YAAa;AACxB,GAAG,CAAC;EAEFF,MAAM,CAACE,YAAY,CAAC,GAAG,IAAI;AAC7B"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
export declare class ErrorWithStack extends Error {
|
|
2
2
|
constructor(message: string | undefined, callsite: Function);
|
|
3
3
|
}
|
|
4
|
-
export declare const createLibraryNotSupportedError: (error: unknown) => Error;
|
|
5
4
|
export declare const prepareErrorMessage: (error: unknown, name?: string, value?: unknown) => string;
|
|
6
5
|
export declare const createQueryByError: (error: unknown, callsite: Function) => null;
|
|
7
6
|
export declare function copyStackTrace(target: unknown, stackTraceSource: Error): void;
|
|
8
|
-
export declare function printDeprecationWarning(functionName: string): void;
|
|
9
|
-
export declare function throwRemovedFunctionError(functionName: string, docsRef: string): void;
|
|
10
|
-
export declare function throwRenamedFunctionError(functionName: string, newFunctionName: string): void;
|
package/build/helpers/errors.js
CHANGED
|
@@ -5,10 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ErrorWithStack = void 0;
|
|
7
7
|
exports.copyStackTrace = copyStackTrace;
|
|
8
|
-
exports.prepareErrorMessage = exports.createQueryByError =
|
|
9
|
-
exports.printDeprecationWarning = printDeprecationWarning;
|
|
10
|
-
exports.throwRemovedFunctionError = throwRemovedFunctionError;
|
|
11
|
-
exports.throwRenamedFunctionError = throwRenamedFunctionError;
|
|
8
|
+
exports.prepareErrorMessage = exports.createQueryByError = void 0;
|
|
12
9
|
var _prettyFormat = _interopRequireDefault(require("pretty-format"));
|
|
13
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
11
|
class ErrorWithStack extends Error {
|
|
@@ -20,8 +17,6 @@ class ErrorWithStack extends Error {
|
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
19
|
exports.ErrorWithStack = ErrorWithStack;
|
|
23
|
-
const createLibraryNotSupportedError = error => new Error(`Currently the only supported library to search by text is "react-native".\n\n${error instanceof Error ? error.message : ''}`);
|
|
24
|
-
exports.createLibraryNotSupportedError = createLibraryNotSupportedError;
|
|
25
20
|
const prepareErrorMessage = (error, name, value) => {
|
|
26
21
|
let errorMessage;
|
|
27
22
|
if (error instanceof Error) {
|
|
@@ -58,23 +53,4 @@ function copyStackTrace(target, stackTraceSource) {
|
|
|
58
53
|
target.stack = stackTraceSource.stack.replace(stackTraceSource.message, target.message);
|
|
59
54
|
}
|
|
60
55
|
}
|
|
61
|
-
const warned = {};
|
|
62
|
-
function printDeprecationWarning(functionName) {
|
|
63
|
-
if (warned[functionName]) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// eslint-disable-next-line no-console
|
|
68
|
-
console.warn(`
|
|
69
|
-
Deprecation Warning:
|
|
70
|
-
Use of ${functionName} is not recommended and will be deleted in future versions of @testing-library/react-native.
|
|
71
|
-
`);
|
|
72
|
-
warned[functionName] = true;
|
|
73
|
-
}
|
|
74
|
-
function throwRemovedFunctionError(functionName, docsRef) {
|
|
75
|
-
throw new Error(`"${functionName}" has been removed.\n\nPlease consult: https://callstack.github.io/react-native-testing-library/docs/${docsRef}`);
|
|
76
|
-
}
|
|
77
|
-
function throwRenamedFunctionError(functionName, newFunctionName) {
|
|
78
|
-
throw new ErrorWithStack(`The "${functionName}" function has been renamed to "${newFunctionName}". Please replace all occurrences.`, throwRenamedFunctionError);
|
|
79
|
-
}
|
|
80
56
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":["_prettyFormat","_interopRequireDefault","require","obj","__esModule","default","ErrorWithStack","Error","constructor","message","callsite","captureStackTrace","exports","
|
|
1
|
+
{"version":3,"file":"errors.js","names":["_prettyFormat","_interopRequireDefault","require","obj","__esModule","default","ErrorWithStack","Error","constructor","message","callsite","captureStackTrace","exports","prepareErrorMessage","error","name","value","errorMessage","replace","toString","prettyFormat","min","createQueryByError","includes","copyStackTrace","target","stackTraceSource","stack"],"sources":["../../src/helpers/errors.ts"],"sourcesContent":["import prettyFormat from 'pretty-format';\n\nexport class ErrorWithStack extends Error {\n constructor(message: string | undefined, callsite: Function) {\n super(message);\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, callsite);\n }\n }\n}\n\nexport const prepareErrorMessage = (\n // TS states that error caught in a catch close are of type `unknown`\n // most real cases will be `Error`, but better safe than sorry\n error: unknown,\n name?: string,\n value?: unknown\n): string => {\n let errorMessage: string;\n if (error instanceof Error) {\n // Strip info about custom predicate\n errorMessage = error.message.replace(\n / matching custom predicate[^]*/gm,\n ''\n );\n } else if (error && typeof error === 'object') {\n errorMessage = error.toString();\n } else {\n errorMessage = 'Caught unknown error';\n }\n\n if (name && value) {\n errorMessage += ` with ${name} ${prettyFormat(value, { min: true })}`;\n }\n return errorMessage;\n};\n\nexport const createQueryByError = (\n error: unknown,\n callsite: Function\n): null => {\n if (error instanceof Error) {\n if (error.message.includes('No instances found')) {\n return null;\n }\n throw new ErrorWithStack(error.message, callsite);\n }\n\n throw new ErrorWithStack(\n // generic refining of `unknown` is very hard, you cannot do `'toString' in error` or anything like that\n // Converting as any with extra safe optional chaining will do the job just as well\n `Query: caught unknown error type: ${typeof error}, value: ${(\n error as any\n )?.toString?.()}`,\n callsite\n );\n};\n\nexport function copyStackTrace(target: unknown, stackTraceSource: Error) {\n if (target instanceof Error && stackTraceSource.stack) {\n target.stack = stackTraceSource.stack.replace(\n stackTraceSource.message,\n target.message\n );\n }\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AAE;MAChD,OAAO,IAAI;IACb;IACA,MAAM,IAAIjB,cAAc,CAACQ,KAAK,CAACL,OAAO,EAAEC,QAAQ,CAAC;EACnD;EAEA,MAAM,IAAIJ,cAAc;EACtB;EACA;EACC,qCAAoC,OAAOQ,KAAM,YAChDA,KAAK,EACJK,QAAQ,IAAK,EAAC,EACjBT,QAAQ,CACT;AACH,CAAC;AAACE,OAAA,CAAAU,kBAAA,GAAAA,kBAAA;AAEK,SAASE,cAAcA,CAACC,MAAe,EAAEC,gBAAuB,EAAE;EACvE,IAAID,MAAM,YAAYlB,KAAK,IAAImB,gBAAgB,CAACC,KAAK,EAAE;IACrDF,MAAM,CAACE,KAAK,GAAGD,gBAAgB,CAACC,KAAK,CAACT,OAAO,CAC3CQ,gBAAgB,CAACjB,OAAO,EACxBgB,MAAM,CAAChB,OAAO,CACf;EACH;AACF"}
|
|
@@ -39,10 +39,13 @@ function detectHostComponentNames() {
|
|
|
39
39
|
testID: "text"
|
|
40
40
|
}, "Hello"), /*#__PURE__*/React.createElement(_reactNative.TextInput, {
|
|
41
41
|
testID: "textInput"
|
|
42
|
+
}), /*#__PURE__*/React.createElement(_reactNative.Switch, {
|
|
43
|
+
testID: "switch"
|
|
42
44
|
})));
|
|
43
45
|
return {
|
|
44
46
|
text: getByTestId(renderer.root, 'text').type,
|
|
45
|
-
textInput: getByTestId(renderer.root, 'textInput').type
|
|
47
|
+
textInput: getByTestId(renderer.root, 'textInput').type,
|
|
48
|
+
switch: getByTestId(renderer.root, 'switch').type
|
|
46
49
|
};
|
|
47
50
|
} catch (error) {
|
|
48
51
|
const errorMessage = error && typeof error === 'object' && 'message' in error ? error.message : null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-component-names.js","names":["React","_interopRequireWildcard","require","_reactNative","_config","_renderAct","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","userConfigErrorMessage","getHostComponentNames","hostComponentNames","getConfig","detectHostComponentNames","configureInternal","configureHostComponentNamesIfNeeded","configHostComponentNames","renderer","renderWithAct","createElement","View","Text","testID","TextInput","text","getByTestId","root","type","textInput","error","errorMessage","message","Error","instance","nodes","findAll","node","props","length"],"sources":["../../src/helpers/host-component-names.tsx"],"sourcesContent":["import * as React from 'react';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { Text, TextInput, View } from 'react-native';\nimport { configureInternal, getConfig, HostComponentNames } from '../config';\nimport { renderWithAct } from '../render-act';\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 </View>\n );\n\n return {\n text: getByTestId(renderer.root, 'text').type as string,\n textInput: getByTestId(renderer.root, 'textInput').type as string,\n };\n } catch (error) {\n const errorMessage =\n error && typeof error === 'object' && 'message' in error\n ? error.message\n : 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: ${test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GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA;AAE9C,MAAMW,sBAAsB,GAAI;AAChC,oGAAoG;AAE7F,SAASC,qBAAqBA,CAAA,EAAuB;EAC1D,IAAIC,kBAAkB,GAAG,IAAAC,iBAAS,GAAE,CAACD,kBAAkB;EACvD,IAAI,CAACA,kBAAkB,EAAE;IACvBA,kBAAkB,GAAGE,wBAAwB,EAAE;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,GAAE,CAACD,kBAAkB;EAC/D,IAAIK,wBAAwB,EAAE;IAC5B;EACF;EAEA,MAAML,kBAAkB,GAAGE,wBAAwB,EAAE;EACrD,IAAAC,yBAAiB,EAAC;IAAEH;EAAmB,CAAC,CAAC;AAC3C;AAEA,SAASE,wBAAwBA,CAAA,EAAuB;EACtD,IAAI;IACF,MAAMI,QAAQ,GAAG,IAAAC,wBAAa,gBAC5BrC,KAAA,CAAAsC,aAAA,CAACnC,YAAA,CAAAoC,IAAI,qBACHvC,KAAA,CAAAsC,aAAA,CAACnC,YAAA,CAAAqC,IAAI;MAACC,MAAM,EAAC;IAAM,GAAC,OAAK,CAAO,eAChCzC,KAAA,CAAAsC,aAAA,CAACnC,YAAA,CAAAuC,SAAS;MAACD,MAAM,EAAC;IAAW,EAAG,
|
|
1
|
+
{"version":3,"file":"host-component-names.js","names":["React","_interopRequireWildcard","require","_reactNative","_config","_renderAct","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","userConfigErrorMessage","getHostComponentNames","hostComponentNames","getConfig","detectHostComponentNames","configureInternal","configureHostComponentNamesIfNeeded","configHostComponentNames","renderer","renderWithAct","createElement","View","Text","testID","TextInput","Switch","text","getByTestId","root","type","textInput","switch","error","errorMessage","message","Error","instance","nodes","findAll","node","props","length"],"sources":["../../src/helpers/host-component-names.tsx"],"sourcesContent":["import * as React from 'react';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { Switch, Text, TextInput, View } from 'react-native';\nimport { configureInternal, getConfig, HostComponentNames } from '../config';\nimport { renderWithAct } from '../render-act';\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 <Switch testID=\"switch\" />\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 switch: getByTestId(renderer.root, 'switch').type as string,\n };\n } catch (error) {\n const errorMessage =\n error && typeof error === 'object' && 'message' in error\n ? error.message\n : 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"],"mappings":";;;;;;;AAAA,IAAAA,KAAA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