@testing-library/react-native 11.2.0 → 11.3.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/config.d.ts +10 -0
- package/build/config.js +28 -0
- package/build/config.js.map +1 -0
- package/build/fireEvent.js +4 -6
- package/build/fireEvent.js.map +1 -1
- package/build/helpers/component-tree.d.ts +15 -0
- package/build/helpers/component-tree.js +55 -0
- package/build/helpers/component-tree.js.map +1 -1
- package/build/helpers/timers.js +1 -1
- package/build/helpers/timers.js.map +1 -1
- package/build/index.flow.js +8 -0
- package/build/pure.d.ts +2 -0
- package/build/pure.js +14 -0
- package/build/pure.js.map +1 -1
- package/build/queries/a11yState.d.ts +1 -1
- package/build/queries/a11yState.js.map +1 -1
- package/build/queries/displayValue.js +7 -15
- package/build/queries/displayValue.js.map +1 -1
- package/build/queries/placeholderText.js +6 -14
- package/build/queries/placeholderText.js.map +1 -1
- package/build/queries/text.js +28 -28
- package/build/queries/text.js.map +1 -1
- package/build/waitFor.js +3 -2
- package/build/waitFor.js.map +1 -1
- package/package.json +11 -11
- package/typings/index.flow.js +8 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare type Config = {
|
|
2
|
+
/** Default timeout, in ms, for `waitFor` and `findBy*` queries. */
|
|
3
|
+
asyncUtilTimeout: number;
|
|
4
|
+
};
|
|
5
|
+
export declare function configure(options: Partial<Config>): void;
|
|
6
|
+
export declare function resetToDefaults(): void;
|
|
7
|
+
export declare function getConfig(): {
|
|
8
|
+
/** Default timeout, in ms, for `waitFor` and `findBy*` queries. */
|
|
9
|
+
asyncUtilTimeout: number;
|
|
10
|
+
};
|
package/build/config.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.configure = configure;
|
|
7
|
+
exports.getConfig = getConfig;
|
|
8
|
+
exports.resetToDefaults = resetToDefaults;
|
|
9
|
+
const defaultConfig = {
|
|
10
|
+
asyncUtilTimeout: 1000
|
|
11
|
+
};
|
|
12
|
+
let config = { ...defaultConfig
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function configure(options) {
|
|
16
|
+
config = { ...config,
|
|
17
|
+
...options
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function resetToDefaults() {
|
|
22
|
+
config = defaultConfig;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getConfig() {
|
|
26
|
+
return config;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","names":["defaultConfig","asyncUtilTimeout","config","configure","options","resetToDefaults","getConfig"],"sources":["../src/config.ts"],"sourcesContent":["export type Config = {\n /** Default timeout, in ms, for `waitFor` and `findBy*` queries. */\n asyncUtilTimeout: number;\n};\n\nconst defaultConfig: Config = {\n asyncUtilTimeout: 1000,\n};\n\nlet config = {\n ...defaultConfig,\n};\n\nexport function configure(options: Partial<Config>) {\n config = {\n ...config,\n ...options,\n };\n}\n\nexport function resetToDefaults() {\n config = defaultConfig;\n}\n\nexport function getConfig() {\n return config;\n}\n"],"mappings":";;;;;;;;AAKA,MAAMA,aAAqB,GAAG;EAC5BC,gBAAgB,EAAE;AADU,CAA9B;AAIA,IAAIC,MAAM,GAAG,EACX,GAAGF;AADQ,CAAb;;AAIO,SAASG,SAAT,CAAmBC,OAAnB,EAA6C;EAClDF,MAAM,GAAG,EACP,GAAGA,MADI;IAEP,GAAGE;EAFI,CAAT;AAID;;AAEM,SAASC,eAAT,GAA2B;EAChCH,MAAM,GAAGF,aAAT;AACD;;AAEM,SAASM,SAAT,GAAqB;EAC1B,OAAOJ,MAAP;AACD"}
|
package/build/fireEvent.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
|
|
8
10
|
var _act = _interopRequireDefault(require("./act"));
|
|
9
11
|
|
|
10
12
|
var _componentTree = require("./helpers/component-tree");
|
|
@@ -16,11 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
16
18
|
const isTextInput = element => {
|
|
17
19
|
if (!element) {
|
|
18
20
|
return false;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const {
|
|
22
|
-
TextInput
|
|
23
|
-
} = require('react-native'); // We have to test if the element type is either the TextInput component
|
|
21
|
+
} // We have to test if the element type is either the TextInput component
|
|
24
22
|
// (which would if it is a composite component) or the string
|
|
25
23
|
// TextInput (which would be true if it is a host component)
|
|
26
24
|
// All queries but the one by testID return composite component and event
|
|
@@ -28,7 +26,7 @@ const isTextInput = element => {
|
|
|
28
26
|
// it would trigger the parent prop without the composite component check
|
|
29
27
|
|
|
30
28
|
|
|
31
|
-
return (0, _filterNodeByType.filterNodeByType)(element, TextInput) || (0, _filterNodeByType.filterNodeByType)(element, 'TextInput');
|
|
29
|
+
return (0, _filterNodeByType.filterNodeByType)(element, _reactNative.TextInput) || (0, _filterNodeByType.filterNodeByType)(element, 'TextInput');
|
|
32
30
|
};
|
|
33
31
|
|
|
34
32
|
const isTouchResponder = element => {
|
package/build/fireEvent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fireEvent.js","names":["isTextInput","element","
|
|
1
|
+
{"version":3,"file":"fireEvent.js","names":["isTextInput","element","filterNodeByType","TextInput","isTouchResponder","isHostElement","props","onStartShouldSetResponder","isPointerEventEnabled","isParent","parentCondition","pointerEvents","parent","isTouchEvent","eventName","isEventEnabled","touchResponder","editable","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","callsite","nearestTouchResponder","handler","getEventHandler","eventHandlerName","toEventHandlerName","invokeEvent","data","returnValue","act","charAt","toUpperCase","slice","pressHandler","changeTextHandler","scrollHandler","fireEvent","press","changeText","scroll"],"sources":["../src/fireEvent.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { TextInput } from 'react-native';\nimport act from './act';\nimport { isHostElement } from './helpers/component-tree';\nimport { filterNodeByType } from './helpers/filterNodeByType';\n\ntype EventHandler = (...args: any) => unknown;\n\nconst isTextInput = (element?: ReactTestInstance) => {\n if (!element) {\n return false;\n }\n\n // We have to test if the element type is either the TextInput component\n // (which would if it is a composite component) or the string\n // TextInput (which would be true if it is a host component)\n // All queries but the one by testID return composite component and event\n // if all queries returned host components, since fireEvent bubbles up\n // it would trigger the parent prop without the composite component check\n return (\n filterNodeByType(element, TextInput) ||\n filterNodeByType(element, 'TextInput')\n );\n};\n\nconst isTouchResponder = (element?: ReactTestInstance) => {\n if (!isHostElement(element)) return false;\n\n return !!element?.props.onStartShouldSetResponder || isTextInput(element);\n};\n\nconst isPointerEventEnabled = (\n element?: ReactTestInstance,\n isParent?: boolean\n): boolean => {\n const parentCondition = isParent\n ? element?.props.pointerEvents === 'box-only'\n : element?.props.pointerEvents === 'box-none';\n\n if (element?.props.pointerEvents === 'none' || parentCondition) {\n return false;\n }\n\n if (!element?.parent) return true;\n\n return isPointerEventEnabled(element.parent, true);\n};\n\nconst isTouchEvent = (eventName?: string) => {\n return eventName === 'press';\n};\n\nconst isEventEnabled = (\n element?: ReactTestInstance,\n touchResponder?: ReactTestInstance,\n eventName?: string\n) => {\n if (isTextInput(element)) return element?.props.editable !== false;\n if (!isPointerEventEnabled(element) && isTouchEvent(eventName)) return false;\n\n const touchStart = touchResponder?.props.onStartShouldSetResponder?.();\n const touchMove = touchResponder?.props.onMoveShouldSetResponder?.();\n\n if (touchStart || touchMove) return true;\n\n return touchStart === undefined && touchMove === undefined;\n};\n\nconst findEventHandler = (\n element: ReactTestInstance,\n eventName: string,\n callsite?: any,\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, touchResponder, eventName))\n return handler;\n\n if (element.parent === null || element.parent.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, callsite, touchResponder);\n};\n\nconst getEventHandler = (\n element: ReactTestInstance,\n eventName: string\n): EventHandler | undefined => {\n const eventHandlerName = toEventHandlerName(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\nconst invokeEvent = (\n element: ReactTestInstance,\n eventName: string,\n callsite?: any,\n ...data: Array<any>\n) => {\n const handler = findEventHandler(element, eventName, callsite);\n\n if (!handler) {\n return;\n }\n\n let returnValue;\n\n act(() => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n};\n\nconst toEventHandlerName = (eventName: string) =>\n `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n\nconst pressHandler = (element: ReactTestInstance, ...data: Array<any>): void =>\n invokeEvent(element, 'press', pressHandler, ...data);\nconst changeTextHandler = (\n element: ReactTestInstance,\n ...data: Array<any>\n): void => invokeEvent(element, 'changeText', changeTextHandler, ...data);\nconst scrollHandler = (element: ReactTestInstance, ...data: Array<any>): void =>\n invokeEvent(element, 'scroll', scrollHandler, ...data);\n\nconst fireEvent = (\n element: ReactTestInstance,\n eventName: string,\n ...data: Array<any>\n): void => invokeEvent(element, eventName, fireEvent, ...data);\n\nfireEvent.press = pressHandler;\nfireEvent.changeText = changeTextHandler;\nfireEvent.scroll = scrollHandler;\n\nexport default fireEvent;\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;;;AAIA,MAAMA,WAAW,GAAIC,OAAD,IAAiC;EACnD,IAAI,CAACA,OAAL,EAAc;IACZ,OAAO,KAAP;EACD,CAHkD,CAKnD;EACA;EACA;EACA;EACA;EACA;;;EACA,OACE,IA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B;eAEeC,S"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { ReactTestInstance } from 'react-test-renderer';
|
|
2
3
|
/**
|
|
3
4
|
* Checks if the given element is a host element.
|
|
@@ -14,6 +15,15 @@ export declare function getHostParent(element: ReactTestInstance | null): ReactT
|
|
|
14
15
|
* @param element The element start traversing from.
|
|
15
16
|
*/
|
|
16
17
|
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;
|
|
17
27
|
/**
|
|
18
28
|
* Return the array of host elements that represent the passed element.
|
|
19
29
|
*
|
|
@@ -27,3 +37,8 @@ export declare function getHostSelves(element: ReactTestInstance | null): ReactT
|
|
|
27
37
|
* @param element The element start traversing from.
|
|
28
38
|
*/
|
|
29
39
|
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,11 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getCompositeParentOfType = getCompositeParentOfType;
|
|
6
7
|
exports.getHostChildren = getHostChildren;
|
|
7
8
|
exports.getHostParent = getHostParent;
|
|
9
|
+
exports.getHostSelf = getHostSelf;
|
|
8
10
|
exports.getHostSelves = getHostSelves;
|
|
9
11
|
exports.getHostSiblings = getHostSiblings;
|
|
10
12
|
exports.isHostElement = isHostElement;
|
|
13
|
+
exports.isHostElementForType = isHostElementForType;
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* Checks if the given element is a host element.
|
|
@@ -64,6 +67,29 @@ function getHostChildren(element) {
|
|
|
64
67
|
});
|
|
65
68
|
return hostChildren;
|
|
66
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Return a single host element that represent the passed host or composite element.
|
|
72
|
+
*
|
|
73
|
+
* @param element The element start traversing from.
|
|
74
|
+
* @throws Error if the passed element is a composite element and has no host children or has more than one host child.
|
|
75
|
+
* @returns If the passed element is a host element, it will return itself, if the passed element is a composite
|
|
76
|
+
* element, it will return a single host descendant.
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
function getHostSelf(element) {
|
|
81
|
+
const hostSelves = getHostSelves(element);
|
|
82
|
+
|
|
83
|
+
if (hostSelves.length === 0) {
|
|
84
|
+
throw new Error(`Expected exactly one host element, but found none.`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (hostSelves.length > 1) {
|
|
88
|
+
throw new Error(`Expected exactly one host element, but found ${hostSelves.length}.`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return hostSelves[0];
|
|
92
|
+
}
|
|
67
93
|
/**
|
|
68
94
|
* Return the array of host elements that represent the passed element.
|
|
69
95
|
*
|
|
@@ -87,4 +113,33 @@ function getHostSiblings(element) {
|
|
|
87
113
|
const hostSelves = getHostSelves(element);
|
|
88
114
|
return getHostChildren(hostParent).filter(sibling => !hostSelves.includes(sibling));
|
|
89
115
|
}
|
|
116
|
+
|
|
117
|
+
function getCompositeParentOfType(element, type) {
|
|
118
|
+
let current = element.parent;
|
|
119
|
+
|
|
120
|
+
while (!isHostElement(current)) {
|
|
121
|
+
// We're at the root of the tree
|
|
122
|
+
if (!current) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (current.type === type) {
|
|
127
|
+
return current;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
current = current.parent;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Note: this function should be generally used for core React Native types like `View`, `Text`, `TextInput`, etc.
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
function isHostElementForType(element, type) {
|
|
141
|
+
// Not a host element
|
|
142
|
+
if (!isHostElement(element)) return false;
|
|
143
|
+
return getCompositeParentOfType(element, type) !== null;
|
|
144
|
+
}
|
|
90
145
|
//# 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","getHostSelves","
|
|
1
|
+
{"version":3,"file":"component-tree.js","names":["isHostElement","element","type","getHostParent","current","parent","getHostChildren","hostChildren","children","forEach","child","push","getHostSelf","hostSelves","getHostSelves","length","Error","getHostSiblings","hostParent","filter","sibling","includes","getCompositeParentOfType","isHostElementForType"],"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): boolean {\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 a single host element that represent the passed host or composite element.\n *\n * @param element The element start traversing from.\n * @throws Error if the passed element is a composite element and has no host children or has more than one host child.\n * @returns If the passed element is a host element, it will return itself, if the passed element is a composite\n * element, it will return a single host descendant.\n */\nexport function getHostSelf(\n element: ReactTestInstance | null\n): ReactTestInstance {\n const hostSelves = getHostSelves(element);\n\n if (hostSelves.length === 0) {\n throw new Error(`Expected exactly one host element, but found none.`);\n }\n\n if (hostSelves.length > 1) {\n throw new Error(\n `Expected exactly one host element, but found ${hostSelves.length}.`\n );\n }\n\n return hostSelves[0];\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\nexport function getCompositeParentOfType(\n element: ReactTestInstance,\n type: React.ComponentType\n) {\n let current = element.parent;\n\n while (!isHostElement(current)) {\n // We're at the root of the tree\n if (!current) {\n return null;\n }\n\n if (current.type === type) {\n return current;\n }\n current = current.parent;\n }\n\n return null;\n}\n\n/**\n * Note: this function should be generally used for core React Native types like `View`, `Text`, `TextInput`, etc.\n */\nexport function isHostElementForType(\n element: ReactTestInstance,\n type: React.ComponentType\n) {\n // Not a host element\n if (!isHostElement(element)) return false;\n\n return getCompositeParentOfType(element, type) !== null;\n}\n"],"mappings":";;;;;;;;;;;;;;AAEA;AACA;AACA;AACA;AACO,SAASA,aAAT,CAAuBC,OAAvB,EAAoE;EACzE,OAAO,OAAOA,OAAO,EAAEC,IAAhB,KAAyB,QAAhC;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASC,aAAT,CACLF,OADK,EAEqB;EAC1B,IAAIA,OAAO,IAAI,IAAf,EAAqB;IACnB,OAAO,IAAP;EACD;;EAED,IAAIG,OAAO,GAAGH,OAAO,CAACI,MAAtB;;EACA,OAAOD,OAAP,EAAgB;IACd,IAAIJ,aAAa,CAACI,OAAD,CAAjB,EAA4B;MAC1B,OAAOA,OAAP;IACD;;IAEDA,OAAO,GAAGA,OAAO,CAACC,MAAlB;EACD;;EAED,OAAO,IAAP;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASC,eAAT,CACLL,OADK,EAEgB;EACrB,IAAIA,OAAO,IAAI,IAAf,EAAqB;IACnB,OAAO,EAAP;EACD;;EAED,MAAMM,YAAiC,GAAG,EAA1C;EAEAN,OAAO,CAACO,QAAR,CAAiBC,OAAjB,CAA0BC,KAAD,IAAW;IAClC,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;MAC7B;IACD;;IAED,IAAIV,aAAa,CAACU,KAAD,CAAjB,EAA0B;MACxBH,YAAY,CAACI,IAAb,CAAkBD,KAAlB;IACD,CAFD,MAEO;MACLH,YAAY,CAACI,IAAb,CAAkB,GAAGL,eAAe,CAACI,KAAD,CAApC;IACD;EACF,CAVD;EAYA,OAAOH,YAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASK,WAAT,CACLX,OADK,EAEc;EACnB,MAAMY,UAAU,GAAGC,aAAa,CAACb,OAAD,CAAhC;;EAEA,IAAIY,UAAU,CAACE,MAAX,KAAsB,CAA1B,EAA6B;IAC3B,MAAM,IAAIC,KAAJ,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
|
package/build/helpers/timers.js
CHANGED
|
@@ -31,7 +31,7 @@ function runWithRealTimers(callback) {
|
|
|
31
31
|
|
|
32
32
|
function getJestFakeTimersType() {
|
|
33
33
|
// istanbul ignore if
|
|
34
|
-
if (typeof jest === 'undefined' || typeof globalObj.setTimeout === 'undefined') {
|
|
34
|
+
if (typeof jest === 'undefined' || typeof globalObj.setTimeout === 'undefined' || process.env.RNTL_SKIP_AUTO_DETECT_FAKE_TIMERS) {
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timers.js","names":["globalObj","window","global","runWithRealTimers","callback","fakeTimersType","getJestFakeTimersType","jest","useRealTimers","callbackReturnValue","fakeTimersConfig","getFakeTimersConfigFromType","useFakeTimers","setTimeout","_isMockFunction","clock","getRealSystemTime","type","legacyFakeTimers","jestFakeTimersAreEnabled","Boolean","setImmediatePolyfill","fn","bindTimeFunctions","clearTimeoutFn","clearTimeout","setImmediateFn","setImmediate","setTimeoutFn"],"sources":["../../src/helpers/timers.ts"],"sourcesContent":["// Most content of this file sourced directly from https://github.com/testing-library/dom-testing-library/blob/main/src/helpers.js\n/* globals jest */\nconst globalObj = typeof window === 'undefined' ? global : window;\n\ntype FakeTimersTypes = 'modern' | 'legacy';\n\n// Currently this fn only supports jest timers, but it could support other test runners in the future.\nfunction runWithRealTimers<T>(callback: () => T): T {\n const fakeTimersType = getJestFakeTimersType();\n if (fakeTimersType) {\n jest.useRealTimers();\n }\n\n const callbackReturnValue = callback();\n\n if (fakeTimersType) {\n const fakeTimersConfig = getFakeTimersConfigFromType(fakeTimersType);\n jest.useFakeTimers(fakeTimersConfig);\n }\n\n return callbackReturnValue;\n}\n\nfunction getJestFakeTimersType(): FakeTimersTypes | null {\n // istanbul ignore if\n if (\n typeof jest === 'undefined' ||\n typeof globalObj.setTimeout === 'undefined'\n ) {\n return null;\n }\n\n if (\n // @ts-expect-error jest mutates setTimeout\n typeof globalObj.setTimeout._isMockFunction !== 'undefined' &&\n // @ts-expect-error jest mutates setTimeout\n globalObj.setTimeout._isMockFunction\n ) {\n return 'legacy';\n }\n\n if (\n // @ts-expect-error jest mutates setTimeout\n typeof globalObj.setTimeout.clock !== 'undefined' &&\n typeof jest.getRealSystemTime !== 'undefined'\n ) {\n try {\n // jest.getRealSystemTime is only supported for Jest's `modern` fake timers and otherwise throws\n jest.getRealSystemTime();\n return 'modern';\n } catch {\n // not using Jest's modern fake timers\n }\n }\n\n return null;\n}\n\nfunction getFakeTimersConfigFromType(type: FakeTimersTypes) {\n return type === 'legacy'\n ? { legacyFakeTimers: true }\n : { legacyFakeTimers: false };\n}\n\nconst jestFakeTimersAreEnabled = (): boolean =>\n Boolean(getJestFakeTimersType());\n\n// we only run our tests in node, and setImmediate is supported in node.\nfunction setImmediatePolyfill(fn: Function) {\n return globalObj.setTimeout(fn, 0);\n}\n\ntype BindTimeFunctions = {\n clearTimeoutFn: typeof clearTimeout;\n setImmediateFn: typeof setImmediate;\n setTimeoutFn: typeof setTimeout;\n};\n\nfunction bindTimeFunctions(): BindTimeFunctions {\n return {\n clearTimeoutFn: globalObj.clearTimeout,\n setImmediateFn: globalObj.setImmediate || setImmediatePolyfill,\n setTimeoutFn: globalObj.setTimeout,\n };\n}\n\nconst { clearTimeoutFn, setImmediateFn, setTimeoutFn } = runWithRealTimers(\n bindTimeFunctions\n) as BindTimeFunctions;\n\nexport {\n runWithRealTimers,\n jestFakeTimersAreEnabled,\n clearTimeoutFn as clearTimeout,\n setImmediateFn as setImmediate,\n setTimeoutFn as setTimeout,\n};\n"],"mappings":";;;;;;;;AAAA;;AACA;AACA,MAAMA,SAAS,GAAG,OAAOC,MAAP,KAAkB,WAAlB,GAAgCC,MAAhC,GAAyCD,MAA3D;;AAIA;AACA,SAASE,iBAAT,CAA8BC,QAA9B,EAAoD;EAClD,MAAMC,cAAc,GAAGC,qBAAqB,EAA5C;;EACA,IAAID,cAAJ,EAAoB;IAClBE,IAAI,CAACC,aAAL;EACD;;EAED,MAAMC,mBAAmB,GAAGL,QAAQ,EAApC;;EAEA,IAAIC,cAAJ,EAAoB;IAClB,MAAMK,gBAAgB,GAAGC,2BAA2B,CAACN,cAAD,CAApD;IACAE,IAAI,CAACK,aAAL,CAAmBF,gBAAnB;EACD;;EAED,OAAOD,mBAAP;AACD;;AAED,SAASH,qBAAT,GAAyD;EACvD;EACA,IACE,OAAOC,IAAP,KAAgB,WAAhB,IACA,OAAOP,SAAS,CAACa,UAAjB,KAAgC,
|
|
1
|
+
{"version":3,"file":"timers.js","names":["globalObj","window","global","runWithRealTimers","callback","fakeTimersType","getJestFakeTimersType","jest","useRealTimers","callbackReturnValue","fakeTimersConfig","getFakeTimersConfigFromType","useFakeTimers","setTimeout","process","env","RNTL_SKIP_AUTO_DETECT_FAKE_TIMERS","_isMockFunction","clock","getRealSystemTime","type","legacyFakeTimers","jestFakeTimersAreEnabled","Boolean","setImmediatePolyfill","fn","bindTimeFunctions","clearTimeoutFn","clearTimeout","setImmediateFn","setImmediate","setTimeoutFn"],"sources":["../../src/helpers/timers.ts"],"sourcesContent":["// Most content of this file sourced directly from https://github.com/testing-library/dom-testing-library/blob/main/src/helpers.js\n/* globals jest */\nconst globalObj = typeof window === 'undefined' ? global : window;\n\ntype FakeTimersTypes = 'modern' | 'legacy';\n\n// Currently this fn only supports jest timers, but it could support other test runners in the future.\nfunction runWithRealTimers<T>(callback: () => T): T {\n const fakeTimersType = getJestFakeTimersType();\n if (fakeTimersType) {\n jest.useRealTimers();\n }\n\n const callbackReturnValue = callback();\n\n if (fakeTimersType) {\n const fakeTimersConfig = getFakeTimersConfigFromType(fakeTimersType);\n jest.useFakeTimers(fakeTimersConfig);\n }\n\n return callbackReturnValue;\n}\n\nfunction getJestFakeTimersType(): FakeTimersTypes | null {\n // istanbul ignore if\n if (\n typeof jest === 'undefined' ||\n typeof globalObj.setTimeout === 'undefined' ||\n process.env.RNTL_SKIP_AUTO_DETECT_FAKE_TIMERS\n ) {\n return null;\n }\n\n if (\n // @ts-expect-error jest mutates setTimeout\n typeof globalObj.setTimeout._isMockFunction !== 'undefined' &&\n // @ts-expect-error jest mutates setTimeout\n globalObj.setTimeout._isMockFunction\n ) {\n return 'legacy';\n }\n\n if (\n // @ts-expect-error jest mutates setTimeout\n typeof globalObj.setTimeout.clock !== 'undefined' &&\n typeof jest.getRealSystemTime !== 'undefined'\n ) {\n try {\n // jest.getRealSystemTime is only supported for Jest's `modern` fake timers and otherwise throws\n jest.getRealSystemTime();\n return 'modern';\n } catch {\n // not using Jest's modern fake timers\n }\n }\n\n return null;\n}\n\nfunction getFakeTimersConfigFromType(type: FakeTimersTypes) {\n return type === 'legacy'\n ? { legacyFakeTimers: true }\n : { legacyFakeTimers: false };\n}\n\nconst jestFakeTimersAreEnabled = (): boolean =>\n Boolean(getJestFakeTimersType());\n\n// we only run our tests in node, and setImmediate is supported in node.\nfunction setImmediatePolyfill(fn: Function) {\n return globalObj.setTimeout(fn, 0);\n}\n\ntype BindTimeFunctions = {\n clearTimeoutFn: typeof clearTimeout;\n setImmediateFn: typeof setImmediate;\n setTimeoutFn: typeof setTimeout;\n};\n\nfunction bindTimeFunctions(): BindTimeFunctions {\n return {\n clearTimeoutFn: globalObj.clearTimeout,\n setImmediateFn: globalObj.setImmediate || setImmediatePolyfill,\n setTimeoutFn: globalObj.setTimeout,\n };\n}\n\nconst { clearTimeoutFn, setImmediateFn, setTimeoutFn } = runWithRealTimers(\n bindTimeFunctions\n) as BindTimeFunctions;\n\nexport {\n runWithRealTimers,\n jestFakeTimersAreEnabled,\n clearTimeoutFn as clearTimeout,\n setImmediateFn as setImmediate,\n setTimeoutFn as setTimeout,\n};\n"],"mappings":";;;;;;;;AAAA;;AACA;AACA,MAAMA,SAAS,GAAG,OAAOC,MAAP,KAAkB,WAAlB,GAAgCC,MAAhC,GAAyCD,MAA3D;;AAIA;AACA,SAASE,iBAAT,CAA8BC,QAA9B,EAAoD;EAClD,MAAMC,cAAc,GAAGC,q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AAO;IACLC,cAAc,EAAE3B,SAAS,CAAC4B,YADrB;IAELC,cAAc,EAAE7B,SAAS,CAAC8B,YAAV,IAA0BN,oBAFrC;IAGLO,YAAY,EAAE/B,SAAS,CAACa;EAHnB,CAAP;AAKD;;AAED,MAAM;EAAEc,cAAF;EAAkBE,cAAlB;EAAkCE;AAAlC,IAAmD5B,iBAAiB,CACxEuB,iBADwE,CAA1E"}
|
package/build/index.flow.js
CHANGED
|
@@ -346,6 +346,7 @@ declare module '@testing-library/react-native' {
|
|
|
346
346
|
declare interface RenderOptions {
|
|
347
347
|
wrapper?: React.ComponentType<any>;
|
|
348
348
|
createNodeMock?: (element: React.Element<any>) => any;
|
|
349
|
+
unstable_validateStringsRenderedWithinText?: boolean;
|
|
349
350
|
}
|
|
350
351
|
|
|
351
352
|
declare export var render: (
|
|
@@ -367,6 +368,13 @@ declare module '@testing-library/react-native' {
|
|
|
367
368
|
|
|
368
369
|
declare export var waitForElementToBeRemoved: WaitForElementToBeRemovedFunction;
|
|
369
370
|
|
|
371
|
+
declare interface Config {
|
|
372
|
+
asyncUtilTimeout: number;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
declare export var configure: (options: $Shape<Config>) => void;
|
|
376
|
+
declare export var resetToDefaults: () => void;
|
|
377
|
+
|
|
370
378
|
declare export var act: (callback: () => void) => Thenable;
|
|
371
379
|
declare export var within: (instance: ReactTestInstance) => Queries;
|
|
372
380
|
declare export var getQueriesForElement: (
|
package/build/pure.d.ts
CHANGED
|
@@ -11,8 +11,10 @@ import { screen } from './screen';
|
|
|
11
11
|
import { isInaccessible } from './helpers/accessiblity';
|
|
12
12
|
export type { RenderOptions, RenderResult, RenderResult as RenderAPI, } from './render';
|
|
13
13
|
export type { RenderHookOptions, RenderHookResult } from './renderHook';
|
|
14
|
+
export type { Config } from './config';
|
|
14
15
|
export { act };
|
|
15
16
|
export { cleanup };
|
|
17
|
+
export { configure, resetToDefaults } from './config';
|
|
16
18
|
export { fireEvent };
|
|
17
19
|
export { render };
|
|
18
20
|
export { waitFor };
|
package/build/pure.js
CHANGED
|
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "cleanup", {
|
|
|
15
15
|
return _cleanup.default;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "configure", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _config.configure;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
Object.defineProperty(exports, "fireEvent", {
|
|
19
25
|
enumerable: true,
|
|
20
26
|
get: function () {
|
|
@@ -51,6 +57,12 @@ Object.defineProperty(exports, "renderHook", {
|
|
|
51
57
|
return _renderHook.renderHook;
|
|
52
58
|
}
|
|
53
59
|
});
|
|
60
|
+
Object.defineProperty(exports, "resetToDefaults", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _config.resetToDefaults;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
54
66
|
Object.defineProperty(exports, "screen", {
|
|
55
67
|
enumerable: true,
|
|
56
68
|
get: function () {
|
|
@@ -98,5 +110,7 @@ var _screen = require("./screen");
|
|
|
98
110
|
|
|
99
111
|
var _accessiblity = require("./helpers/accessiblity");
|
|
100
112
|
|
|
113
|
+
var _config = require("./config");
|
|
114
|
+
|
|
101
115
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
102
116
|
//# sourceMappingURL=pure.js.map
|
package/build/pure.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pure.js","names":[],"sources":["../src/pure.ts"],"sourcesContent":["import act from './act';\nimport cleanup from './cleanup';\nimport fireEvent from './fireEvent';\nimport render from './render';\nimport waitFor from './waitFor';\nimport waitForElementToBeRemoved from './waitForElementToBeRemoved';\nimport { within, getQueriesForElement } from './within';\nimport { getDefaultNormalizer } from './matches';\nimport { renderHook } from './renderHook';\nimport { screen } from './screen';\nimport { isInaccessible } from './helpers/accessiblity';\n\nexport type {\n RenderOptions,\n RenderResult,\n RenderResult as RenderAPI,\n} from './render';\nexport type { RenderHookOptions, RenderHookResult } from './renderHook';\n\nexport { act };\nexport { cleanup };\nexport { fireEvent };\nexport { render };\nexport { waitFor };\nexport { waitForElementToBeRemoved };\nexport { within, getQueriesForElement };\nexport { getDefaultNormalizer };\nexport { renderHook };\nexport { screen };\nexport { isInaccessible };\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"pure.js","names":[],"sources":["../src/pure.ts"],"sourcesContent":["import act from './act';\nimport cleanup from './cleanup';\nimport fireEvent from './fireEvent';\nimport render from './render';\nimport waitFor from './waitFor';\nimport waitForElementToBeRemoved from './waitForElementToBeRemoved';\nimport { within, getQueriesForElement } from './within';\nimport { getDefaultNormalizer } from './matches';\nimport { renderHook } from './renderHook';\nimport { screen } from './screen';\nimport { isInaccessible } from './helpers/accessiblity';\n\nexport type {\n RenderOptions,\n RenderResult,\n RenderResult as RenderAPI,\n} from './render';\nexport type { RenderHookOptions, RenderHookResult } from './renderHook';\nexport type { Config } from './config';\n\nexport { act };\nexport { cleanup };\nexport { configure, resetToDefaults } from './config';\nexport { fireEvent };\nexport { render };\nexport { waitFor };\nexport { waitForElementToBeRemoved };\nexport { within, getQueriesForElement };\nexport { getDefaultNormalizer };\nexport { renderHook };\nexport { screen };\nexport { isInaccessible };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAYA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
-
import { AccessibilityState } from 'react-native';
|
|
2
|
+
import type { AccessibilityState } from 'react-native';
|
|
3
3
|
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './makeQueries';
|
|
4
4
|
export declare type ByA11yStateQueries = {
|
|
5
5
|
getByA11yState: GetByQuery<AccessibilityState>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"a11yState.js","names":["queryAllByA11yState","instance","queryAllByA11yStateFn","state","findAll","node","type","matchObjectProp","props","accessibilityState","getMultipleError","JSON","stringify","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByA11yStateQueries","getByA11yState","getAllByA11yState","queryByA11yState","findByA11yState","findAllByA11yState","getByAccessibilityState","getAllByAccessibilityState","queryByAccessibilityState","queryAllByAccessibilityState","findByAccessibilityState","findAllByAccessibilityState"],"sources":["../../src/queries/a11yState.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { AccessibilityState } from 'react-native';\nimport { matchObjectProp } from '../helpers/matchers/matchObjectProp';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\nconst queryAllByA11yState = (\n instance: ReactTestInstance\n): ((state: AccessibilityState) => Array<ReactTestInstance>) =>\n function queryAllByA11yStateFn(state) {\n return instance.findAll(\n (node) =>\n typeof node.type === 'string' &&\n matchObjectProp(node.props.accessibilityState, state)\n );\n };\n\nconst getMultipleError = (state: AccessibilityState) =>\n `Found multiple elements with accessibilityState: ${JSON.stringify(state)}`;\nconst getMissingError = (state: AccessibilityState) =>\n `Unable to find an element with accessibilityState: ${JSON.stringify(state)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByA11yState,\n getMissingError,\n getMultipleError\n);\n\nexport type ByA11yStateQueries = {\n getByA11yState: GetByQuery<AccessibilityState>;\n getAllByA11yState: GetAllByQuery<AccessibilityState>;\n queryByA11yState: QueryByQuery<AccessibilityState>;\n queryAllByA11yState: QueryAllByQuery<AccessibilityState>;\n findByA11yState: FindByQuery<AccessibilityState>;\n findAllByA11yState: FindAllByQuery<AccessibilityState>;\n\n getByAccessibilityState: GetByQuery<AccessibilityState>;\n getAllByAccessibilityState: GetAllByQuery<AccessibilityState>;\n queryByAccessibilityState: QueryByQuery<AccessibilityState>;\n queryAllByAccessibilityState: QueryAllByQuery<AccessibilityState>;\n findByAccessibilityState: FindByQuery<AccessibilityState>;\n findAllByAccessibilityState: FindAllByQuery<AccessibilityState>;\n};\n\nexport const bindByA11yStateQueries = (\n instance: ReactTestInstance\n): ByA11yStateQueries => {\n const getByA11yState = getBy(instance);\n const getAllByA11yState = getAllBy(instance);\n const queryByA11yState = queryBy(instance);\n const queryAllByA11yState = queryAllBy(instance);\n const findByA11yState = findBy(instance);\n const findAllByA11yState = findAllBy(instance);\n\n return {\n getByA11yState,\n getAllByA11yState,\n queryByA11yState,\n queryAllByA11yState,\n findByA11yState,\n findAllByA11yState,\n\n getByAccessibilityState: getByA11yState,\n getAllByAccessibilityState: getAllByA11yState,\n queryByAccessibilityState: queryByA11yState,\n queryAllByAccessibilityState: queryAllByA11yState,\n findByAccessibilityState: findByA11yState,\n findAllByAccessibilityState: findAllByA11yState,\n };\n};\n"],"mappings":";;;;;;;AAEA;;AACA;;AAUA,MAAMA,mBAAmB,GACvBC,QAD0B,IAG1B,SAASC,qBAAT,CAA+BC,KAA/B,EAAsC;EACpC,OAAOF,QAAQ,CAACG,OAAT,CACJC,IAAD,IACE,OAAOA,IAAI,CAACC,IAAZ,KAAqB,QAArB,IACA,IAAAC,gCAAA,EAAgBF,IAAI,CAACG,KAAL,CAAWC,kBAA3B,EAA+CN,KAA/C,CAHG,CAAP;AAKD,CATH;;AAWA,MAAMO,gBAAgB,GAAIP,KAAD,IACtB,oDAAmDQ,IAAI,CAACC,SAAL,CAAeT,KAAf,CAAsB,EAD5E;;AAEA,MAAMU,eAAe,GAAIV,KAAD,IACrB,sDAAqDQ,IAAI,CAACC,SAAL,CAAeT,KAAf,CAAsB,EAD9E;;AAGA,MAAM;EAAEW,KAAF;EAASC,QAAT;EAAmBC,OAAnB;EAA4BC,UAA5B;EAAwCC,MAAxC;EAAgDC;AAAhD,IAA8D,IAAAC,wBAAA,EAClEpB,mBADkE,EAElEa,eAFkE,EAGlEH,gBAHkE,CAApE;;AAsBO,MAAMW,sBAAsB,GACjCpB,QADoC,IAEb;EACvB,MAAMqB,cAAc,GAAGR,KAAK,CAACb,QAAD,CAA5B;EACA,MAAMsB,iBAAiB,GAAGR,QAAQ,CAACd,QAAD,CAAlC;EACA,MAAMuB,gBAAgB,GAAGR,OAAO,CAACf,QAAD,CAAhC;EACA,MAAMD,mBAAmB,GAAGiB,UAAU,CAAChB,QAAD,CAAtC;EACA,MAAMwB,eAAe,GAAGP,MAAM,CAACjB,QAAD,CAA9B;EACA,MAAMyB,kBAAkB,GAAGP,SAAS,CAAClB,QAAD,CAApC;EAEA,OAAO;IACLqB,cADK;IAELC,iBAFK;IAGLC,gBAHK;IAILxB,mBAJK;IAKLyB,eALK;IAMLC,kBANK;IAQLC,uBAAuB,EAAEL,cARpB;IASLM,0BAA0B,EAAEL,iBATvB;IAULM,yBAAyB,EAAEL,gBAVtB;IAWLM,4BAA4B,EAAE9B,mBAXzB;IAYL+B,wBAAwB,EAAEN,eAZrB;IAaLO,2BAA2B,EAAEN;EAbxB,CAAP;AAeD,CAzBM"}
|
|
1
|
+
{"version":3,"file":"a11yState.js","names":["queryAllByA11yState","instance","queryAllByA11yStateFn","state","findAll","node","type","matchObjectProp","props","accessibilityState","getMultipleError","JSON","stringify","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByA11yStateQueries","getByA11yState","getAllByA11yState","queryByA11yState","findByA11yState","findAllByA11yState","getByAccessibilityState","getAllByAccessibilityState","queryByAccessibilityState","queryAllByAccessibilityState","findByAccessibilityState","findAllByAccessibilityState"],"sources":["../../src/queries/a11yState.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport type { AccessibilityState } from 'react-native';\nimport { matchObjectProp } from '../helpers/matchers/matchObjectProp';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\nconst queryAllByA11yState = (\n instance: ReactTestInstance\n): ((state: AccessibilityState) => Array<ReactTestInstance>) =>\n function queryAllByA11yStateFn(state) {\n return instance.findAll(\n (node) =>\n typeof node.type === 'string' &&\n matchObjectProp(node.props.accessibilityState, state)\n );\n };\n\nconst getMultipleError = (state: AccessibilityState) =>\n `Found multiple elements with accessibilityState: ${JSON.stringify(state)}`;\nconst getMissingError = (state: AccessibilityState) =>\n `Unable to find an element with accessibilityState: ${JSON.stringify(state)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByA11yState,\n getMissingError,\n getMultipleError\n);\n\nexport type ByA11yStateQueries = {\n getByA11yState: GetByQuery<AccessibilityState>;\n getAllByA11yState: GetAllByQuery<AccessibilityState>;\n queryByA11yState: QueryByQuery<AccessibilityState>;\n queryAllByA11yState: QueryAllByQuery<AccessibilityState>;\n findByA11yState: FindByQuery<AccessibilityState>;\n findAllByA11yState: FindAllByQuery<AccessibilityState>;\n\n getByAccessibilityState: GetByQuery<AccessibilityState>;\n getAllByAccessibilityState: GetAllByQuery<AccessibilityState>;\n queryByAccessibilityState: QueryByQuery<AccessibilityState>;\n queryAllByAccessibilityState: QueryAllByQuery<AccessibilityState>;\n findByAccessibilityState: FindByQuery<AccessibilityState>;\n findAllByAccessibilityState: FindAllByQuery<AccessibilityState>;\n};\n\nexport const bindByA11yStateQueries = (\n instance: ReactTestInstance\n): ByA11yStateQueries => {\n const getByA11yState = getBy(instance);\n const getAllByA11yState = getAllBy(instance);\n const queryByA11yState = queryBy(instance);\n const queryAllByA11yState = queryAllBy(instance);\n const findByA11yState = findBy(instance);\n const findAllByA11yState = findAllBy(instance);\n\n return {\n getByA11yState,\n getAllByA11yState,\n queryByA11yState,\n queryAllByA11yState,\n findByA11yState,\n findAllByA11yState,\n\n getByAccessibilityState: getByA11yState,\n getAllByAccessibilityState: getAllByA11yState,\n queryByAccessibilityState: queryByA11yState,\n queryAllByAccessibilityState: queryAllByA11yState,\n findByAccessibilityState: findByA11yState,\n findAllByAccessibilityState: findAllByA11yState,\n };\n};\n"],"mappings":";;;;;;;AAEA;;AACA;;AAUA,MAAMA,mBAAmB,GACvBC,QAD0B,IAG1B,SAASC,qBAAT,CAA+BC,KAA/B,EAAsC;EACpC,OAAOF,QAAQ,CAACG,OAAT,CACJC,IAAD,IACE,OAAOA,IAAI,CAACC,IAAZ,KAAqB,QAArB,IACA,IAAAC,gCAAA,EAAgBF,IAAI,CAACG,KAAL,CAAWC,kBAA3B,EAA+CN,KAA/C,CAHG,CAAP;AAKD,CATH;;AAWA,MAAMO,gBAAgB,GAAIP,KAAD,IACtB,oDAAmDQ,IAAI,CAACC,SAAL,CAAeT,KAAf,CAAsB,EAD5E;;AAEA,MAAMU,eAAe,GAAIV,KAAD,IACrB,sDAAqDQ,IAAI,CAACC,SAAL,CAAeT,KAAf,CAAsB,EAD9E;;AAGA,MAAM;EAAEW,KAAF;EAASC,QAAT;EAAmBC,OAAnB;EAA4BC,UAA5B;EAAwCC,MAAxC;EAAgDC;AAAhD,IAA8D,IAAAC,wBAAA,EAClEpB,mBADkE,EAElEa,eAFkE,EAGlEH,gBAHkE,CAApE;;AAsBO,MAAMW,sBAAsB,GACjCpB,QADoC,IAEb;EACvB,MAAMqB,cAAc,GAAGR,KAAK,CAACb,QAAD,CAA5B;EACA,MAAMsB,iBAAiB,GAAGR,QAAQ,CAACd,QAAD,CAAlC;EACA,MAAMuB,gBAAgB,GAAGR,OAAO,CAACf,QAAD,CAAhC;EACA,MAAMD,mBAAmB,GAAGiB,UAAU,CAAChB,QAAD,CAAtC;EACA,MAAMwB,eAAe,GAAGP,MAAM,CAACjB,QAAD,CAA9B;EACA,MAAMyB,kBAAkB,GAAGP,SAAS,CAAClB,QAAD,CAApC;EAEA,OAAO;IACLqB,cADK;IAELC,iBAFK;IAGLC,gBAHK;IAILxB,mBAJK;IAKLyB,eALK;IAMLC,kBANK;IAQLC,uBAAuB,EAAEL,cARpB;IASLM,0BAA0B,EAAEL,iBATvB;IAULM,yBAAyB,EAAEL,gBAVtB;IAWLM,4BAA4B,EAAE9B,mBAXzB;IAYL+B,wBAAwB,EAAEN,eAZrB;IAaLO,2BAA2B,EAAEN;EAbxB,CAAP;AAeD,CAzBM"}
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.bindByDisplayValueQueries = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
9
|
|
|
10
10
|
var _filterNodeByType = require("../helpers/filterNodeByType");
|
|
11
11
|
|
|
@@ -14,20 +14,12 @@ var _matches = require("../matches");
|
|
|
14
14
|
var _makeQueries = require("./makeQueries");
|
|
15
15
|
|
|
16
16
|
const getTextInputNodeByDisplayValue = (node, value, options = {}) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
exact,
|
|
24
|
-
normalizer
|
|
25
|
-
} = options;
|
|
26
|
-
const nodeValue = node.props.value !== undefined ? node.props.value : node.props.defaultValue;
|
|
27
|
-
return (0, _filterNodeByType.filterNodeByType)(node, TextInput) && (0, _matches.matches)(value, nodeValue, normalizer, exact);
|
|
28
|
-
} catch (error) {
|
|
29
|
-
throw (0, _errors.createLibraryNotSupportedError)(error);
|
|
30
|
-
}
|
|
17
|
+
const {
|
|
18
|
+
exact,
|
|
19
|
+
normalizer
|
|
20
|
+
} = options;
|
|
21
|
+
const nodeValue = node.props.value !== undefined ? node.props.value : node.props.defaultValue;
|
|
22
|
+
return (0, _filterNodeByType.filterNodeByType)(node, _reactNative.TextInput) && (0, _matches.matches)(value, nodeValue, normalizer, exact);
|
|
31
23
|
};
|
|
32
24
|
|
|
33
25
|
const queryAllByDisplayValue = instance => function queryAllByDisplayValueFn(displayValue, queryOptions) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"displayValue.js","names":["getTextInputNodeByDisplayValue","node","value","options","
|
|
1
|
+
{"version":3,"file":"displayValue.js","names":["getTextInputNodeByDisplayValue","node","value","options","exact","normalizer","nodeValue","props","undefined","defaultValue","filterNodeByType","TextInput","matches","queryAllByDisplayValue","instance","queryAllByDisplayValueFn","displayValue","queryOptions","findAll","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByDisplayValueQueries","getByDisplayValue","getAllByDisplayValue","queryByDisplayValue","findByDisplayValue","findAllByDisplayValue"],"sources":["../../src/queries/displayValue.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { TextInput } from 'react-native';\nimport { filterNodeByType } from '../helpers/filterNodeByType';\nimport { matches, TextMatch } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport type { TextMatchOptions } from './text';\n\nconst getTextInputNodeByDisplayValue = (\n node: ReactTestInstance,\n value: TextMatch,\n options: TextMatchOptions = {}\n) => {\n const { exact, normalizer } = options;\n const nodeValue =\n node.props.value !== undefined ? node.props.value : node.props.defaultValue;\n return (\n filterNodeByType(node, TextInput) &&\n matches(value, nodeValue, normalizer, exact)\n );\n};\n\nconst queryAllByDisplayValue = (\n instance: ReactTestInstance\n): ((\n displayValue: TextMatch,\n queryOptions?: TextMatchOptions\n) => Array<ReactTestInstance>) =>\n function queryAllByDisplayValueFn(displayValue, queryOptions) {\n return instance.findAll((node) =>\n getTextInputNodeByDisplayValue(node, displayValue, queryOptions)\n );\n };\n\nconst getMultipleError = (displayValue: TextMatch) =>\n `Found multiple elements with display value: ${String(displayValue)} `;\nconst getMissingError = (displayValue: TextMatch) =>\n `Unable to find an element with displayValue: ${String(displayValue)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByDisplayValue,\n getMissingError,\n getMultipleError\n);\n\nexport type ByDisplayValueQueries = {\n getByDisplayValue: GetByQuery<TextMatch, TextMatchOptions>;\n getAllByDisplayValue: GetAllByQuery<TextMatch, TextMatchOptions>;\n queryByDisplayValue: QueryByQuery<TextMatch, TextMatchOptions>;\n queryAllByDisplayValue: QueryAllByQuery<TextMatch, TextMatchOptions>;\n findByDisplayValue: FindByQuery<TextMatch, TextMatchOptions>;\n findAllByDisplayValue: FindAllByQuery<TextMatch, TextMatchOptions>;\n};\n\nexport const bindByDisplayValueQueries = (\n instance: ReactTestInstance\n): ByDisplayValueQueries => ({\n getByDisplayValue: getBy(instance),\n getAllByDisplayValue: getAllBy(instance),\n queryByDisplayValue: queryBy(instance),\n queryAllByDisplayValue: queryAllBy(instance),\n findByDisplayValue: findBy(instance),\n findAllByDisplayValue: findAllBy(instance),\n});\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AAWA,MAAMA,8BAA8B,GAAG,CACrCC,IADqC,EAErCC,KAFqC,EAGrCC,OAAyB,GAAG,EAHS,KAIlC;EACH,MAAM;IAAEC,KAAF;IAASC;EAAT,IAAwBF,OAA9B;EACA,MAAMG,SAAS,GACbL,IAAI,CAACM,KAAL,CAAWL,KAAX,KAAqBM,SAArB,GAAiCP,IAAI,CAACM,KAAL,CAAWL,KAA5C,GAAoDD,IAAI,CAACM,KAAL,CAAWE,YADjE;EAEA,OACE,IAAAC,kCAAA,EAAiBT,IAAjB,EAAuBU,sBAAvB,KACA,IAAAC,gBAAA,EAAQV,KAAR,EAAeI,SAAf,EAA0BD,UAA1B,EAAsCD,KAAtC,CAFF;AAID,CAZD;;AAcA,MAAMS,sBAAsB,GAC1BC,QAD6B,IAM7B,SAASC,wBAAT,CAAkCC,YAAlC,EAAgDC,YAAhD,EAA8D;EAC5D,OAAOH,QAAQ,CAACI,OAAT,CAAkBjB,IAAD,IACtBD,8BAA8B,CAACC,IAAD,EAAOe,YAAP,EAAqBC,YAArB,CADzB,CAAP;AAGD,CAVH;;AAYA,MAAME,gBAAgB,GAAIH,YAAD,IACtB,+CAA8CI,MAAM,CAACJ,YAAD,CAAe,GADtE;;AAEA,MAAMK,eAAe,GAAIL,YAAD,IACrB,gDAA+CI,MAAM,CAACJ,YAAD,CAAe,EADvE;;AAGA,MAAM;EAAEM,KAAF;EAASC,QAAT;EAAmBC,OAAnB;EAA4BC,UAA5B;EAAwCC,MAAxC;EAAgDC;AAAhD,IAA8D,IAAAC,wBAAA,EAClEf,sBADkE,EAElEQ,eAFkE,EAGlEF,gBAHkE,CAApE;;AAeO,MAAMU,yBAAyB,GACpCf,QADuC,KAEZ;EAC3BgB,iBAAiB,EAAER,KAAK,CAACR,QAAD,CADG;EAE3BiB,oBAAoB,EAAER,QAAQ,CAACT,QAAD,CAFH;EAG3BkB,mBAAmB,EAAER,OAAO,CAACV,QAAD,CAHD;EAI3BD,sBAAsB,EAAEY,UAAU,CAACX,QAAD,CAJP;EAK3BmB,kBAAkB,EAAEP,MAAM,CAACZ,QAAD,CALC;EAM3BoB,qBAAqB,EAAEP,SAAS,CAACb,QAAD;AANL,CAFY,CAAlC"}
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.bindByPlaceholderTextQueries = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
9
|
|
|
10
10
|
var _filterNodeByType = require("../helpers/filterNodeByType");
|
|
11
11
|
|
|
@@ -14,19 +14,11 @@ var _matches = require("../matches");
|
|
|
14
14
|
var _makeQueries = require("./makeQueries");
|
|
15
15
|
|
|
16
16
|
const getTextInputNodeByPlaceholderText = (node, placeholder, options = {}) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const {
|
|
23
|
-
exact,
|
|
24
|
-
normalizer
|
|
25
|
-
} = options;
|
|
26
|
-
return (0, _filterNodeByType.filterNodeByType)(node, TextInput) && (0, _matches.matches)(placeholder, node.props.placeholder, normalizer, exact);
|
|
27
|
-
} catch (error) {
|
|
28
|
-
throw (0, _errors.createLibraryNotSupportedError)(error);
|
|
29
|
-
}
|
|
17
|
+
const {
|
|
18
|
+
exact,
|
|
19
|
+
normalizer
|
|
20
|
+
} = options;
|
|
21
|
+
return (0, _filterNodeByType.filterNodeByType)(node, _reactNative.TextInput) && (0, _matches.matches)(placeholder, node.props.placeholder, normalizer, exact);
|
|
30
22
|
};
|
|
31
23
|
|
|
32
24
|
const queryAllByPlaceholderText = instance => function queryAllByPlaceholderFn(placeholder, queryOptions) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"placeholderText.js","names":["getTextInputNodeByPlaceholderText","node","placeholder","options","
|
|
1
|
+
{"version":3,"file":"placeholderText.js","names":["getTextInputNodeByPlaceholderText","node","placeholder","options","exact","normalizer","filterNodeByType","TextInput","matches","props","queryAllByPlaceholderText","instance","queryAllByPlaceholderFn","queryOptions","findAll","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByPlaceholderTextQueries","getByPlaceholderText","getAllByPlaceholderText","queryByPlaceholderText","findByPlaceholderText","findAllByPlaceholderText"],"sources":["../../src/queries/placeholderText.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { TextInput } from 'react-native';\nimport { filterNodeByType } from '../helpers/filterNodeByType';\nimport { matches, TextMatch } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\nimport type { TextMatchOptions } from './text';\n\nconst getTextInputNodeByPlaceholderText = (\n node: ReactTestInstance,\n placeholder: TextMatch,\n options: TextMatchOptions = {}\n) => {\n const { exact, normalizer } = options;\n return (\n filterNodeByType(node, TextInput) &&\n matches(placeholder, node.props.placeholder, normalizer, exact)\n );\n};\n\nconst queryAllByPlaceholderText = (\n instance: ReactTestInstance\n): ((\n placeholder: TextMatch,\n queryOptions?: TextMatchOptions\n) => Array<ReactTestInstance>) =>\n function queryAllByPlaceholderFn(placeholder, queryOptions) {\n return instance.findAll((node) =>\n getTextInputNodeByPlaceholderText(node, placeholder, queryOptions)\n );\n };\n\nconst getMultipleError = (placeholder: TextMatch) =>\n `Found multiple elements with placeholder: ${String(placeholder)} `;\nconst getMissingError = (placeholder: TextMatch) =>\n `Unable to find an element with placeholder: ${String(placeholder)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByPlaceholderText,\n getMissingError,\n getMultipleError\n);\n\nexport type ByPlaceholderTextQueries = {\n getByPlaceholderText: GetByQuery<TextMatch, TextMatchOptions>;\n getAllByPlaceholderText: GetAllByQuery<TextMatch, TextMatchOptions>;\n queryByPlaceholderText: QueryByQuery<TextMatch, TextMatchOptions>;\n queryAllByPlaceholderText: QueryAllByQuery<TextMatch, TextMatchOptions>;\n findByPlaceholderText: FindByQuery<TextMatch, TextMatchOptions>;\n findAllByPlaceholderText: FindAllByQuery<TextMatch, TextMatchOptions>;\n};\n\nexport const bindByPlaceholderTextQueries = (\n instance: ReactTestInstance\n): ByPlaceholderTextQueries => ({\n getByPlaceholderText: getBy(instance),\n getAllByPlaceholderText: getAllBy(instance),\n queryByPlaceholderText: queryBy(instance),\n queryAllByPlaceholderText: queryAllBy(instance),\n findByPlaceholderText: findBy(instance),\n findAllByPlaceholderText: findAllBy(instance),\n});\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AAWA,MAAMA,iCAAiC,GAAG,CACxCC,IADwC,EAExCC,WAFwC,EA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, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.bindByTextQueries = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
11
|
|
|
12
12
|
var _filterNodeByType = require("../helpers/filterNodeByType");
|
|
13
13
|
|
|
14
|
+
var _componentTree = require("../helpers/component-tree");
|
|
15
|
+
|
|
14
16
|
var _matches = require("../matches");
|
|
15
17
|
|
|
16
18
|
var _makeQueries = require("./makeQueries");
|
|
@@ -19,7 +21,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
19
21
|
|
|
20
22
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
23
|
|
|
22
|
-
const getChildrenAsText =
|
|
24
|
+
const getChildrenAsText = children => {
|
|
23
25
|
const textContent = [];
|
|
24
26
|
React.Children.forEach(children, child => {
|
|
25
27
|
if (typeof child === 'string') {
|
|
@@ -37,12 +39,12 @@ const getChildrenAsText = (children, TextComponent) => {
|
|
|
37
39
|
// has no text. In such situations, react-test-renderer will traverse down
|
|
38
40
|
// this tree in a separate call and run this query again. As a result, the
|
|
39
41
|
// query will match the deepest text node that matches requested text.
|
|
40
|
-
if ((0, _filterNodeByType.filterNodeByType)(child,
|
|
42
|
+
if ((0, _filterNodeByType.filterNodeByType)(child, _reactNative.Text)) {
|
|
41
43
|
return;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
if ((0, _filterNodeByType.filterNodeByType)(child, React.Fragment)) {
|
|
45
|
-
textContent.push(...getChildrenAsText(child.props.children
|
|
47
|
+
textContent.push(...getChildrenAsText(child.props.children));
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
});
|
|
@@ -50,34 +52,32 @@ const getChildrenAsText = (children, TextComponent) => {
|
|
|
50
52
|
};
|
|
51
53
|
|
|
52
54
|
const getNodeByText = (node, text, options = {}) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const {
|
|
66
|
-
exact,
|
|
67
|
-
normalizer
|
|
68
|
-
} = options;
|
|
69
|
-
return (0, _matches.matches)(text, textToTest, normalizer, exact);
|
|
70
|
-
}
|
|
55
|
+
const isTextComponent = (0, _filterNodeByType.filterNodeByType)(node, _reactNative.Text);
|
|
56
|
+
|
|
57
|
+
if (isTextComponent) {
|
|
58
|
+
const textChildren = getChildrenAsText(node.props.children);
|
|
59
|
+
|
|
60
|
+
if (textChildren) {
|
|
61
|
+
const textToTest = textChildren.join('');
|
|
62
|
+
const {
|
|
63
|
+
exact,
|
|
64
|
+
normalizer
|
|
65
|
+
} = options;
|
|
66
|
+
return (0, _matches.matches)(text, textToTest, normalizer, exact);
|
|
71
67
|
}
|
|
72
|
-
|
|
73
|
-
return false;
|
|
74
|
-
} catch (error) {
|
|
75
|
-
throw (0, _errors.createLibraryNotSupportedError)(error);
|
|
76
68
|
}
|
|
69
|
+
|
|
70
|
+
return false;
|
|
77
71
|
};
|
|
78
72
|
|
|
79
73
|
const queryAllByText = instance => function queryAllByTextFn(text, options) {
|
|
80
|
-
const
|
|
74
|
+
const baseInstance = (0, _componentTree.isHostElementForType)(instance, _reactNative.Text) ? (0, _componentTree.getCompositeParentOfType)(instance, _reactNative.Text) : instance;
|
|
75
|
+
|
|
76
|
+
if (!baseInstance) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const results = baseInstance.findAll(node => getNodeByText(node, text, options));
|
|
81
81
|
return results;
|
|
82
82
|
};
|
|
83
83
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","names":["getChildrenAsText","children","
|
|
1
|
+
{"version":3,"file":"text.js","names":["getChildrenAsText","children","textContent","React","Children","forEach","child","push","toString","props","filterNodeByType","Text","Fragment","getNodeByText","node","text","options","isTextComponent","textChildren","textToTest","join","exact","normalizer","matches","queryAllByText","instance","queryAllByTextFn","baseInstance","isHostElementForType","getCompositeParentOfType","results","findAll","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTextQueries","getByText","getAllByText","queryByText","findByText","findAllByText"],"sources":["../../src/queries/text.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { Text } from 'react-native';\nimport * as React from 'react';\nimport { filterNodeByType } from '../helpers/filterNodeByType';\nimport {\n isHostElementForType,\n getCompositeParentOfType,\n} from '../helpers/component-tree';\nimport { matches, TextMatch } from '../matches';\nimport type { NormalizerFn } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\nexport type TextMatchOptions = {\n exact?: boolean;\n normalizer?: NormalizerFn;\n};\n\nconst getChildrenAsText = (children: React.ReactChild[]) => {\n const textContent: string[] = [];\n React.Children.forEach(children, (child) => {\n if (typeof child === 'string') {\n textContent.push(child);\n return;\n }\n\n if (typeof child === 'number') {\n textContent.push(child.toString());\n return;\n }\n\n if (child?.props?.children) {\n // Bail on traversing text children down the tree if current node (child)\n // has no text. In such situations, react-test-renderer will traverse down\n // this tree in a separate call and run this query again. As a result, the\n // query will match the deepest text node that matches requested text.\n if (filterNodeByType(child, Text)) {\n return;\n }\n\n if (filterNodeByType(child, React.Fragment)) {\n textContent.push(...getChildrenAsText(child.props.children));\n }\n }\n });\n\n return textContent;\n};\n\nconst getNodeByText = (\n node: ReactTestInstance,\n text: TextMatch,\n options: TextMatchOptions = {}\n) => {\n const isTextComponent = filterNodeByType(node, Text);\n if (isTextComponent) {\n const textChildren = getChildrenAsText(node.props.children);\n if (textChildren) {\n const textToTest = textChildren.join('');\n const { exact, normalizer } = options;\n return matches(text, textToTest, normalizer, exact);\n }\n }\n return false;\n};\n\nconst queryAllByText = (\n instance: ReactTestInstance\n): ((\n text: TextMatch,\n options?: TextMatchOptions\n) => Array<ReactTestInstance>) =>\n function queryAllByTextFn(text, options) {\n const baseInstance = isHostElementForType(instance, Text)\n ? getCompositeParentOfType(instance, Text)\n : instance;\n\n if (!baseInstance) {\n return [];\n }\n\n const results = baseInstance.findAll((node) =>\n getNodeByText(node, text, options)\n );\n\n return results;\n };\n\nconst getMultipleError = (text: TextMatch) =>\n `Found multiple elements with text: ${String(text)}`;\nconst getMissingError = (text: TextMatch) =>\n `Unable to find an element with text: ${String(text)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByText,\n getMissingError,\n getMultipleError\n);\n\nexport type ByTextQueries = {\n getByText: GetByQuery<TextMatch, TextMatchOptions>;\n getAllByText: GetAllByQuery<TextMatch, TextMatchOptions>;\n queryByText: QueryByQuery<TextMatch, TextMatchOptions>;\n queryAllByText: QueryAllByQuery<TextMatch, TextMatchOptions>;\n findByText: FindByQuery<TextMatch, TextMatchOptions>;\n findAllByText: FindAllByQuery<TextMatch, TextMatchOptions>;\n};\n\nexport const bindByTextQueries = (\n instance: ReactTestInstance\n): ByTextQueries => ({\n getByText: getBy(instance),\n getAllByText: getAllBy(instance),\n queryByText: queryBy(instance),\n queryAllByText: queryAllBy(instance),\n findByText: findBy(instance),\n findAllByText: findAllBy(instance),\n});\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AAIA;;AAEA;;;;;;AAeA,MAAMA,iBAAiB,GAAIC,QAAD,IAAkC;EAC1D,MAAMC,WAAqB,GAAG,EAA9B;EACAC,KAAK,CAACC,QAAN,CAAeC,OAAf,CAAuBJ,QAAvB,EAAkCK,KAAD,IAAW;IAC1C,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;MAC7BJ,WAAW,CAACK,IAAZ,CAAiBD,KAAjB;MACA;IACD;;IAED,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;MAC7BJ,WAAW,CAACK,IAAZ,CAAiBD,KAAK,CAACE,QAAN,EAAjB;MACA;IACD;;IAED,IAAIF,KAAK,EAAEG,KAAP,EAAcR,QAAlB,EAA4B;MAC1B;MACA;MACA;MACA;MACA,IAAI,IAAAS,kCAAA,EAAiBJ,KAAjB,EAAwBK,iBAAxB,CAAJ,EAAmC;QACjC;MACD;;MAED,IAAI,IAAAD,kCAAA,EAAiBJ,KAAjB,EAAwBH,KAAK,CAACS,QAA9B,CAAJ,EAA6C;QAC3CV,WAAW,CAACK,IAAZ,CAAiB,GAAGP,iBAAiB,CAACM,KAAK,CAACG,KAAN,CAAYR,QAAb,CAArC;MACD;IACF;EACF,CAxBD;EA0BA,OAAOC,WAAP;AACD,CA7BD;;AA+BA,MAAMW,aAAa,GAAG,CACpBC,IADoB,EAEpBC,IAFoB,EAGpBC,OAAyB,GAAG,EAHR,KAIjB;EACH,MAAMC,eAAe,GAAG,IAAAP,kCAAA,EAAiBI,IAAjB,EAAuBH,iBAAvB,CAAxB;;EACA,IAAIM,eAAJ,EAAqB;IACnB,MAAMC,YAAY,GAAGlB,iBAAiB,CAACc,IAAI,CAACL,KAAL,CAAWR,QAAZ,CAAtC;;IACA,IAAIiB,YAAJ,EAAkB;MAChB,MAAMC,U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UAAU,CAACb,QAAD,CAJP;EAKnBqB,UAAU,EAAEP,MAAM,CAACd,QAAD,CALC;EAMnBsB,aAAa,EAAEP,SAAS,CAACf,QAAD;AANL,CAFY,CAA1B"}
|
package/build/waitFor.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.default = waitFor;
|
|
|
7
7
|
|
|
8
8
|
var _act = _interopRequireWildcard(require("./act"));
|
|
9
9
|
|
|
10
|
+
var _config = require("./config");
|
|
11
|
+
|
|
10
12
|
var _errors = require("./helpers/errors");
|
|
11
13
|
|
|
12
14
|
var _timers = require("./helpers/timers");
|
|
@@ -18,11 +20,10 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
18
20
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
21
|
|
|
20
22
|
/* globals jest */
|
|
21
|
-
const DEFAULT_TIMEOUT = 1000;
|
|
22
23
|
const DEFAULT_INTERVAL = 50;
|
|
23
24
|
|
|
24
25
|
function waitForInternal(expectation, {
|
|
25
|
-
timeout =
|
|
26
|
+
timeout = (0, _config.getConfig)().asyncUtilTimeout,
|
|
26
27
|
interval = DEFAULT_INTERVAL,
|
|
27
28
|
stackTraceError,
|
|
28
29
|
onTimeout
|
package/build/waitFor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitFor.js","names":["DEFAULT_TIMEOUT","DEFAULT_INTERVAL","waitForInternal","expectation","timeout","interval","stackTraceError","onTimeout","TypeError","Promise","resolve","reject","lastError","intervalId","finished","promiseStatus","overallTimeoutTimer","setTimeout","handleTimeout","usingFakeTimers","jestFakeTimersAreEnabled","checkExpectation","fakeTimeRemaining","error","Error","copyStackTrace","jest","advanceTimersByTime","setImmediate","setInterval","checkRealTimersCallback","onDone","done","clearTimeout","clearInterval","type","result","then","promiseResult","resolvedValue","rejectedValue","waitFor","options","ErrorWithStack","optionsWithStackTrace","checkReactVersionAtLeast","previousActEnvironment","getIsReactActEnvironment","setReactActEnvironment","act"],"sources":["../src/waitFor.ts"],"sourcesContent":["/* globals jest */\nimport act, { setReactActEnvironment, getIsReactActEnvironment } from './act';\nimport { ErrorWithStack, copyStackTrace } from './helpers/errors';\nimport {\n setTimeout,\n clearTimeout,\n setImmediate,\n jestFakeTimersAreEnabled,\n} from './helpers/timers';\nimport { checkReactVersionAtLeast } from './react-versions';\n\nconst DEFAULT_TIMEOUT = 1000;\nconst DEFAULT_INTERVAL = 50;\n\nexport type WaitForOptions = {\n timeout?: number;\n interval?: number;\n stackTraceError?: ErrorWithStack;\n onTimeout?: (error: unknown) => Error;\n};\n\nfunction waitForInternal<T>(\n expectation: () => T,\n {\n timeout = DEFAULT_TIMEOUT,\n interval = DEFAULT_INTERVAL,\n stackTraceError,\n onTimeout,\n }: WaitForOptions\n): Promise<T> {\n if (typeof expectation !== 'function') {\n throw new TypeError('Received `expectation` arg must be a function');\n }\n\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n let lastError: unknown, intervalId: ReturnType<typeof setTimeout>;\n let finished = false;\n let promiseStatus = 'idle';\n\n const overallTimeoutTimer = setTimeout(handleTimeout, timeout);\n\n const usingFakeTimers = jestFakeTimersAreEnabled();\n\n if (usingFakeTimers) {\n checkExpectation();\n // this is a dangerous rule to disable because it could lead to an\n // infinite loop. However, eslint isn't smart enough to know that we're\n // setting finished inside `onDone` which will be called when we're done\n // waiting or when we've timed out.\n // eslint-disable-next-line no-unmodified-loop-condition\n let fakeTimeRemaining = timeout;\n while (!finished) {\n if (!jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n reject(error);\n return;\n }\n\n // when fake timers are used we want to simulate the interval time passing\n if (fakeTimeRemaining <= 0) {\n return;\n } else {\n fakeTimeRemaining -= interval;\n }\n\n // we *could* (maybe should?) use `advanceTimersToNextTimer` but it's\n // possible that could make this loop go on forever if someone is using\n // third party code that's setting up recursive timers so rapidly that\n // the user's timer's don't get a chance to resolve. So we'll advance\n // by an interval instead. (We have a test for this case).\n jest.advanceTimersByTime(interval);\n\n // It's really important that checkExpectation is run *before* we flush\n // in-flight promises. To be honest, I'm not sure why, and I can't quite\n // think of a way to reproduce the problem in a test, but I spent\n // an entire day banging my head against a wall on this.\n checkExpectation();\n\n // In this rare case, we *need* to wait for in-flight promises\n // to resolve before continuing. We don't need to take advantage\n // of parallelization so we're fine.\n // https://stackoverflow.com/a/59243586/971592\n // eslint-disable-next-line no-await-in-loop\n await new Promise((resolve) => setImmediate(resolve));\n }\n } else {\n intervalId = setInterval(checkRealTimersCallback, interval);\n checkExpectation();\n }\n\n function onDone(\n done: { type: 'result'; result: T } | { type: 'error'; error: unknown }\n ) {\n finished = true;\n clearTimeout(overallTimeoutTimer);\n\n if (!usingFakeTimers) {\n clearInterval(intervalId);\n }\n\n if (done.type === 'error') {\n reject(done.error);\n } else {\n resolve(done.result);\n }\n }\n\n function checkRealTimersCallback() {\n if (jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n return reject(error);\n } else {\n return checkExpectation();\n }\n }\n\n function checkExpectation() {\n if (promiseStatus === 'pending') return;\n try {\n const result = expectation();\n\n // @ts-ignore result can be a promise\n // eslint-disable-next-line promise/prefer-await-to-then\n if (typeof result?.then === 'function') {\n const promiseResult: Promise<T> = result as any;\n promiseStatus = 'pending';\n // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then\n promiseResult.then(\n (resolvedValue) => {\n promiseStatus = 'resolved';\n onDone({ type: 'result', result: resolvedValue });\n return;\n },\n (rejectedValue) => {\n promiseStatus = 'rejected';\n lastError = rejectedValue;\n return;\n }\n );\n } else {\n onDone({ type: 'result', result: result });\n }\n // If `callback` throws, wait for the next mutation, interval, or timeout.\n } catch (error) {\n // Save the most recent callback error to reject the promise with it in the event of a timeout\n lastError = error;\n }\n }\n\n function handleTimeout() {\n let error;\n if (lastError) {\n error = lastError;\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n } else {\n error = new Error('Timed out in waitFor.');\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n }\n if (typeof onTimeout === 'function') {\n onTimeout(error);\n }\n onDone({ type: 'error', error });\n }\n });\n}\n\nexport default async function waitFor<T>(\n expectation: () => T,\n options?: WaitForOptions\n): Promise<T> {\n // Being able to display a useful stack trace requires generating it before doing anything async\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', waitFor);\n const optionsWithStackTrace = { stackTraceError, ...options };\n\n if (checkReactVersionAtLeast(18, 0)) {\n const previousActEnvironment = getIsReactActEnvironment();\n setReactActEnvironment(false);\n\n try {\n return await waitForInternal(expectation, optionsWithStackTrace);\n } finally {\n setReactActEnvironment(previousActEnvironment);\n }\n }\n\n if (!checkReactVersionAtLeast(16, 9)) {\n return waitForInternal(expectation, optionsWithStackTrace);\n }\n\n let result: T;\n\n await act(async () => {\n result = await waitForInternal(expectation, optionsWithStackTrace);\n });\n\n // Either we have result or `waitFor` threw error\n return result!;\n}\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AAMA;;;;;;AATA;AAWA,MAAMA,eAAe,GAAG,IAAxB;AACA,MAAMC,gBAAgB,GAAG,EAAzB;;AASA,SAASC,eAAT,CACEC,WADF,EAEE;EACEC,OAAO,GAAGJ,eADZ;EAEEK,QAAQ,GAAGJ,gBAFb;EAGEK,eAHF;EAIEC;AAJF,CAFF,EAQc;EACZ,IAAI,OAAOJ,WAAP,KAAuB,UAA3B,EAAuC;IACrC,MAAM,IAAIK,SAAJ,CAAc,+CAAd,CAAN;EACD,CAHW,CAKZ;;;EACA,OAAO,IAAIC,OAAJ,CAAY,OAAOC,OAAP,EAAgBC,MAAhB,KAA2B;IAC5C,IAAIC,SAAJ,EAAwBC,UAAxB;IACA,IAAIC,QAAQ,GAAG,KAAf;IACA,IAAIC,aAAa,GAAG,MAApB;IAEA,MAAMC,mBAAmB,GAAG,IAAAC,kBAAA,EAAWC,aAAX,EAA0Bd,OAA1B,CAA5B;IAEA,MAAMe,eAAe,GAAG,IAAAC,gCAAA,GAAxB;;IAEA,IAAID,eAAJ,EAAqB;MACnBE,gBAAgB,GADG,CAEnB;MACA;MACA;MACA;MACA;;MACA,IAAIC,iBAAiB,GAAGlB,OAAxB;;MACA,OAAO,CAACU,QAAR,EAAkB;QAChB,IAAI,CAAC,IAAAM,gCAAA,GAAL,EAAiC;UAC/B,MAAMG,KAAK,GAAG,IAAIC,KAAJ,CACX,kUADW,CAAd;;UAGA,IAAIlB,eAAJ,EAAqB;YACnB,IAAAmB,sBAAA,EAAeF,KAAf,EAAsBjB,eAAtB;UACD;;UACDK,MAAM,CAACY,KAAD,CAAN;UACA;QACD,CAVe,CAYhB;;;QACA,IAAID,iBAAiB,IAAI,CAAzB,EAA4B;UAC1B;QACD,CAFD,MAEO;UACLA,iBAAiB,IAAIjB,QAArB;QACD,CAjBe,CAmBhB;QACA;QACA;Q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,IAAAG,uCAAA,EAAyB,EAAzB,EAA6B,CAA7B,CAAJ,EAAqC;IACnC,MAAMC,sBAAsB,GAAG,IAAAC,6BAAA,GAA/B;IACA,IAAAC,2BAAA,EAAuB,KAAvB;;IAEA,IAAI;MACF,OAAO,MAAM9C,eAAe,CAACC,WAAD,EAAcyC,qBAAd,CAA5B;IACD,CAFD,SAEU;MACR,IAAAI,2BAAA,EAAuBF,sBAAvB;IACD;EACF;;EAED,IAAI,CAAC,IAAAD,uCAAA,EAAyB,EAAzB,EAA6B,CAA7B,CAAL,EAAsC;IACpC,OAAO3C,eAAe,CAACC,WAAD,EAAcyC,qBAAd,CAAtB;EACD;;EAED,IAAIR,MAAJ;EAEA,MAAM,IAAAa,YAAA,EAAI,YAAY;IACpBb,MAAM,GAAG,MAAMlC,eAAe,CAACC,WAAD,EAAcyC,qBAAd,CAA9B;EACD,CAFK,CAAN,CAtBY,CA0BZ;;EACA,OAAOR,MAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"waitFor.js","names":["DEFAULT_INTERVAL","waitForInternal","expectation","timeout","getConfig","asyncUtilTimeout","interval","stackTraceError","onTimeout","TypeError","Promise","resolve","reject","lastError","intervalId","finished","promiseStatus","overallTimeoutTimer","setTimeout","handleTimeout","usingFakeTimers","jestFakeTimersAreEnabled","checkExpectation","fakeTimeRemaining","error","Error","copyStackTrace","jest","advanceTimersByTime","setImmediate","setInterval","checkRealTimersCallback","onDone","done","clearTimeout","clearInterval","type","result","then","promiseResult","resolvedValue","rejectedValue","waitFor","options","ErrorWithStack","optionsWithStackTrace","checkReactVersionAtLeast","previousActEnvironment","getIsReactActEnvironment","setReactActEnvironment","act"],"sources":["../src/waitFor.ts"],"sourcesContent":["/* globals jest */\nimport act, { setReactActEnvironment, getIsReactActEnvironment } from './act';\nimport { getConfig } from './config';\nimport { ErrorWithStack, copyStackTrace } from './helpers/errors';\nimport {\n setTimeout,\n clearTimeout,\n setImmediate,\n jestFakeTimersAreEnabled,\n} from './helpers/timers';\nimport { checkReactVersionAtLeast } from './react-versions';\n\nconst DEFAULT_INTERVAL = 50;\n\nexport type WaitForOptions = {\n timeout?: number;\n interval?: number;\n stackTraceError?: ErrorWithStack;\n onTimeout?: (error: unknown) => Error;\n};\n\nfunction waitForInternal<T>(\n expectation: () => T,\n {\n timeout = getConfig().asyncUtilTimeout,\n interval = DEFAULT_INTERVAL,\n stackTraceError,\n onTimeout,\n }: WaitForOptions\n): Promise<T> {\n if (typeof expectation !== 'function') {\n throw new TypeError('Received `expectation` arg must be a function');\n }\n\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n let lastError: unknown, intervalId: ReturnType<typeof setTimeout>;\n let finished = false;\n let promiseStatus = 'idle';\n\n const overallTimeoutTimer = setTimeout(handleTimeout, timeout);\n\n const usingFakeTimers = jestFakeTimersAreEnabled();\n\n if (usingFakeTimers) {\n checkExpectation();\n // this is a dangerous rule to disable because it could lead to an\n // infinite loop. However, eslint isn't smart enough to know that we're\n // setting finished inside `onDone` which will be called when we're done\n // waiting or when we've timed out.\n // eslint-disable-next-line no-unmodified-loop-condition\n let fakeTimeRemaining = timeout;\n while (!finished) {\n if (!jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n reject(error);\n return;\n }\n\n // when fake timers are used we want to simulate the interval time passing\n if (fakeTimeRemaining <= 0) {\n return;\n } else {\n fakeTimeRemaining -= interval;\n }\n\n // we *could* (maybe should?) use `advanceTimersToNextTimer` but it's\n // possible that could make this loop go on forever if someone is using\n // third party code that's setting up recursive timers so rapidly that\n // the user's timer's don't get a chance to resolve. So we'll advance\n // by an interval instead. (We have a test for this case).\n jest.advanceTimersByTime(interval);\n\n // It's really important that checkExpectation is run *before* we flush\n // in-flight promises. To be honest, I'm not sure why, and I can't quite\n // think of a way to reproduce the problem in a test, but I spent\n // an entire day banging my head against a wall on this.\n checkExpectation();\n\n // In this rare case, we *need* to wait for in-flight promises\n // to resolve before continuing. We don't need to take advantage\n // of parallelization so we're fine.\n // https://stackoverflow.com/a/59243586/971592\n // eslint-disable-next-line no-await-in-loop\n await new Promise((resolve) => setImmediate(resolve));\n }\n } else {\n intervalId = setInterval(checkRealTimersCallback, interval);\n checkExpectation();\n }\n\n function onDone(\n done: { type: 'result'; result: T } | { type: 'error'; error: unknown }\n ) {\n finished = true;\n clearTimeout(overallTimeoutTimer);\n\n if (!usingFakeTimers) {\n clearInterval(intervalId);\n }\n\n if (done.type === 'error') {\n reject(done.error);\n } else {\n resolve(done.result);\n }\n }\n\n function checkRealTimersCallback() {\n if (jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n return reject(error);\n } else {\n return checkExpectation();\n }\n }\n\n function checkExpectation() {\n if (promiseStatus === 'pending') return;\n try {\n const result = expectation();\n\n // @ts-ignore result can be a promise\n // eslint-disable-next-line promise/prefer-await-to-then\n if (typeof result?.then === 'function') {\n const promiseResult: Promise<T> = result as any;\n promiseStatus = 'pending';\n // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then\n promiseResult.then(\n (resolvedValue) => {\n promiseStatus = 'resolved';\n onDone({ type: 'result', result: resolvedValue });\n return;\n },\n (rejectedValue) => {\n promiseStatus = 'rejected';\n lastError = rejectedValue;\n return;\n }\n );\n } else {\n onDone({ type: 'result', result: result });\n }\n // If `callback` throws, wait for the next mutation, interval, or timeout.\n } catch (error) {\n // Save the most recent callback error to reject the promise with it in the event of a timeout\n lastError = error;\n }\n }\n\n function handleTimeout() {\n let error;\n if (lastError) {\n error = lastError;\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n } else {\n error = new Error('Timed out in waitFor.');\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n }\n if (typeof onTimeout === 'function') {\n onTimeout(error);\n }\n onDone({ type: 'error', error });\n }\n });\n}\n\nexport default async function waitFor<T>(\n expectation: () => T,\n options?: WaitForOptions\n): Promise<T> {\n // Being able to display a useful stack trace requires generating it before doing anything async\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', waitFor);\n const optionsWithStackTrace = { stackTraceError, ...options };\n\n if (checkReactVersionAtLeast(18, 0)) {\n const previousActEnvironment = getIsReactActEnvironment();\n setReactActEnvironment(false);\n\n try {\n return await waitForInternal(expectation, optionsWithStackTrace);\n } finally {\n setReactActEnvironment(previousActEnvironment);\n }\n }\n\n if (!checkReactVersionAtLeast(16, 9)) {\n return waitForInternal(expectation, optionsWithStackTrace);\n }\n\n let result: T;\n\n await act(async () => {\n result = await waitForInternal(expectation, optionsWithStackTrace);\n });\n\n // Either we have result or `waitFor` threw error\n return result!;\n}\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AAMA;;;;;;AAVA;AAYA,MAAMA,gBAAgB,GAAG,EAAzB;;AASA,SAASC,eAAT,CACEC,WADF,EAEE;EACEC,OAAO,GAAG,IAAAC,iBAAA,IAAYC,gBADxB;EAEEC,QAAQ,GAAGN,gBAFb;EAGEO,eAHF;EAIEC;AAJF,CAFF,EAQc;EACZ,IAAI,OAAON,WAAP,KAAuB,UAA3B,EAAuC;IACrC,MAAM,IAAIO,SAAJ,CAAc,+CAAd,CAAN;EACD,CAHW,CAKZ;;;EACA,OAAO,IAAIC,OAAJ,CAAY,OAAOC,OAAP,EAAgBC,MAAhB,KAA2B;IAC5C,IAAIC,SAAJ,EAAwBC,UAAxB;IACA,IAAIC,QAAQ,GAAG,KAAf;IACA,IAAIC,aAAa,GAAG,MAApB;IAEA,MAAMC,mBAAmB,GAAG,IAAAC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6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testing-library/react-native",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.3.0",
|
|
4
4
|
"description": "Simple and complete React Native testing utilities that encourage good testing practices.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"dont-cleanup-after-each.js"
|
|
27
27
|
],
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@babel/cli": "^7.
|
|
30
|
-
"@babel/core": "^7.
|
|
31
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
32
|
-
"@babel/plugin-transform-flow-strip-types": "^7.
|
|
33
|
-
"@babel/preset-env": "^7.
|
|
34
|
-
"@babel/preset-flow": "^7.
|
|
35
|
-
"@babel/preset-react": "^7.
|
|
36
|
-
"@babel/preset-typescript": "^7.
|
|
29
|
+
"@babel/cli": "^7.18.10",
|
|
30
|
+
"@babel/core": "^7.19.1",
|
|
31
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
32
|
+
"@babel/plugin-transform-flow-strip-types": "^7.19.0",
|
|
33
|
+
"@babel/preset-env": "^7.19.1",
|
|
34
|
+
"@babel/preset-flow": "^7.18.6",
|
|
35
|
+
"@babel/preset-react": "^7.18.6",
|
|
36
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
37
37
|
"@callstack/eslint-config": "^13.0.1",
|
|
38
|
-
"@testing-library/jest-native": "
|
|
38
|
+
"@testing-library/jest-native": "^5.0.0",
|
|
39
39
|
"@types/jest": "^29.0.2",
|
|
40
40
|
"@types/react": "~18.0.18",
|
|
41
41
|
"@types/react-native": "~0.70.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"flow-copy-source": "^2.0.9",
|
|
50
50
|
"jest": "^29.0.3",
|
|
51
51
|
"react": "18.1.0",
|
|
52
|
-
"react-native": "0.70.
|
|
52
|
+
"react-native": "0.70.3",
|
|
53
53
|
"react-test-renderer": "18.1.0",
|
|
54
54
|
"strip-ansi": "^6.0.0",
|
|
55
55
|
"typescript": "^4.0.2"
|
package/typings/index.flow.js
CHANGED
|
@@ -346,6 +346,7 @@ declare module '@testing-library/react-native' {
|
|
|
346
346
|
declare interface RenderOptions {
|
|
347
347
|
wrapper?: React.ComponentType<any>;
|
|
348
348
|
createNodeMock?: (element: React.Element<any>) => any;
|
|
349
|
+
unstable_validateStringsRenderedWithinText?: boolean;
|
|
349
350
|
}
|
|
350
351
|
|
|
351
352
|
declare export var render: (
|
|
@@ -367,6 +368,13 @@ declare module '@testing-library/react-native' {
|
|
|
367
368
|
|
|
368
369
|
declare export var waitForElementToBeRemoved: WaitForElementToBeRemovedFunction;
|
|
369
370
|
|
|
371
|
+
declare interface Config {
|
|
372
|
+
asyncUtilTimeout: number;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
declare export var configure: (options: $Shape<Config>) => void;
|
|
376
|
+
declare export var resetToDefaults: () => void;
|
|
377
|
+
|
|
370
378
|
declare export var act: (callback: () => void) => Thenable;
|
|
371
379
|
declare export var within: (instance: ReactTestInstance) => Queries;
|
|
372
380
|
declare export var getQueriesForElement: (
|