@testing-library/react-native 11.1.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/act.d.ts +8 -3
- package/build/act.js +73 -2
- package/build/act.js.map +1 -1
- package/build/config.d.ts +10 -0
- package/build/config.js +28 -0
- package/build/config.js.map +1 -0
- package/build/fireEvent.js +7 -11
- 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 +44 -0
- package/build/helpers/component-tree.js +145 -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/helpers/timers.js +1 -1
- package/build/helpers/timers.js.map +1 -1
- package/build/index.flow.js +28 -4
- package/build/index.js +27 -11
- package/build/index.js.map +1 -1
- package/build/pure.d.ts +4 -0
- package/build/pure.js +22 -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/role.d.ts +10 -6
- package/build/queries/role.js +13 -2
- package/build/queries/role.js.map +1 -1
- package/build/queries/text.js +28 -28
- package/build/queries/text.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 +16 -12
- package/build/waitFor.js.map +1 -1
- package/build/within.d.ts +18 -6
- package/package.json +12 -11
- package/typings/index.flow.js +28 -4
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;EAAF,CAAH,GAAwBO,SAFV,CAA9B;EAKA,OAAOC,iBAAiB,CAACH,QAAD,EAAWF,IAAX,CAAxB;AACD;;AAED,SAASD,0BAAT,CACEL,SADF,EAEE;EACEC,OAAO,EAAEC,OADX;EAEEC;AAFF,IAGuE,EALzE,EAME;EACA,MAAMS,YAA6C,GAAG,CAACC,CAAD,EAAIC,KAAJ,KAAc;IAClE,IAAIA,KAAK,KAAK,QAAd,EAAwB;MACtB,IAAAC,mDAAA,EAAkCC,cAAA,CAAOC,MAAP,EAAlC;I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+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,32 +5,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = waitFor;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _act = _interopRequireWildcard(require("./act"));
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _config = require("./config");
|
|
11
11
|
|
|
12
12
|
var _errors = require("./helpers/errors");
|
|
13
13
|
|
|
14
14
|
var _timers = require("./helpers/timers");
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
var _reactVersions = require("./react-versions");
|
|
17
17
|
|
|
18
18
|
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
19
|
|
|
20
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; }
|
|
21
21
|
|
|
22
22
|
/* globals jest */
|
|
23
|
-
const DEFAULT_TIMEOUT = 1000;
|
|
24
23
|
const DEFAULT_INTERVAL = 50;
|
|
25
24
|
|
|
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
25
|
function waitForInternal(expectation, {
|
|
33
|
-
timeout =
|
|
26
|
+
timeout = (0, _config.getConfig)().asyncUtilTimeout,
|
|
34
27
|
interval = DEFAULT_INTERVAL,
|
|
35
28
|
stackTraceError,
|
|
36
29
|
onTimeout
|
|
@@ -200,7 +193,18 @@ async function waitFor(expectation, options) {
|
|
|
200
193
|
...options
|
|
201
194
|
};
|
|
202
195
|
|
|
203
|
-
if (
|
|
196
|
+
if ((0, _reactVersions.checkReactVersionAtLeast)(18, 0)) {
|
|
197
|
+
const previousActEnvironment = (0, _act.getIsReactActEnvironment)();
|
|
198
|
+
(0, _act.setReactActEnvironment)(false);
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
return await waitForInternal(expectation, optionsWithStackTrace);
|
|
202
|
+
} finally {
|
|
203
|
+
(0, _act.setReactActEnvironment)(previousActEnvironment);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (!(0, _reactVersions.checkReactVersionAtLeast)(16, 9)) {
|
|
204
208
|
return waitForInternal(expectation, optionsWithStackTrace);
|
|
205
209
|
}
|
|
206
210
|
|
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,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QACLiB,KAAK,GAAG,IAAIC,KAAJ,CAAU,uBAAV,CAAR;;QACA,IAAIlB,eAAJ,EAAqB;UACnB,IAAAmB,sBAAA,EAAeF,KAAf,EAAsBjB,eAAtB;QACD;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_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,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e,CAACC,WAAD,EAAc2C,qBAAd,CAAtB;EACD;;EAED,IAAIR,MAAJ;EAEA,MAAM,IAAAa,YAAA,EAAI,YAAY;IACpBb,MAAM,GAAG,MAAMpC,eAAe,CAACC,WAAD,EAAc2C,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.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"
|
|
@@ -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
|
|
|
@@ -330,6 +346,7 @@ declare module '@testing-library/react-native' {
|
|
|
330
346
|
declare interface RenderOptions {
|
|
331
347
|
wrapper?: React.ComponentType<any>;
|
|
332
348
|
createNodeMock?: (element: React.Element<any>) => any;
|
|
349
|
+
unstable_validateStringsRenderedWithinText?: boolean;
|
|
333
350
|
}
|
|
334
351
|
|
|
335
352
|
declare export var render: (
|
|
@@ -351,6 +368,13 @@ declare module '@testing-library/react-native' {
|
|
|
351
368
|
|
|
352
369
|
declare export var waitForElementToBeRemoved: WaitForElementToBeRemovedFunction;
|
|
353
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
|
+
|
|
354
378
|
declare export var act: (callback: () => void) => Thenable;
|
|
355
379
|
declare export var within: (instance: ReactTestInstance) => Queries;
|
|
356
380
|
declare export var getQueriesForElement: (
|