@testing-library/react-native 11.1.0 → 11.2.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/act.d.ts +8 -3
- package/build/act.js +73 -2
- package/build/act.js.map +1 -1
- package/build/fireEvent.js +3 -5
- package/build/fireEvent.js.map +1 -1
- package/build/helpers/accessiblity.d.ts +2 -0
- package/build/helpers/accessiblity.js +60 -0
- package/build/helpers/accessiblity.js.map +1 -0
- package/build/helpers/component-tree.d.ts +29 -0
- package/build/helpers/component-tree.js +90 -0
- package/build/helpers/component-tree.js.map +1 -0
- package/build/helpers/stringValidation.d.ts +2 -0
- package/build/helpers/stringValidation.js +38 -0
- package/build/helpers/stringValidation.js.map +1 -0
- package/build/index.flow.js +20 -4
- package/build/index.js +27 -11
- package/build/index.js.map +1 -1
- package/build/pure.d.ts +2 -0
- package/build/pure.js +8 -0
- package/build/pure.js.map +1 -1
- package/build/queries/role.d.ts +10 -6
- package/build/queries/role.js +13 -2
- package/build/queries/role.js.map +1 -1
- package/build/react-versions.d.ts +1 -0
- package/build/react-versions.js +19 -0
- package/build/react-versions.js.map +1 -0
- package/build/render.d.ts +20 -7
- package/build/render.js +37 -1
- package/build/render.js.map +1 -1
- package/build/waitFor.js +14 -11
- package/build/waitFor.js.map +1 -1
- package/build/within.d.ts +18 -6
- package/package.json +2 -1
- package/typings/index.flow.js +20 -4
package/build/act.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
declare global {
|
|
2
|
+
var IS_REACT_ACT_ENVIRONMENT: boolean | undefined;
|
|
3
|
+
}
|
|
4
|
+
declare function setIsReactActEnvironment(isReactActEnvironment: boolean | undefined): void;
|
|
5
|
+
declare function getIsReactActEnvironment(): boolean | undefined;
|
|
6
|
+
declare const act: (callback: () => void) => void;
|
|
7
|
+
export default act;
|
|
8
|
+
export { setIsReactActEnvironment as setReactActEnvironment, getIsReactActEnvironment, };
|
package/build/act.js
CHANGED
|
@@ -4,14 +4,85 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
exports.getIsReactActEnvironment = getIsReactActEnvironment;
|
|
8
|
+
exports.setReactActEnvironment = setIsReactActEnvironment;
|
|
7
9
|
|
|
8
10
|
var _reactTestRenderer = require("react-test-renderer");
|
|
9
11
|
|
|
12
|
+
var _reactVersions = require("./react-versions");
|
|
13
|
+
|
|
14
|
+
// This file and the act() implementation is sourced from react-testing-library
|
|
15
|
+
// https://github.com/testing-library/react-testing-library/blob/c80809a956b0b9f3289c4a6fa8b5e8cc72d6ef6d/src/act-compat.js
|
|
10
16
|
const actMock = callback => {
|
|
11
17
|
callback();
|
|
12
|
-
};
|
|
18
|
+
}; // See https://github.com/reactwg/react-18/discussions/102 for more context on global.IS_REACT_ACT_ENVIRONMENT
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
function setIsReactActEnvironment(isReactActEnvironment) {
|
|
22
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getIsReactActEnvironment() {
|
|
26
|
+
return globalThis.IS_REACT_ACT_ENVIRONMENT;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function withGlobalActEnvironment(actImplementation) {
|
|
30
|
+
return callback => {
|
|
31
|
+
const previousActEnvironment = getIsReactActEnvironment();
|
|
32
|
+
setIsReactActEnvironment(true); // this code is riddled with eslint disabling comments because this doesn't use real promises but eslint thinks we do
|
|
13
33
|
|
|
14
|
-
|
|
34
|
+
try {
|
|
35
|
+
// The return value of `act` is always a thenable.
|
|
36
|
+
let callbackNeedsToBeAwaited = false;
|
|
37
|
+
const actResult = actImplementation(() => {
|
|
38
|
+
const result = callback();
|
|
39
|
+
|
|
40
|
+
if (result !== null && typeof result === 'object' && // @ts-expect-error this should be a promise or thenable
|
|
41
|
+
// eslint-disable-next-line promise/prefer-await-to-then
|
|
42
|
+
typeof result.then === 'function') {
|
|
43
|
+
callbackNeedsToBeAwaited = true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return result;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (callbackNeedsToBeAwaited) {
|
|
50
|
+
const thenable = actResult;
|
|
51
|
+
return {
|
|
52
|
+
then: (resolve, reject) => {
|
|
53
|
+
// eslint-disable-next-line
|
|
54
|
+
thenable.then( // eslint-disable-next-line promise/always-return
|
|
55
|
+
returnValue => {
|
|
56
|
+
setIsReactActEnvironment(previousActEnvironment);
|
|
57
|
+
resolve(returnValue);
|
|
58
|
+
}, error => {
|
|
59
|
+
setIsReactActEnvironment(previousActEnvironment);
|
|
60
|
+
reject(error);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
} else {
|
|
65
|
+
setIsReactActEnvironment(previousActEnvironment);
|
|
66
|
+
return actResult;
|
|
67
|
+
}
|
|
68
|
+
} catch (error) {
|
|
69
|
+
// Can't be a `finally {}` block since we don't know if we have to immediately restore IS_REACT_ACT_ENVIRONMENT
|
|
70
|
+
// or if we have to await the callback first.
|
|
71
|
+
setIsReactActEnvironment(previousActEnvironment);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const getAct = () => {
|
|
78
|
+
if (!_reactTestRenderer.act) {
|
|
79
|
+
return actMock;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return (0, _reactVersions.checkReactVersionAtLeast)(18, 0) ? withGlobalActEnvironment(_reactTestRenderer.act) : _reactTestRenderer.act;
|
|
83
|
+
};
|
|
15
84
|
|
|
85
|
+
const act = getAct();
|
|
86
|
+
var _default = act;
|
|
16
87
|
exports.default = _default;
|
|
17
88
|
//# sourceMappingURL=act.js.map
|
package/build/act.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"act.js","names":["actMock","callback","act"],"sources":["../src/act.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"act.js","names":["actMock","callback","setIsReactActEnvironment","isReactActEnvironment","globalThis","IS_REACT_ACT_ENVIRONMENT","getIsReactActEnvironment","withGlobalActEnvironment","actImplementation","previousActEnvironment","callbackNeedsToBeAwaited","actResult","result","then","thenable","resolve","reject","returnValue","error","getAct","reactTestRendererAct","checkReactVersionAtLeast","act"],"sources":["../src/act.ts"],"sourcesContent":["// This file and the act() implementation is sourced from react-testing-library\n// https://github.com/testing-library/react-testing-library/blob/c80809a956b0b9f3289c4a6fa8b5e8cc72d6ef6d/src/act-compat.js\nimport { act as reactTestRendererAct } from 'react-test-renderer';\nimport { checkReactVersionAtLeast } from './react-versions';\n\nconst actMock = (callback: () => void) => {\n callback();\n};\n\n// See https://github.com/reactwg/react-18/discussions/102 for more context on global.IS_REACT_ACT_ENVIRONMENT\ndeclare global {\n var IS_REACT_ACT_ENVIRONMENT: boolean | undefined;\n}\n\nfunction setIsReactActEnvironment(isReactActEnvironment: boolean | undefined) {\n globalThis.IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment;\n}\n\nfunction getIsReactActEnvironment() {\n return globalThis.IS_REACT_ACT_ENVIRONMENT;\n}\n\ntype Act = typeof reactTestRendererAct;\n\nfunction withGlobalActEnvironment(actImplementation: Act) {\n return (callback: Parameters<Act>[0]) => {\n const previousActEnvironment = getIsReactActEnvironment();\n setIsReactActEnvironment(true);\n\n // this code is riddled with eslint disabling comments because this doesn't use real promises but eslint thinks we do\n try {\n // The return value of `act` is always a thenable.\n let callbackNeedsToBeAwaited = false;\n const actResult = actImplementation(() => {\n const result = callback();\n if (\n result !== null &&\n typeof result === 'object' &&\n // @ts-expect-error this should be a promise or thenable\n // eslint-disable-next-line promise/prefer-await-to-then\n typeof result.then === 'function'\n ) {\n callbackNeedsToBeAwaited = true;\n }\n return result;\n });\n if (callbackNeedsToBeAwaited) {\n const thenable = actResult;\n return {\n then: (\n resolve: (value: never) => never,\n reject: (value: never) => never\n ) => {\n // eslint-disable-next-line\n thenable.then(\n // eslint-disable-next-line promise/always-return\n (returnValue) => {\n setIsReactActEnvironment(previousActEnvironment);\n resolve(returnValue);\n },\n (error) => {\n setIsReactActEnvironment(previousActEnvironment);\n reject(error);\n }\n );\n },\n };\n } else {\n setIsReactActEnvironment(previousActEnvironment);\n return actResult;\n }\n } catch (error) {\n // Can't be a `finally {}` block since we don't know if we have to immediately restore IS_REACT_ACT_ENVIRONMENT\n // or if we have to await the callback first.\n setIsReactActEnvironment(previousActEnvironment);\n throw error;\n }\n };\n}\nconst getAct = () => {\n if (!reactTestRendererAct) {\n return actMock;\n }\n\n return checkReactVersionAtLeast(18, 0)\n ? withGlobalActEnvironment(reactTestRendererAct)\n : reactTestRendererAct;\n};\nconst act = getAct();\n\nexport default act;\nexport {\n setIsReactActEnvironment as setReactActEnvironment,\n getIsReactActEnvironment,\n};\n"],"mappings":";;;;;;;;;AAEA;;AACA;;AAHA;AACA;AAIA,MAAMA,OAAO,GAAIC,QAAD,IAA0B;EACxCA,QAAQ;AACT,CAFD,C,CAIA;;;AAKA,SAASC,wBAAT,CAAkCC,qBAAlC,EAA8E;EAC5EC,UAAU,CAACC,wBAAX,GAAsCF,qBAAtC;AACD;;AAED,SAASG,wBAAT,GAAoC;EAClC,OAAOF,UAAU,CAACC,wBAAlB;AACD;;AAID,SAASE,wBAAT,CAAkCC,iBAAlC,EAA0D;EACxD,OAAQP,QAAD,IAAkC;IACvC,MAAMQ,sBAAsB,GAAGH,wBAAwB,EAAvD;IACAJ,wBAAwB,CAAC,IAAD,CAAxB,CAFuC,CAIvC;;IACA,IAAI;MACF;MACA,IAAIQ,wBAAwB,GAAG,KAA/B;MACA,MAAMC,SAAS,GAAGH,iBAAiB,CAAC,MAAM;QACxC,MAAMI,MAAM,GAAGX,QAAQ,EAAvB;;QACA,IACEW,MAAM,KAAK,IAAX,IACA,OAAOA,MAAP,KAAkB,QADlB,IAEA;QACA;QACA,OAAOA,MAAM,CAACC,IAAd,KAAuB,UALzB,EAME;UACAH,wBAAwB,GAAG,IAA3B;QACD;;QACD,OAAOE,MAAP;MACD,CAZkC,CAAnC;;MAaA,IAAIF,wBAAJ,EAA8B;QAC5B,MAAMI,QAAQ,GAAGH,SAAjB;QACA,OAAO;UACLE,IAAI,EAAE,CACJE,OADI,EAEJC,MAFI,KAGD;YACH;YACAF,QAAQ,CAACD,IAAT,EACE;YACCI,WAAD,IAAiB;cACff,wBAAwB,CAACO,sBAAD,CAAxB;cACAM,OAAO,CAACE,WAAD,CAAP;YACD,CALH,EAMGC,KAAD,IAAW;cACThB,wBAAwB,CAACO,sBAAD,CAAxB;cACAO,MAAM,CAACE,KAAD,CAAN;YACD,CATH;UAWD;QAjBI,CAAP;MAmBD,CArBD,MAqBO;QACLhB,wBAAwB,CAACO,sBAAD,CAAxB;QACA,OAAOE,SAAP;MACD;IACF,CAzCD,CAyCE,OAAOO,KAAP,EAAc;MACd;MACA;MACAhB,wBAAwB,CAACO,sBAAD,CAAxB;MACA,MAAMS,KAAN;IACD;EACF,CApDD;AAqDD;;AACD,MAAMC,MAAM,GAAG,MAAM;EACnB,IAAI,CAACC,sBAAL,EAA2B;IACzB,OAAOpB,OAAP;EACD;;EAED,OAAO,IAAAqB,uCAAA,EAAyB,EAAzB,EAA6B,CAA7B,IACHd,wBAAwB,CAACa,sBAAD,CADrB,GAEHA,sBAFJ;AAGD,CARD;;AASA,MAAME,GAAG,GAAGH,MAAM,EAAlB;eAEeG,G"}
|
package/build/fireEvent.js
CHANGED
|
@@ -7,14 +7,12 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _act = _interopRequireDefault(require("./act"));
|
|
9
9
|
|
|
10
|
+
var _componentTree = require("./helpers/component-tree");
|
|
11
|
+
|
|
10
12
|
var _filterNodeByType = require("./helpers/filterNodeByType");
|
|
11
13
|
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
15
|
|
|
14
|
-
const isHostElement = element => {
|
|
15
|
-
return typeof element?.type === 'string';
|
|
16
|
-
};
|
|
17
|
-
|
|
18
16
|
const isTextInput = element => {
|
|
19
17
|
if (!element) {
|
|
20
18
|
return false;
|
|
@@ -34,7 +32,7 @@ const isTextInput = element => {
|
|
|
34
32
|
};
|
|
35
33
|
|
|
36
34
|
const isTouchResponder = element => {
|
|
37
|
-
if (!isHostElement(element)) return false;
|
|
35
|
+
if (!(0, _componentTree.isHostElement)(element)) return false;
|
|
38
36
|
return !!element?.props.onStartShouldSetResponder || isTextInput(element);
|
|
39
37
|
};
|
|
40
38
|
|
package/build/fireEvent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fireEvent.js","names":["
|
|
1
|
+
{"version":3,"file":"fireEvent.js","names":["isTextInput","element","TextInput","require","filterNodeByType","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 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 const { TextInput } = require('react-native');\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;;;;AAIA,MAAMA,WAAW,GAAIC,OAAD,IAAiC;EACnD,IAAI,CAACA,OAAL,EAAc;IACZ,OAAO,KAAP;EACD;;EAED,MAAM;IAAEC;EAAF,IAAgBC,OAAO,CAAC,cAAD,CAA7B,CALmD,CAMnD;EACA;EACA;EACA;EACA;EACA;;;EACA,OACE,IAAAC,kCAAA,EAAiBH,OAAjB,EAA0BC,SAA1B,KACA,IAAAE,kCAAA,EAAiBH,OAAjB,EAA0B,WAA1B,CAFF;AAID,CAhBD;;AAkBA,MAAMI,gBAAgB,GAAIJ,OAAD,IAAiC;EACxD,IAAI,CAAC,IAAAK,4BAAA,EAAcL,OAAd,CAAL,EAA6B,OAAO,KAAP;EAE7B,OAAO,CAAC,CAACA,OAAO,EAAEM,KAAT,CAAeC,yBAAjB,IAA8CR,WAAW,CAACC,OAAD,CAAhE;AACD,CAJD;;AAMA,MAAMQ,qBAAqB,GAAG,CAC5BR,OAD4B,EAE5BS,QAF4B,KAGhB;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AAS,CAACmB,MAAV,CAAiB,CAAjB,EAAoBC,WAApB,EAAkC,GAAEpB,SAAS,CAACqB,KAAV,CAAgB,CAAhB,CAAmB,EAD9D;;AAGA,MAAMC,YAAY,GAAG,CAACpC,OAAD,EAA6B,GAAG8B,IAAhC,KACnBD,WAAW,CAAC7B,OAAD,EAAU,OAAV,EAAmBoC,YAAnB,EAAiC,GAAGN,IAApC,CADb;;AAEA,MAAMO,iBAAiB,GAAG,CACxBrC,OADwB,EAExB,GAAG8B,IAFqB,KAGfD,WAAW,CAAC7B,OAAD,EAAU,YAAV,EAAwBqC,iBAAxB,EAA2C,GAAGP,IAA9C,CAHtB;;AAIA,MAAMQ,aAAa,GAAG,CAACtC,OAAD,EAA6B,GAAG8B,IAAhC,KACpBD,WAAW,CAAC7B,OAAD,EAAU,QAAV,EAAoBsC,aAApB,EAAmC,GAAGR,IAAtC,CADb;;AAGA,MAAMS,SAAS,GAAG,CAChBvC,OADgB,EAEhBc,SAFgB,EAGhB,GAAGgB,IAHa,KAIPD,WAAW,CAAC7B,OAAD,EAAUc,SAAV,EAAqByB,SAArB,EAAgC,GAAGT,IAAnC,CAJtB;;AAMAS,SAAS,CAACC,KAAV,GAAkBJ,YAAlB;AACAG,SAAS,CAACE,UAAV,GAAuBJ,iBAAvB;AACAE,SAAS,CAACG,MAAV,GAAmBJ,aAAnB;eAEeC,S"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isInaccessible = isInaccessible;
|
|
7
|
+
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
|
|
10
|
+
var _componentTree = require("./component-tree");
|
|
11
|
+
|
|
12
|
+
function isInaccessible(element) {
|
|
13
|
+
if (element == null) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let current = element;
|
|
18
|
+
|
|
19
|
+
while (current) {
|
|
20
|
+
if (isSubtreeInaccessible(current)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
current = current.parent;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isSubtreeInaccessible(element) {
|
|
31
|
+
if (element == null) {
|
|
32
|
+
return true;
|
|
33
|
+
} // iOS: accessibilityElementsHidden
|
|
34
|
+
// See: https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if (element.props.accessibilityElementsHidden) {
|
|
38
|
+
return true;
|
|
39
|
+
} // Android: importantForAccessibility
|
|
40
|
+
// See: https://reactnative.dev/docs/accessibility#importantforaccessibility-android
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if (element.props.importantForAccessibility === 'no-hide-descendants') {
|
|
44
|
+
return true;
|
|
45
|
+
} // Note that `opacity: 0` is not threated as inassessible on iOS
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
const flatStyle = _reactNative.StyleSheet.flatten(element.props.style) ?? {};
|
|
49
|
+
if (flatStyle.display === 'none') return true; // iOS: accessibilityViewIsModal
|
|
50
|
+
// See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios
|
|
51
|
+
|
|
52
|
+
const hostSiblings = (0, _componentTree.getHostSiblings)(element);
|
|
53
|
+
|
|
54
|
+
if (hostSiblings.some(sibling => sibling.props.accessibilityViewIsModal)) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=accessiblity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessiblity.js","names":["isInaccessible","element","current","isSubtreeInaccessible","parent","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","accessibilityViewIsModal"],"sources":["../../src/helpers/accessiblity.ts"],"sourcesContent":["import { StyleSheet } from 'react-native';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport { getHostSiblings } from './component-tree';\n\nexport function isInaccessible(element: ReactTestInstance | null): boolean {\n if (element == null) {\n return true;\n }\n\n let current: ReactTestInstance | null = element;\n while (current) {\n if (isSubtreeInaccessible(current)) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n}\n\nfunction isSubtreeInaccessible(element: ReactTestInstance | null): boolean {\n if (element == null) {\n return true;\n }\n\n // iOS: accessibilityElementsHidden\n // See: https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios\n if (element.props.accessibilityElementsHidden) {\n return true;\n }\n\n // Android: importantForAccessibility\n // See: https://reactnative.dev/docs/accessibility#importantforaccessibility-android\n if (element.props.importantForAccessibility === 'no-hide-descendants') {\n return true;\n }\n\n // Note that `opacity: 0` is not threated as inassessible 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"],"mappings":";;;;;;;AAAA;;AAEA;;AAEO,SAASA,cAAT,CAAwBC,OAAxB,EAAoE;EACzE,IAAIA,OAAO,IAAI,IAAf,EAAqB;IACnB,OAAO,IAAP;EACD;;EAED,IAAIC,OAAiC,GAAGD,OAAxC;;EACA,OAAOC,OAAP,EAAgB;IACd,IAAIC,qBAAqB,CAACD,OAAD,CAAzB,EAAoC;MAClC,OAAO,IAAP;IACD;;IAEDA,OAAO,GAAGA,OAAO,CAACE,MAAlB;EACD;;EAED,OAAO,KAAP;AACD;;AAED,SAASD,qBAAT,CAA+BF,OAA/B,EAA2E;EACzE,IAAIA,OAAO,IAAI,IAAf,EAAqB;IACnB,OAAO,IAAP;EACD,CAHwE,CAKzE;EACA;;;EACA,IAAIA,OAAO,CAACI,KAAR,CAAcC,2BAAlB,EAA+C;IAC7C,OAAO,IAAP;EACD,CATwE,CAWzE;EACA;;;EACA,IAAIL,OAAO,CAACI,KAAR,CAAcE,yBAAd,KAA4C,qBAAhD,EAAuE;IACrE,OAAO,IAAP;EACD,CAfwE,CAiBzE;;;EACA,MAAMC,SAAS,GAAGC,uBAAA,CAAWC,OAAX,CAAmBT,OAAO,CAACI,KAAR,CAAcM,KAAjC,KAA2C,EAA7D;EACA,IAAIH,SAAS,CAACI,OAAV,KAAsB,MAA1B,EAAkC,OAAO,IAAP,CAnBuC,CAqBzE;EACA;;EACA,MAAMC,YAAY,GAAG,IAAAC,8BAAA,EAAgBb,OAAhB,CAArB;;EACA,IAAIY,YAAY,CAACE,IAAb,CAAmBC,OAAD,IAAaA,OAAO,CAACX,KAAR,CAAcY,wBAA7C,CAAJ,EAA4E;IAC1E,OAAO,IAAP;EACD;;EAED,OAAO,KAAP;AACD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ReactTestInstance } from 'react-test-renderer';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given element is a host element.
|
|
4
|
+
* @param element The element to check.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isHostElement(element?: ReactTestInstance | null): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Returns first host ancestor for given element.
|
|
9
|
+
* @param element The element start traversing from.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getHostParent(element: ReactTestInstance | null): ReactTestInstance | null;
|
|
12
|
+
/**
|
|
13
|
+
* Returns host children for given element.
|
|
14
|
+
* @param element The element start traversing from.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getHostChildren(element: ReactTestInstance | null): ReactTestInstance[];
|
|
17
|
+
/**
|
|
18
|
+
* Return the array of host elements that represent the passed element.
|
|
19
|
+
*
|
|
20
|
+
* @param element The element start traversing from.
|
|
21
|
+
* @returns If the passed element is a host element, it will return an array containing only that element,
|
|
22
|
+
* if the passed element is a composite element, it will return an array containing its host children (zero, one or many).
|
|
23
|
+
*/
|
|
24
|
+
export declare function getHostSelves(element: ReactTestInstance | null): ReactTestInstance[];
|
|
25
|
+
/**
|
|
26
|
+
* Returns host siblings for given element.
|
|
27
|
+
* @param element The element start traversing from.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getHostSiblings(element: ReactTestInstance | null): ReactTestInstance[];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getHostChildren = getHostChildren;
|
|
7
|
+
exports.getHostParent = getHostParent;
|
|
8
|
+
exports.getHostSelves = getHostSelves;
|
|
9
|
+
exports.getHostSiblings = getHostSiblings;
|
|
10
|
+
exports.isHostElement = isHostElement;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Checks if the given element is a host element.
|
|
14
|
+
* @param element The element to check.
|
|
15
|
+
*/
|
|
16
|
+
function isHostElement(element) {
|
|
17
|
+
return typeof element?.type === 'string';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns first host ancestor for given element.
|
|
21
|
+
* @param element The element start traversing from.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
function getHostParent(element) {
|
|
26
|
+
if (element == null) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let current = element.parent;
|
|
31
|
+
|
|
32
|
+
while (current) {
|
|
33
|
+
if (isHostElement(current)) {
|
|
34
|
+
return current;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
current = current.parent;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns host children for given element.
|
|
44
|
+
* @param element The element start traversing from.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
function getHostChildren(element) {
|
|
49
|
+
if (element == null) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const hostChildren = [];
|
|
54
|
+
element.children.forEach(child => {
|
|
55
|
+
if (typeof child !== 'object') {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (isHostElement(child)) {
|
|
60
|
+
hostChildren.push(child);
|
|
61
|
+
} else {
|
|
62
|
+
hostChildren.push(...getHostChildren(child));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return hostChildren;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Return the array of host elements that represent the passed element.
|
|
69
|
+
*
|
|
70
|
+
* @param element The element start traversing from.
|
|
71
|
+
* @returns If the passed element is a host element, it will return an array containing only that element,
|
|
72
|
+
* if the passed element is a composite element, it will return an array containing its host children (zero, one or many).
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
function getHostSelves(element) {
|
|
77
|
+
return typeof element?.type === 'string' ? [element] : getHostChildren(element);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns host siblings for given element.
|
|
81
|
+
* @param element The element start traversing from.
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
function getHostSiblings(element) {
|
|
86
|
+
const hostParent = getHostParent(element);
|
|
87
|
+
const hostSelves = getHostSelves(element);
|
|
88
|
+
return getHostChildren(hostParent).filter(sibling => !hostSelves.includes(sibling));
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=component-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-tree.js","names":["isHostElement","element","type","getHostParent","current","parent","getHostChildren","hostChildren","children","forEach","child","push","getHostSelves","getHostSiblings","hostParent","hostSelves","filter","sibling","includes"],"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 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,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,IA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
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.validateStringsRenderedWithinText = void 0;
|
|
7
|
+
|
|
8
|
+
const validateStringsRenderedWithinText = rendererJSON => {
|
|
9
|
+
if (!rendererJSON) return;
|
|
10
|
+
|
|
11
|
+
if (Array.isArray(rendererJSON)) {
|
|
12
|
+
rendererJSON.forEach(validateStringsRenderedWithinTextForNode);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return validateStringsRenderedWithinTextForNode(rendererJSON);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.validateStringsRenderedWithinText = validateStringsRenderedWithinText;
|
|
20
|
+
|
|
21
|
+
const validateStringsRenderedWithinTextForNode = node => {
|
|
22
|
+
if (typeof node === 'string') {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (node.type !== 'Text') {
|
|
27
|
+
node.children?.forEach(child => {
|
|
28
|
+
if (typeof child === 'string') {
|
|
29
|
+
throw new Error(`Invariant Violation: Text strings must be rendered within a <Text> component. Detected attempt to render "${child}" string within a <${node.type}> component.`);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (node.children) {
|
|
35
|
+
node.children.forEach(validateStringsRenderedWithinTextForNode);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=stringValidation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringValidation.js","names":["validateStringsRenderedWithinText","rendererJSON","Array","isArray","forEach","validateStringsRenderedWithinTextForNode","node","type","children","child","Error"],"sources":["../../src/helpers/stringValidation.ts"],"sourcesContent":["import { ReactTestRendererNode } from 'react-test-renderer';\n\nexport const validateStringsRenderedWithinText = (\n rendererJSON: ReactTestRendererNode | Array<ReactTestRendererNode> | null\n) => {\n if (!rendererJSON) return;\n\n if (Array.isArray(rendererJSON)) {\n rendererJSON.forEach(validateStringsRenderedWithinTextForNode);\n return;\n }\n\n return validateStringsRenderedWithinTextForNode(rendererJSON);\n};\n\nconst validateStringsRenderedWithinTextForNode = (\n node: ReactTestRendererNode\n) => {\n if (typeof node === 'string') {\n return;\n }\n\n if (node.type !== 'Text') {\n node.children?.forEach((child) => {\n if (typeof child === 'string') {\n throw new Error(\n `Invariant Violation: Text strings must be rendered within a <Text> component. Detected attempt to render \"${child}\" string within a <${node.type}> component.`\n );\n }\n });\n }\n\n if (node.children) {\n node.children.forEach(validateStringsRenderedWithinTextForNode);\n }\n};\n"],"mappings":";;;;;;;AAEO,MAAMA,iCAAiC,GAC5CC,YAD+C,IAE5C;EACH,IAAI,CAACA,YAAL,EAAmB;;EAEnB,IAAIC,KAAK,CAACC,OAAN,CAAcF,YAAd,CAAJ,EAAiC;IAC/BA,YAAY,CAACG,OAAb,CAAqBC,wCAArB;IACA;EACD;;EAED,OAAOA,wCAAwC,CAACJ,YAAD,CAA/C;AACD,CAXM;;;;AAaP,MAAMI,wCAAwC,GAC5CC,IAD+C,IAE5C;EACH,IAAI,OAAOA,IAAP,KAAgB,QAApB,EAA8B;IAC5B;EACD;;EAED,IAAIA,IAAI,CAACC,IAAL,KAAc,MAAlB,EAA0B;IACxBD,IAAI,CAACE,QAAL,EAAeJ,OAAf,CAAwBK,KAAD,IAAW;MAChC,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;QAC7B,MAAM,IAAIC,KAAJ,CACH,6GAA4GD,KAAM,sBAAqBH,IAAI,CAACC,IAAK,cAD9I,CAAN;MAGD;IACF,CAND;EAOD;;EAED,IAAID,IAAI,CAACE,QAAT,EAAmB;IACjBF,IAAI,CAACE,QAAL,CAAcJ,OAAd,CAAsBC,wCAAtB;EACD;AACF,CApBD"}
|
package/build/index.flow.js
CHANGED
|
@@ -202,6 +202,11 @@ interface UnsafeByPropsQueries {
|
|
|
202
202
|
| Array<ReactTestInstance>
|
|
203
203
|
| [];
|
|
204
204
|
}
|
|
205
|
+
|
|
206
|
+
interface ByRoleOptions {
|
|
207
|
+
name?: string;
|
|
208
|
+
}
|
|
209
|
+
|
|
205
210
|
interface A11yAPI {
|
|
206
211
|
// Label
|
|
207
212
|
getByLabelText: (matcher: TextMatch) => GetReturn;
|
|
@@ -244,16 +249,27 @@ interface A11yAPI {
|
|
|
244
249
|
) => FindAllReturn;
|
|
245
250
|
|
|
246
251
|
// Role
|
|
247
|
-
getByRole: (matcher: A11yRole | RegExp) => GetReturn;
|
|
248
|
-
getAllByRole: (
|
|
249
|
-
|
|
250
|
-
|
|
252
|
+
getByRole: (matcher: A11yRole | RegExp, role?: ByRoleOptions) => GetReturn;
|
|
253
|
+
getAllByRole: (
|
|
254
|
+
matcher: A11yRole | RegExp,
|
|
255
|
+
role?: ByRoleOptions
|
|
256
|
+
) => GetAllReturn;
|
|
257
|
+
queryByRole: (
|
|
258
|
+
matcher: A11yRole | RegExp,
|
|
259
|
+
role?: ByRoleOptions
|
|
260
|
+
) => QueryReturn;
|
|
261
|
+
queryAllByRole: (
|
|
262
|
+
matcher: A11yRole | RegExp,
|
|
263
|
+
role?: ByRoleOptions
|
|
264
|
+
) => QueryAllReturn;
|
|
251
265
|
findByRole: (
|
|
252
266
|
matcher: A11yRole | RegExp,
|
|
267
|
+
role?: ByRoleOptions,
|
|
253
268
|
waitForOptions?: WaitForOptions
|
|
254
269
|
) => FindReturn;
|
|
255
270
|
findAllByRole: (
|
|
256
271
|
matcher: A11yRole | RegExp,
|
|
272
|
+
role?: ByRoleOptions,
|
|
257
273
|
waitForOptions?: WaitForOptions
|
|
258
274
|
) => FindAllReturn;
|
|
259
275
|
|
package/build/index.js
CHANGED
|
@@ -19,16 +19,32 @@ Object.keys(_pure).forEach(function (key) {
|
|
|
19
19
|
|
|
20
20
|
var _flushMicroTasks = require("./flushMicroTasks");
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
var _act = require("./act");
|
|
23
|
+
|
|
24
|
+
if (typeof process === 'undefined' || !process.env?.RNTL_SKIP_AUTO_CLEANUP) {
|
|
25
|
+
// If we're running in a test runner that supports afterEach
|
|
26
|
+
// then we'll automatically run cleanup afterEach test
|
|
27
|
+
// this ensures that tests run in isolation from each other
|
|
28
|
+
// if you don't like this then either import the `pure` module
|
|
29
|
+
// or set the RNTL_SKIP_AUTO_CLEANUP env variable to 'true'.
|
|
30
|
+
if (typeof afterEach === 'function') {
|
|
31
|
+
// eslint-disable-next-line no-undef
|
|
32
|
+
afterEach(async () => {
|
|
33
|
+
await (0, _flushMicroTasks.flushMicroTasks)();
|
|
34
|
+
(0, _pure.cleanup)();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (typeof beforeAll === 'function' && typeof afterAll === 'function') {
|
|
39
|
+
// This matches the behavior of React < 18.
|
|
40
|
+
let previousIsReactActEnvironment = (0, _act.getIsReactActEnvironment)();
|
|
41
|
+
beforeAll(() => {
|
|
42
|
+
previousIsReactActEnvironment = (0, _act.getIsReactActEnvironment)();
|
|
43
|
+
(0, _act.setReactActEnvironment)(true);
|
|
44
|
+
});
|
|
45
|
+
afterAll(() => {
|
|
46
|
+
(0, _act.setReactActEnvironment)(previousIsReactActEnvironment);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
33
49
|
}
|
|
34
50
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["process","env","RNTL_SKIP_AUTO_CLEANUP","afterEach","flushMicroTasks","cleanup","beforeAll","afterAll","previousIsReactActEnvironment","getIsReactActEnvironment","setReactActEnvironment"],"sources":["../src/index.ts"],"sourcesContent":["import { cleanup } from './pure';\nimport { flushMicroTasks } from './flushMicroTasks';\nimport { getIsReactActEnvironment, setReactActEnvironment } from './act';\n\nif (typeof process === 'undefined' || !process.env?.RNTL_SKIP_AUTO_CLEANUP) {\n // If we're running in a test runner that supports afterEach\n // then we'll automatically run cleanup afterEach test\n // this ensures that tests run in isolation from each other\n // if you don't like this then either import the `pure` module\n // or set the RNTL_SKIP_AUTO_CLEANUP env variable to 'true'.\n if (typeof afterEach === 'function') {\n // eslint-disable-next-line no-undef\n afterEach(async () => {\n await flushMicroTasks();\n cleanup();\n });\n }\n\n if (typeof beforeAll === 'function' && typeof afterAll === 'function') {\n // This matches the behavior of React < 18.\n let previousIsReactActEnvironment = getIsReactActEnvironment();\n beforeAll(() => {\n previousIsReactActEnvironment = getIsReactActEnvironment();\n setReactActEnvironment(true);\n });\n\n afterAll(() => {\n setReactActEnvironment(previousIsReactActEnvironment);\n });\n }\n}\n\nexport * from './pure';\n"],"mappings":";;;;;;AAAA;;AAgCA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AA/BA;;AACA;;AAEA,IAAI,OAAOA,OAAP,KAAmB,WAAnB,IAAkC,CAACA,OAAO,CAACC,GAAR,EAAaC,sBAApD,EAA4E;EAC1E;EACA;EACA;EACA;EACA;EACA,IAAI,OAAOC,SAAP,KAAqB,UAAzB,EAAqC;IACnC;IACAA,SAAS,CAAC,YAAY;MACpB,MAAM,IAAAC,gCAAA,GAAN;MACA,IAAAC,aAAA;IACD,CAHQ,CAAT;EAID;;EAED,IAAI,OAAOC,SAAP,KAAqB,UAArB,IAAmC,OAAOC,QAAP,KAAoB,UAA3D,EAAuE;IACrE;IACA,IAAIC,6BAA6B,GAAG,IAAAC,6BAAA,GAApC;IACAH,SAAS,CAAC,MAAM;MACdE,6BAA6B,GAAG,IAAAC,6BAAA,GAAhC;MACA,IAAAC,2BAAA,EAAuB,IAAvB;IACD,CAHQ,CAAT;IAKAH,QAAQ,CAAC,MAAM;MACb,IAAAG,2BAAA,EAAuBF,6BAAvB;IACD,CAFO,CAAR;EAGD;AACF"}
|
package/build/pure.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { within, getQueriesForElement } from './within';
|
|
|
8
8
|
import { getDefaultNormalizer } from './matches';
|
|
9
9
|
import { renderHook } from './renderHook';
|
|
10
10
|
import { screen } from './screen';
|
|
11
|
+
import { isInaccessible } from './helpers/accessiblity';
|
|
11
12
|
export type { RenderOptions, RenderResult, RenderResult as RenderAPI, } from './render';
|
|
12
13
|
export type { RenderHookOptions, RenderHookResult } from './renderHook';
|
|
13
14
|
export { act };
|
|
@@ -20,3 +21,4 @@ export { within, getQueriesForElement };
|
|
|
20
21
|
export { getDefaultNormalizer };
|
|
21
22
|
export { renderHook };
|
|
22
23
|
export { screen };
|
|
24
|
+
export { isInaccessible };
|
package/build/pure.js
CHANGED
|
@@ -33,6 +33,12 @@ Object.defineProperty(exports, "getQueriesForElement", {
|
|
|
33
33
|
return _within.getQueriesForElement;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
+
Object.defineProperty(exports, "isInaccessible", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _accessiblity.isInaccessible;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
36
42
|
Object.defineProperty(exports, "render", {
|
|
37
43
|
enumerable: true,
|
|
38
44
|
get: function () {
|
|
@@ -90,5 +96,7 @@ var _renderHook = require("./renderHook");
|
|
|
90
96
|
|
|
91
97
|
var _screen = require("./screen");
|
|
92
98
|
|
|
99
|
+
var _accessiblity = require("./helpers/accessiblity");
|
|
100
|
+
|
|
93
101
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
94
102
|
//# 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';\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 };\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';\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA"}
|
package/build/queries/role.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { ReactTestInstance } from 'react-test-renderer';
|
|
2
2
|
import { TextMatch } from '../matches';
|
|
3
3
|
import type { FindAllByQuery, FindByQuery, GetAllByQuery, GetByQuery, QueryAllByQuery, QueryByQuery } from './makeQueries';
|
|
4
|
+
declare type ByRoleOptions = {
|
|
5
|
+
name?: TextMatch;
|
|
6
|
+
};
|
|
4
7
|
export declare type ByRoleQueries = {
|
|
5
|
-
getByRole: GetByQuery<TextMatch>;
|
|
6
|
-
getAllByRole: GetAllByQuery<TextMatch>;
|
|
7
|
-
queryByRole: QueryByQuery<TextMatch>;
|
|
8
|
-
queryAllByRole: QueryAllByQuery<TextMatch>;
|
|
9
|
-
findByRole: FindByQuery<TextMatch>;
|
|
10
|
-
findAllByRole: FindAllByQuery<TextMatch>;
|
|
8
|
+
getByRole: GetByQuery<TextMatch, ByRoleOptions>;
|
|
9
|
+
getAllByRole: GetAllByQuery<TextMatch, ByRoleOptions>;
|
|
10
|
+
queryByRole: QueryByQuery<TextMatch, ByRoleOptions>;
|
|
11
|
+
queryAllByRole: QueryAllByQuery<TextMatch, ByRoleOptions>;
|
|
12
|
+
findByRole: FindByQuery<TextMatch, ByRoleOptions>;
|
|
13
|
+
findAllByRole: FindAllByQuery<TextMatch, ByRoleOptions>;
|
|
11
14
|
};
|
|
12
15
|
export declare const bindByRoleQueries: (instance: ReactTestInstance) => ByRoleQueries;
|
|
16
|
+
export {};
|
package/build/queries/role.js
CHANGED
|
@@ -7,10 +7,21 @@ exports.bindByRoleQueries = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _matchStringProp = require("../helpers/matchers/matchStringProp");
|
|
9
9
|
|
|
10
|
+
var _within = require("../within");
|
|
11
|
+
|
|
10
12
|
var _makeQueries = require("./makeQueries");
|
|
11
13
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
+
const matchAccessibleNameIfNeeded = (node, name) => {
|
|
15
|
+
if (name == null) return true;
|
|
16
|
+
const {
|
|
17
|
+
queryAllByText,
|
|
18
|
+
queryAllByLabelText
|
|
19
|
+
} = (0, _within.getQueriesForElement)(node);
|
|
20
|
+
return queryAllByText(name).length > 0 || queryAllByLabelText(name).length > 0;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const queryAllByRole = instance => function queryAllByRoleFn(role, options) {
|
|
24
|
+
return instance.findAll(node => typeof node.type === 'string' && (0, _matchStringProp.matchStringProp)(node.props.accessibilityRole, role) && matchAccessibleNameIfNeeded(node, options?.name));
|
|
14
25
|
};
|
|
15
26
|
|
|
16
27
|
const getMultipleError = role => `Found multiple elements with accessibilityRole: ${String(role)} `;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role.js","names":["queryAllByRole","instance","queryAllByRoleFn","role","
|
|
1
|
+
{"version":3,"file":"role.js","names":["matchAccessibleNameIfNeeded","node","name","queryAllByText","queryAllByLabelText","getQueriesForElement","length","queryAllByRole","instance","queryAllByRoleFn","role","options","findAll","type","matchStringProp","props","accessibilityRole","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByRoleQueries","getByRole","getAllByRole","queryByRole","findByRole","findAllByRole"],"sources":["../../src/queries/role.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { matchStringProp } from '../helpers/matchers/matchStringProp';\nimport { TextMatch } from '../matches';\nimport { getQueriesForElement } from '../within';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\ntype ByRoleOptions = {\n name?: TextMatch;\n};\n\nconst matchAccessibleNameIfNeeded = (\n node: ReactTestInstance,\n name?: TextMatch\n) => {\n if (name == null) return true;\n\n const { queryAllByText, queryAllByLabelText } = getQueriesForElement(node);\n return (\n queryAllByText(name).length > 0 || queryAllByLabelText(name).length > 0\n );\n};\n\nconst queryAllByRole = (\n instance: ReactTestInstance\n): ((role: TextMatch, options?: ByRoleOptions) => Array<ReactTestInstance>) =>\n function queryAllByRoleFn(role, options) {\n return instance.findAll(\n (node) =>\n typeof node.type === 'string' &&\n matchStringProp(node.props.accessibilityRole, role) &&\n matchAccessibleNameIfNeeded(node, options?.name)\n );\n };\n\nconst getMultipleError = (role: TextMatch) =>\n `Found multiple elements with accessibilityRole: ${String(role)} `;\nconst getMissingError = (role: TextMatch) =>\n `Unable to find an element with accessibilityRole: ${String(role)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByRole,\n getMissingError,\n getMultipleError\n);\n\nexport type ByRoleQueries = {\n getByRole: GetByQuery<TextMatch, ByRoleOptions>;\n getAllByRole: GetAllByQuery<TextMatch, ByRoleOptions>;\n queryByRole: QueryByQuery<TextMatch, ByRoleOptions>;\n queryAllByRole: QueryAllByQuery<TextMatch, ByRoleOptions>;\n findByRole: FindByQuery<TextMatch, ByRoleOptions>;\n findAllByRole: FindAllByQuery<TextMatch, ByRoleOptions>;\n};\n\nexport const bindByRoleQueries = (\n instance: ReactTestInstance\n): ByRoleQueries => ({\n getByRole: getBy(instance),\n getAllByRole: getAllBy(instance),\n queryByRole: queryBy(instance),\n queryAllByRole: queryAllBy(instance),\n findByRole: findBy(instance),\n findAllByRole: findAllBy(instance),\n});\n"],"mappings":";;;;;;;AACA;;AAEA;;AACA;;AAcA,MAAMA,2BAA2B,GAAG,CAClCC,IADkC,EAElCC,IAFkC,KAG/B;EACH,IAAIA,IAAI,IAAI,IAAZ,EAAkB,OAAO,IAAP;EAElB,MAAM;IAAEC,cAAF;IAAkBC;EAAlB,IAA0C,IAAAC,4BAAA,EAAqBJ,IAArB,CAAhD;EACA,OACEE,cAAc,CAACD,IAAD,CAAd,CAAqBI,MAArB,GAA8B,CAA9B,IAAmCF,mBAAmB,CAACF,IAAD,CAAnB,CAA0BI,MAA1B,GAAmC,CADxE;AAGD,CAVD;;AAYA,MAAMC,cAAc,GAClBC,QADqB,IAGrB,SAASC,gBAAT,CAA0BC,IAA1B,EAAgCC,OAAhC,EAAyC;EACvC,OAAOH,QAAQ,CAACI,OAAT,CACJX,IAAD,IACE,OAAOA,IAAI,CAACY,IAAZ,KAAqB,QAArB,IACA,IAAAC,gCAAA,EAAgBb,IAAI,CAACc,KAAL,CAAWC,iBAA3B,EAA8CN,IAA9C,CADA,IAEAV,2BAA2B,CAACC,IAAD,EAAOU,OAAO,EAAET,IAAhB,CAJxB,CAAP;AAMD,CAVH;;AAYA,MAAMe,gBAAgB,GAAIP,IAAD,IACtB,mDAAkDQ,MAAM,CAACR,IAAD,CAAO,GADlE;;AAEA,MAAMS,eAAe,GAAIT,IAAD,IACrB,qDAAoDQ,MAAM,CAACR,IAAD,CAAO,EADpE;;AAGA,MAAM;EAAEU,KAAF;EAASC,QAAT;EAAmBC,OAAnB;EAA4BC,UAA5B;EAAwCC,MAAxC;EAAgDC;AAAhD,IAA8D,IAAAC,wBAAA,EAClEnB,cADkE,EAElEY,eAFkE,EAGlEF,gBAHkE,CAApE;;AAeO,MAAMU,iBAAiB,GAC5BnB,QAD+B,KAEZ;EACnBoB,SAAS,EAAER,KAAK,CAACZ,QAAD,CADG;EAEnBqB,YAAY,EAAER,QAAQ,CAACb,QAAD,CAFH;EAGnBsB,WAAW,EAAER,OAAO,CAACd,QAAD,CAHD;EAInBD,cAAc,EAAEgB,UAAU,CAACf,QAAD,CAJP;EAKnBuB,UAAU,EAAEP,MAAM,CAAChB,QAAD,CALC;EAMnBwB,aAAa,EAAEP,SAAS,CAACjB,QAAD;AANL,CAFY,CAA1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkReactVersionAtLeast(major: number, minor: number): boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.checkReactVersionAtLeast = checkReactVersionAtLeast;
|
|
7
|
+
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
+
|
|
12
|
+
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; }
|
|
13
|
+
|
|
14
|
+
function checkReactVersionAtLeast(major, minor) {
|
|
15
|
+
if (React.version === undefined) return false;
|
|
16
|
+
const [actualMajor, actualMinor] = React.version.split('.').map(Number);
|
|
17
|
+
return actualMajor > major || actualMajor === major && actualMinor >= minor;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=react-versions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-versions.js","names":["checkReactVersionAtLeast","major","minor","React","version","undefined","actualMajor","actualMinor","split","map","Number"],"sources":["../src/react-versions.ts"],"sourcesContent":["import * as React from 'react';\n\nexport function checkReactVersionAtLeast(\n major: number,\n minor: number\n): boolean {\n if (React.version === undefined) return false;\n const [actualMajor, actualMinor] = React.version.split('.').map(Number);\n\n return actualMajor > major || (actualMajor === major && actualMinor >= minor);\n}\n"],"mappings":";;;;;;;AAAA;;;;;;AAEO,SAASA,wBAAT,CACLC,KADK,EAELC,KAFK,EAGI;EACT,IAAIC,KAAK,CAACC,OAAN,KAAkBC,SAAtB,EAAiC,OAAO,KAAP;EACjC,MAAM,CAACC,WAAD,EAAcC,WAAd,IAA6BJ,KAAK,CAACC,OAAN,CAAcI,KAAd,CAAoB,GAApB,EAAyBC,GAAzB,CAA6BC,MAA7B,CAAnC;EAEA,OAAOJ,WAAW,GAAGL,KAAd,IAAwBK,WAAW,KAAKL,KAAhB,IAAyBM,WAAW,IAAIL,KAAvE;AACD"}
|
package/build/render.d.ts
CHANGED
|
@@ -3,13 +3,14 @@ import * as React from 'react';
|
|
|
3
3
|
export declare type RenderOptions = {
|
|
4
4
|
wrapper?: React.ComponentType<any>;
|
|
5
5
|
createNodeMock?: (element: React.ReactElement) => any;
|
|
6
|
+
unstable_validateStringsRenderedWithinText?: boolean;
|
|
6
7
|
};
|
|
7
8
|
export declare type RenderResult = ReturnType<typeof render>;
|
|
8
9
|
/**
|
|
9
10
|
* Renders test component deeply using react-test-renderer and exposes helpers
|
|
10
11
|
* to assert on the output.
|
|
11
12
|
*/
|
|
12
|
-
export default function render<T>(component: React.ReactElement<T>, { wrapper: Wrapper, createNodeMock }?: RenderOptions): {
|
|
13
|
+
export default function render<T>(component: React.ReactElement<T>, { wrapper: Wrapper, createNodeMock, unstable_validateStringsRenderedWithinText, }?: RenderOptions): {
|
|
13
14
|
update: (component: React.ReactElement<any, string | React.JSXElementConstructor<any>>) => void;
|
|
14
15
|
unmount: () => void;
|
|
15
16
|
container: TestRenderer.ReactTestInstance;
|
|
@@ -116,12 +117,24 @@ export default function render<T>(component: React.ReactElement<T>, { wrapper: W
|
|
|
116
117
|
queryAllByAccessibilityState: import("./queries/makeQueries").QueryAllByQuery<import("react-native").AccessibilityState, void>;
|
|
117
118
|
findByAccessibilityState: import("./queries/makeQueries").FindByQuery<import("react-native").AccessibilityState, void>;
|
|
118
119
|
findAllByAccessibilityState: import("./queries/makeQueries").FindAllByQuery<import("react-native").AccessibilityState, void>;
|
|
119
|
-
getByRole: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
getByRole: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, {
|
|
121
|
+
name?: import("./matches").TextMatch | undefined;
|
|
122
|
+
}>;
|
|
123
|
+
getAllByRole: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, {
|
|
124
|
+
name?: import("./matches").TextMatch | undefined;
|
|
125
|
+
}>;
|
|
126
|
+
queryByRole: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, {
|
|
127
|
+
name?: import("./matches").TextMatch | undefined;
|
|
128
|
+
}>;
|
|
129
|
+
queryAllByRole: import("./queries/makeQueries").QueryAllByQuery<import("./matches").TextMatch, {
|
|
130
|
+
name?: import("./matches").TextMatch | undefined;
|
|
131
|
+
}>;
|
|
132
|
+
findByRole: import("./queries/makeQueries").FindByQuery<import("./matches").TextMatch, {
|
|
133
|
+
name?: import("./matches").TextMatch | undefined;
|
|
134
|
+
}>;
|
|
135
|
+
findAllByRole: import("./queries/makeQueries").FindAllByQuery<import("./matches").TextMatch, {
|
|
136
|
+
name?: import("./matches").TextMatch | undefined;
|
|
137
|
+
}>;
|
|
125
138
|
getByHintText: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, void>;
|
|
126
139
|
getAllByHintText: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, void>;
|
|
127
140
|
queryByHintText: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, void>;
|
package/build/render.js
CHANGED
|
@@ -21,6 +21,8 @@ var _within = require("./within");
|
|
|
21
21
|
|
|
22
22
|
var _screen = require("./screen");
|
|
23
23
|
|
|
24
|
+
var _stringValidation = require("./helpers/stringValidation");
|
|
25
|
+
|
|
24
26
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
25
27
|
|
|
26
28
|
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; }
|
|
@@ -32,14 +34,48 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
32
34
|
* to assert on the output.
|
|
33
35
|
*/
|
|
34
36
|
function render(component, {
|
|
37
|
+
wrapper: Wrapper,
|
|
38
|
+
createNodeMock,
|
|
39
|
+
unstable_validateStringsRenderedWithinText
|
|
40
|
+
} = {}) {
|
|
41
|
+
if (unstable_validateStringsRenderedWithinText) {
|
|
42
|
+
return renderWithStringValidation(component, {
|
|
43
|
+
wrapper: Wrapper,
|
|
44
|
+
createNodeMock
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const wrap = element => Wrapper ? /*#__PURE__*/React.createElement(Wrapper, null, element) : element;
|
|
49
|
+
|
|
50
|
+
const renderer = renderWithAct(wrap(component), createNodeMock ? {
|
|
51
|
+
createNodeMock
|
|
52
|
+
} : undefined);
|
|
53
|
+
return buildRenderResult(renderer, wrap);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function renderWithStringValidation(component, {
|
|
35
57
|
wrapper: Wrapper,
|
|
36
58
|
createNodeMock
|
|
37
59
|
} = {}) {
|
|
38
|
-
const
|
|
60
|
+
const handleRender = (_, phase) => {
|
|
61
|
+
if (phase === 'update') {
|
|
62
|
+
(0, _stringValidation.validateStringsRenderedWithinText)(_screen.screen.toJSON());
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const wrap = element => /*#__PURE__*/React.createElement(React.Profiler, {
|
|
67
|
+
id: "renderProfiler",
|
|
68
|
+
onRender: handleRender
|
|
69
|
+
}, Wrapper ? /*#__PURE__*/React.createElement(Wrapper, null, element) : element);
|
|
39
70
|
|
|
40
71
|
const renderer = renderWithAct(wrap(component), createNodeMock ? {
|
|
41
72
|
createNodeMock
|
|
42
73
|
} : undefined);
|
|
74
|
+
(0, _stringValidation.validateStringsRenderedWithinText)(renderer.toJSON());
|
|
75
|
+
return buildRenderResult(renderer, wrap);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function buildRenderResult(renderer, wrap) {
|
|
43
79
|
const update = updateWithAct(renderer, wrap);
|
|
44
80
|
const instance = renderer.root;
|
|
45
81
|
|
package/build/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","names":["render","component","wrapper","Wrapper","createNodeMock","wrap","
|
|
1
|
+
{"version":3,"file":"render.js","names":["render","component","wrapper","Wrapper","createNodeMock","unstable_validateStringsRenderedWithinText","renderWithStringValidation","wrap","element","renderer","renderWithAct","undefined","buildRenderResult","handleRender","_","phase","validateStringsRenderedWithinText","screen","toJSON","update","updateWithAct","instance","root","unmount","act","addToCleanupQueue","result","getQueriesForElement","container","rerender","debug","setRenderResult","options","TestRenderer","create","debugImpl","message","json","debugDeep","shallow","debugShallow"],"sources":["../src/render.tsx"],"sourcesContent":["import TestRenderer from 'react-test-renderer';\nimport type { ReactTestInstance, ReactTestRenderer } from 'react-test-renderer';\nimport * as React from 'react';\nimport { Profiler } from 'react';\nimport act from './act';\nimport { addToCleanupQueue } from './cleanup';\nimport debugShallow from './helpers/debugShallow';\nimport debugDeep from './helpers/debugDeep';\nimport { getQueriesForElement } from './within';\nimport { setRenderResult, screen } from './screen';\nimport { validateStringsRenderedWithinText } from './helpers/stringValidation';\n\nexport type RenderOptions = {\n wrapper?: React.ComponentType<any>;\n createNodeMock?: (element: React.ReactElement) => any;\n unstable_validateStringsRenderedWithinText?: boolean;\n};\n\ntype TestRendererOptions = {\n createNodeMock: (element: React.ReactElement) => any;\n};\n\nexport type RenderResult = ReturnType<typeof render>;\n\n/**\n * Renders test component deeply using react-test-renderer and exposes helpers\n * to assert on the output.\n */\nexport default function render<T>(\n component: React.ReactElement<T>,\n {\n wrapper: Wrapper,\n createNodeMock,\n unstable_validateStringsRenderedWithinText,\n }: RenderOptions = {}\n) {\n if (unstable_validateStringsRenderedWithinText) {\n return renderWithStringValidation(component, {\n wrapper: Wrapper,\n createNodeMock,\n });\n }\n\n const wrap = (element: React.ReactElement) =>\n Wrapper ? <Wrapper>{element}</Wrapper> : element;\n\n const renderer = renderWithAct(\n wrap(component),\n createNodeMock ? { createNodeMock } : undefined\n );\n\n return buildRenderResult(renderer, wrap);\n}\n\nfunction renderWithStringValidation<T>(\n component: React.ReactElement<T>,\n {\n wrapper: Wrapper,\n createNodeMock,\n }: Omit<RenderOptions, 'unstable_validateStringsRenderedWithinText'> = {}\n) {\n const handleRender: React.ProfilerProps['onRender'] = (_, phase) => {\n if (phase === 'update') {\n validateStringsRenderedWithinText(screen.toJSON());\n }\n };\n\n const wrap = (element: React.ReactElement) => (\n <Profiler id=\"renderProfiler\" onRender={handleRender}>\n {Wrapper ? <Wrapper>{element}</Wrapper> : element}\n </Profiler>\n );\n\n const renderer = renderWithAct(\n wrap(component),\n createNodeMock ? { createNodeMock } : undefined\n );\n validateStringsRenderedWithinText(renderer.toJSON());\n\n return buildRenderResult(renderer, wrap);\n}\n\nfunction buildRenderResult(\n renderer: ReactTestRenderer,\n wrap: (element: React.ReactElement) => JSX.Element\n) {\n const update = updateWithAct(renderer, wrap);\n const instance = renderer.root;\n\n const unmount = () => {\n act(() => {\n renderer.unmount();\n });\n };\n\n addToCleanupQueue(unmount);\n\n const result = {\n ...getQueriesForElement(instance),\n update,\n unmount,\n container: instance,\n rerender: update, // alias for `update`\n toJSON: renderer.toJSON,\n debug: debug(instance, renderer),\n };\n\n setRenderResult(result);\n return result;\n}\n\nfunction renderWithAct(\n component: React.ReactElement,\n options?: TestRendererOptions\n): ReactTestRenderer {\n let renderer: ReactTestRenderer;\n\n act(() => {\n renderer = TestRenderer.create(component, options);\n });\n\n // @ts-ignore act is sync, so renderer is always initialised here\n return renderer;\n}\n\nfunction updateWithAct(\n renderer: ReactTestRenderer,\n wrap: (innerElement: React.ReactElement) => React.ReactElement\n) {\n return function (component: React.ReactElement) {\n act(() => {\n renderer.update(wrap(component));\n });\n };\n}\n\ninterface DebugFunction {\n (message?: string): void;\n shallow: (message?: string) => void;\n}\n\nfunction debug(\n instance: ReactTestInstance,\n renderer: ReactTestRenderer\n): DebugFunction {\n function debugImpl(message?: string) {\n const json = renderer.toJSON();\n if (json) {\n return debugDeep(json, message);\n }\n }\n debugImpl.shallow = (message?: string) => debugShallow(instance, message);\n return debugImpl;\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAcA;AACA;AACA;AACA;AACe,SAASA,MAAT,CACbC,SADa,EAEb;EACEC,OAAO,EAAEC,OADX;EAEEC,cAFF;EAGEC;AAHF,IAImB,EANN,EAOb;EACA,IAAIA,0CAAJ,EAAgD;IAC9C,OAAOC,0BAA0B,CAACL,SAAD,EAAY;MAC3CC,OAAO,EAAEC,OADkC;MAE3CC;IAF2C,CAAZ,CAAjC;EAID;;EAED,MAAMG,IAAI,GAAIC,OAAD,IACXL,OAAO,gBAAG,oBAAC,OAAD,QAAUK,OAAV,CAAH,GAAkCA,OAD3C;;EAGA,MAAMC,QAAQ,GAAGC,aAAa,CAC5BH,IAAI,CAACN,SAAD,CADwB,EAE5BG,cAAc,GAAG;IAAEA;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;IAKK;IAClBD,MAAM,EAAET,QAAQ,CAACS,MANJ;IAObY,KAAK,EAAEA,KAAK,CAACT,QAAD,EAAWZ,QAAX;EAPC,CAAf;EAUA,IAAAsB,uBAAA,EAAgBL,MAAhB;EACA,OAAOA,MAAP;AACD;;AAED,SAAShB,aAAT,CACET,SADF,EAEE+B,OAFF,EAGqB;EACnB,IAAIvB,QAAJ;EAEA,IAAAe,YAAA,EAAI,MAAM;IACRf,QAAQ,GAAGwB,0BAAA,CAAaC,MAAb,CAAoBjC,SAApB,EAA+B+B,OAA/B,CAAX;EACD,CAFD,EAHmB,CAOnB;;EACA,OAAOvB,QAAP;AACD;;AAED,SAASW,aAAT,CACEX,QADF,EAEEF,IAFF,EAGE;EACA,OAAO,UAAUN,SAAV,EAAyC;IAC9C,IAAAuB,YAAA,EAAI,MAAM;MACRf,QAAQ,CAACU,MAAT,CAAgBZ,IAAI,CAACN,SAAD,CAApB;IACD,CAFD;EAGD,CAJD;AAKD;;AAOD,SAAS6B,KAAT,CACET,QADF,EAEEZ,QAFF,EAGiB;EACf,SAAS0B,SAAT,CAAmBC,OAAnB,EAAqC;IACnC,MAAMC,IAAI,GAAG5B,QAAQ,CAACS,MAAT,EAAb;;IACA,IAAImB,IAAJ,EAAU;MACR,OAAO,IAAAC,kBAAA,EAAUD,IAAV,EAAgBD,OAAhB,CAAP;IACD;EACF;;EACDD,SAAS,CAACI,OAAV,GAAqBH,OAAD,IAAsB,IAAAI,qBAAA,EAAanB,QAAb,EAAuBe,OAAvB,CAA1C;;EACA,OAAOD,SAAP;AACD"}
|
package/build/waitFor.js
CHANGED
|
@@ -5,15 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = waitFor;
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var _act = _interopRequireDefault(require("./act"));
|
|
8
|
+
var _act = _interopRequireWildcard(require("./act"));
|
|
11
9
|
|
|
12
10
|
var _errors = require("./helpers/errors");
|
|
13
11
|
|
|
14
12
|
var _timers = require("./helpers/timers");
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
var _reactVersions = require("./react-versions");
|
|
17
15
|
|
|
18
16
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
17
|
|
|
@@ -23,12 +21,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
23
21
|
const DEFAULT_TIMEOUT = 1000;
|
|
24
22
|
const DEFAULT_INTERVAL = 50;
|
|
25
23
|
|
|
26
|
-
function checkReactVersionAtLeast(major, minor) {
|
|
27
|
-
if (React.version === undefined) return false;
|
|
28
|
-
const [actualMajor, actualMinor] = React.version.split('.').map(Number);
|
|
29
|
-
return actualMajor > major || actualMajor === major && actualMinor >= minor;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
24
|
function waitForInternal(expectation, {
|
|
33
25
|
timeout = DEFAULT_TIMEOUT,
|
|
34
26
|
interval = DEFAULT_INTERVAL,
|
|
@@ -200,7 +192,18 @@ async function waitFor(expectation, options) {
|
|
|
200
192
|
...options
|
|
201
193
|
};
|
|
202
194
|
|
|
203
|
-
if (
|
|
195
|
+
if ((0, _reactVersions.checkReactVersionAtLeast)(18, 0)) {
|
|
196
|
+
const previousActEnvironment = (0, _act.getIsReactActEnvironment)();
|
|
197
|
+
(0, _act.setReactActEnvironment)(false);
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
return await waitForInternal(expectation, optionsWithStackTrace);
|
|
201
|
+
} finally {
|
|
202
|
+
(0, _act.setReactActEnvironment)(previousActEnvironment);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (!(0, _reactVersions.checkReactVersionAtLeast)(16, 9)) {
|
|
204
207
|
return waitForInternal(expectation, optionsWithStackTrace);
|
|
205
208
|
}
|
|
206
209
|
|
package/build/waitFor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitFor.js","names":["DEFAULT_TIMEOUT","DEFAULT_INTERVAL","checkReactVersionAtLeast","major","minor","React","version","undefined","actualMajor","actualMinor","split","map","Number","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","act"],"sources":["../src/waitFor.ts"],"sourcesContent":["/* globals jest */\nimport * as React from 'react';\nimport act from './act';\nimport { ErrorWithStack, copyStackTrace } from './helpers/errors';\nimport {\n setTimeout,\n clearTimeout,\n setImmediate,\n jestFakeTimersAreEnabled,\n} from './helpers/timers';\n\nconst DEFAULT_TIMEOUT = 1000;\nconst DEFAULT_INTERVAL = 50;\n\nfunction checkReactVersionAtLeast(major: number, minor: number): boolean {\n if (React.version === undefined) return false;\n const [actualMajor, actualMinor] = React.version.split('.').map(Number);\n\n return actualMajor > major || (actualMajor === major && actualMinor >= minor);\n}\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(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;;;;;;;;AAJA;AAWA,MAAMA,eAAe,GAAG,IAAxB;AACA,MAAMC,gBAAgB,GAAG,EAAzB;;AAEA,SAASC,wBAAT,CAAkCC,KAAlC,EAAiDC,KAAjD,EAAyE;EACvE,IAAIC,KAAK,CAACC,OAAN,KAAkBC,SAAtB,EAAiC,OAAO,KAAP;EACjC,MAAM,CAACC,WAAD,EAAcC,WAAd,IAA6BJ,KAAK,CAACC,OAAN,CAAcI,KAAd,CAAoB,GAApB,EAAyBC,GAAzB,CAA6BC,MAA7B,CAAnC;EAEA,OAAOJ,WAAW,GAAGL,KAAd,IAAwBK,WAAW,KAAKL,KAAhB,IAAyBM,WAAW,IAAIL,KAAvE;AACD;;AASD,SAASS,eAAT,CACEC,WADF,EAEE;EACEC,OAAO,GAAGf,eADZ;EAEEgB,QAAQ,GAAGf,gBAFb;EAGEgB,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,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;MACF;;MACD,IAAI,OAAOC,SAAP,KAAqB,UAAzB,EAAqC;QACnCA,SAAS,CAACgB,KAAD,CAAT;MACD;;MACDQ,MAAM,CAAC;QAAEI,IAAI,EAAE,OAAR;QAAiBZ;MAAjB,CAAD,CAAN;IACD;EACF,CA/IM,CAAP;AAgJD;;AAEc,eAAekB,OAAf,CACbtC,WADa,EAEbuC,OAFa,EAGD;EACZ;EACA,MAAMpC,eAAe,GAAG,IAAIqC,sBAAJ,CAAmB,mBAAnB,EAAwCF,OAAxC,CAAxB;EACA,MAAMG,qBAAqB,GAAG;IAAEtC,eAAF;IAAmB,GAAGoC;EAAtB,CAA9B;;EAEA,IAAI,CAACnD,wBAAwB,CAAC,EAAD,EAAK,CAAL,CAA7B,EAAsC;IACpC,OAAOW,eAAe,CAACC,WAAD,EAAcyC,qBAAd,CAAtB;EACD;;EAED,IAAIR,MAAJ;EAEA,MAAM,IAAAS,YAAA,EAAI,YAAY;IACpBT,MAAM,GAAG,MAAMlC,eAAe,CAACC,WAAD,EAAcyC,qBAAd,CAA9B;EACD,CAFK,CAAN,CAXY,CAeZ;;EACA,OAAOR,MAAP;AACD"}
|
|
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;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MlC,eAAe,CAACC,WAAD,EAAcyC,qBAAd,CAA9B;EACD,CAFK,CAAN,CAtBY,CA0BZ;;EACA,OAAOR,MAAP;AACD"}
|
package/build/within.d.ts
CHANGED
|
@@ -101,12 +101,24 @@ export declare function within(instance: ReactTestInstance): {
|
|
|
101
101
|
queryAllByAccessibilityState: import("./queries/makeQueries").QueryAllByQuery<import("react-native").AccessibilityState, void>;
|
|
102
102
|
findByAccessibilityState: import("./queries/makeQueries").FindByQuery<import("react-native").AccessibilityState, void>;
|
|
103
103
|
findAllByAccessibilityState: import("./queries/makeQueries").FindAllByQuery<import("react-native").AccessibilityState, void>;
|
|
104
|
-
getByRole: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
getByRole: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, {
|
|
105
|
+
name?: import("./matches").TextMatch | undefined;
|
|
106
|
+
}>;
|
|
107
|
+
getAllByRole: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, {
|
|
108
|
+
name?: import("./matches").TextMatch | undefined;
|
|
109
|
+
}>;
|
|
110
|
+
queryByRole: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, {
|
|
111
|
+
name?: import("./matches").TextMatch | undefined;
|
|
112
|
+
}>;
|
|
113
|
+
queryAllByRole: import("./queries/makeQueries").QueryAllByQuery<import("./matches").TextMatch, {
|
|
114
|
+
name?: import("./matches").TextMatch | undefined;
|
|
115
|
+
}>;
|
|
116
|
+
findByRole: import("./queries/makeQueries").FindByQuery<import("./matches").TextMatch, {
|
|
117
|
+
name?: import("./matches").TextMatch | undefined;
|
|
118
|
+
}>;
|
|
119
|
+
findAllByRole: import("./queries/makeQueries").FindAllByQuery<import("./matches").TextMatch, {
|
|
120
|
+
name?: import("./matches").TextMatch | undefined;
|
|
121
|
+
}>;
|
|
110
122
|
getByHintText: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, void>;
|
|
111
123
|
getAllByHintText: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, void>;
|
|
112
124
|
queryByHintText: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testing-library/react-native",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.2.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",
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"clean": "del build",
|
|
73
73
|
"test": "jest",
|
|
74
74
|
"test:ci": "jest --maxWorkers=2",
|
|
75
|
+
"test:ci:react:17": "scripts/test_react_17",
|
|
75
76
|
"typecheck": "tsc",
|
|
76
77
|
"flow": "flow",
|
|
77
78
|
"copy-flowtypes": "cp typings/index.flow.js build",
|
package/typings/index.flow.js
CHANGED
|
@@ -202,6 +202,11 @@ interface UnsafeByPropsQueries {
|
|
|
202
202
|
| Array<ReactTestInstance>
|
|
203
203
|
| [];
|
|
204
204
|
}
|
|
205
|
+
|
|
206
|
+
interface ByRoleOptions {
|
|
207
|
+
name?: string;
|
|
208
|
+
}
|
|
209
|
+
|
|
205
210
|
interface A11yAPI {
|
|
206
211
|
// Label
|
|
207
212
|
getByLabelText: (matcher: TextMatch) => GetReturn;
|
|
@@ -244,16 +249,27 @@ interface A11yAPI {
|
|
|
244
249
|
) => FindAllReturn;
|
|
245
250
|
|
|
246
251
|
// Role
|
|
247
|
-
getByRole: (matcher: A11yRole | RegExp) => GetReturn;
|
|
248
|
-
getAllByRole: (
|
|
249
|
-
|
|
250
|
-
|
|
252
|
+
getByRole: (matcher: A11yRole | RegExp, role?: ByRoleOptions) => GetReturn;
|
|
253
|
+
getAllByRole: (
|
|
254
|
+
matcher: A11yRole | RegExp,
|
|
255
|
+
role?: ByRoleOptions
|
|
256
|
+
) => GetAllReturn;
|
|
257
|
+
queryByRole: (
|
|
258
|
+
matcher: A11yRole | RegExp,
|
|
259
|
+
role?: ByRoleOptions
|
|
260
|
+
) => QueryReturn;
|
|
261
|
+
queryAllByRole: (
|
|
262
|
+
matcher: A11yRole | RegExp,
|
|
263
|
+
role?: ByRoleOptions
|
|
264
|
+
) => QueryAllReturn;
|
|
251
265
|
findByRole: (
|
|
252
266
|
matcher: A11yRole | RegExp,
|
|
267
|
+
role?: ByRoleOptions,
|
|
253
268
|
waitForOptions?: WaitForOptions
|
|
254
269
|
) => FindReturn;
|
|
255
270
|
findAllByRole: (
|
|
256
271
|
matcher: A11yRole | RegExp,
|
|
272
|
+
role?: ByRoleOptions,
|
|
257
273
|
waitForOptions?: WaitForOptions
|
|
258
274
|
) => FindAllReturn;
|
|
259
275
|
|