@testing-library/react-native 11.0.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/README.md +1 -1
- package/build/act.d.ts +8 -3
- package/build/act.js +73 -2
- package/build/act.js.map +1 -1
- package/build/cleanup.js.map +1 -1
- package/build/fireEvent.js +17 -7
- package/build/fireEvent.js.map +1 -1
- package/build/flushMicroTasks.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/debugDeep.js.map +1 -1
- package/build/helpers/debugShallow.js.map +1 -1
- package/build/helpers/errors.d.ts +2 -2
- package/build/helpers/errors.js.map +1 -1
- package/build/helpers/filterNodeByType.d.ts +1 -1
- package/build/helpers/filterNodeByType.js.map +1 -1
- package/build/helpers/format.js.map +1 -1
- package/build/helpers/matchers/matchArrayProp.js.map +1 -1
- package/build/helpers/matchers/matchObjectProp.js.map +1 -1
- package/build/helpers/matchers/matchStringProp.js.map +1 -1
- 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.map +1 -1
- package/build/index.flow.js +50 -31
- package/build/index.js +27 -11
- package/build/index.js.map +1 -1
- package/build/matches.js.map +1 -1
- package/build/pure.d.ts +5 -3
- package/build/pure.js +8 -0
- package/build/pure.js.map +1 -1
- package/build/queries/a11yState.js.map +1 -1
- package/build/queries/a11yValue.js.map +1 -1
- package/build/queries/displayValue.js.map +1 -1
- package/build/queries/hintText.js.map +1 -1
- package/build/queries/labelText.js.map +1 -1
- package/build/queries/makeQueries.js.map +1 -1
- 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/testId.js.map +1 -1
- package/build/queries/text.js.map +1 -1
- package/build/queries/unsafeProps.js.map +1 -1
- package/build/queries/unsafeType.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 +21 -8
- package/build/render.js +37 -1
- package/build/render.js.map +1 -1
- package/build/renderHook.d.ts +3 -4
- package/build/renderHook.js.map +1 -1
- package/build/screen.js.map +1 -1
- package/build/shallow.js.map +1 -1
- package/build/waitFor.js +14 -11
- package/build/waitFor.js.map +1 -1
- package/build/waitForElementToBeRemoved.js.map +1 -1
- package/build/within.d.ts +18 -6
- package/build/within.js.map +1 -1
- package/package.json +22 -19
- package/typings/index.flow.js +50 -31
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"text.js","names":["getChildrenAsText","children","TextComponent","textContent","React","Children","forEach","child","push","toString","props","filterNodeByType","Fragment","getNodeByText","node","text","options","Text","require","isTextComponent","textChildren","textToTest","join","exact","normalizer","matches","error","createLibraryNotSupportedError","queryAllByText","instance","queryAllByTextFn","results","findAll","getMultipleError","String","getMissingError","getBy","getAllBy","queryBy","queryAllBy","findBy","findAllBy","makeQueries","bindByTextQueries","getByText","getAllByText","queryByText","findByText","findAllByText"],"sources":["../../src/queries/text.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport * as React from 'react';\nimport { createLibraryNotSupportedError } from '../helpers/errors';\nimport { filterNodeByType } from '../helpers/filterNodeByType';\nimport { matches, TextMatch } from '../matches';\nimport type { NormalizerFn } from '../matches';\nimport { makeQueries } from './makeQueries';\nimport type {\n FindAllByQuery,\n FindByQuery,\n GetAllByQuery,\n GetByQuery,\n QueryAllByQuery,\n QueryByQuery,\n} from './makeQueries';\n\nexport type TextMatchOptions = {\n exact?: boolean;\n normalizer?: NormalizerFn;\n};\n\nconst getChildrenAsText = (\n children: React.ReactChild[],\n TextComponent: React.ComponentType\n) => {\n const textContent: string[] = [];\n React.Children.forEach(children, (child) => {\n if (typeof child === 'string') {\n textContent.push(child);\n return;\n }\n\n if (typeof child === 'number') {\n textContent.push(child.toString());\n return;\n }\n\n if (child?.props?.children) {\n // Bail on traversing text children down the tree if current node (child)\n // has no text. In such situations, react-test-renderer will traverse down\n // this tree in a separate call and run this query again. As a result, the\n // query will match the deepest text node that matches requested text.\n if (filterNodeByType(child, TextComponent)) {\n return;\n }\n\n if (filterNodeByType(child, React.Fragment)) {\n textContent.push(\n ...getChildrenAsText(child.props.children, TextComponent)\n );\n }\n }\n });\n\n return textContent;\n};\n\nconst getNodeByText = (\n node: ReactTestInstance,\n text: TextMatch,\n options: TextMatchOptions = {}\n) => {\n try {\n const { Text } = require('react-native');\n const isTextComponent = filterNodeByType(node, Text);\n if (isTextComponent) {\n const textChildren = getChildrenAsText(node.props.children, Text);\n if (textChildren) {\n const textToTest = textChildren.join('');\n const { exact, normalizer } = options;\n return matches(text, textToTest, normalizer, exact);\n }\n }\n return false;\n } catch (error) {\n throw createLibraryNotSupportedError(error);\n }\n};\n\nconst queryAllByText = (\n instance: ReactTestInstance\n): ((\n text: TextMatch,\n options?: TextMatchOptions\n) => Array<ReactTestInstance>) =>\n function queryAllByTextFn(text, options) {\n const results = instance.findAll((node) =>\n getNodeByText(node, text, options)\n );\n\n return results;\n };\n\nconst getMultipleError = (text: TextMatch) =>\n `Found multiple elements with text: ${String(text)}`;\nconst getMissingError = (text: TextMatch) =>\n `Unable to find an element with text: ${String(text)}`;\n\nconst { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(\n queryAllByText,\n getMissingError,\n getMultipleError\n);\n\nexport type ByTextQueries = {\n getByText: GetByQuery<TextMatch, TextMatchOptions>;\n getAllByText: GetAllByQuery<TextMatch, TextMatchOptions>;\n queryByText: QueryByQuery<TextMatch, TextMatchOptions>;\n queryAllByText: QueryAllByQuery<TextMatch, TextMatchOptions>;\n findByText: FindByQuery<TextMatch, TextMatchOptions>;\n findAllByText: FindAllByQuery<TextMatch, TextMatchOptions>;\n};\n\nexport const bindByTextQueries = (\n instance: ReactTestInstance\n): ByTextQueries => ({\n getByText: getBy(instance),\n getAllByText: getAllBy(instance),\n queryByText: queryBy(instance),\n queryAllByText: queryAllBy(instance),\n findByText: findBy(instance),\n findAllByText: findAllBy(instance),\n});\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAeA,MAAMA,iBAAiB,GAAG,CACxBC,QADwB,EAExBC,aAFwB,KAGrB;EACH,MAAMC,WAAqB,GAAG,EAA9B;EACAC,KAAK,CAACC,QAAN,CAAeC,OAAf,CAAuBL,QAAvB,EAAkCM,KAAD,IAAW;IAC1C,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;MAC7BJ,WAAW,CAACK,IAAZ,CAAiBD,KAAjB;MACA;IACD;;IAED,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;MAC7BJ,WAAW,CAACK,IAAZ,CAAiBD,KAAK,CAACE,QAAN,EAAjB;MACA;IACD;;IAED,IAAIF,KAAK,EAAEG,KAAP,EAAcT,QAAlB,EAA4B;MAC1B;MACA;MACA;MACA;MACA,IAAI,IAAAU,kCAAA,EAAiBJ,KAAjB,EAAwBL,aAAxB,CAAJ,EAA4C;QAC1C;MACD;;MAED,IAAI,IAAAS,kCAAA,EAAiBJ,KAAjB,EAAwBH,KAAK,CAACQ,QAA9B,CAAJ,EAA6C;QAC3CT,WAAW,CAACK,IAAZ,CACE,GAAGR,iBAAiB,CAACO,KAAK,CAACG,KAAN,CAAYT,QAAb,EAAuBC,aAAvB,CADtB;MAGD;IACF;EACF,CA1BD;EA4BA,OAAOC,WAAP;AACD,CAlCD;;AAoCA,MAAMU,aAAa,GAAG,CACpBC,IADoB,EAEpBC,IAFoB,EAGpBC,OAAyB,GAAG,EAHR,KAIjB;EACH,IAAI;IACF,MAAM;MAAEC;IAAF,IAAWC,OAAO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e,SAAS,EAAER,KAAK,CAACP,QAAD,CADG;EAEnBgB,YAAY,EAAER,QAAQ,CAACR,QAAD,CAFH;EAGnBiB,WAAW,EAAER,OAAO,CAACT,QAAD,CAHD;EAInBD,cAAc,EAAEW,UAAU,CAACV,QAAD,CAJP;EAKnBkB,UAAU,EAAEP,MAAM,CAACX,QAAD,CALC;EAMnBmB,aAAa,EAAEP,SAAS,CAACZ,QAAD;AANL,CAFY,CAA1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"unsafeProps.js","names":["UNSAFE_getByProps","instance","getByPropsFn","props","findByProps","error","ErrorWithStack","prepareErrorMessage","UNSAFE_getAllByProps","getAllByPropsFn","results","findAllByProps","length","prettyFormat","UNSAFE_queryByProps","queryByPropsFn","createQueryByError","UNSAFE_queryAllByProps","bindUnsafeByPropsQueries"],"sources":["../../src/queries/unsafeProps.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport prettyFormat from 'pretty-format';\nimport { ErrorWithStack, prepareErrorMessage } from '../helpers/errors';\nimport { createQueryByError } from '../helpers/errors';\n\nconst UNSAFE_getByProps = (\n instance: ReactTestInstance\n): ((props: { [propName: string]: any }) => ReactTestInstance) =>\n function getByPropsFn(props: { [propName: string]: any }) {\n try {\n return instance.findByProps(props);\n } catch (error) {\n throw new ErrorWithStack(prepareErrorMessage(error), getByPropsFn);\n }\n };\n\nconst UNSAFE_getAllByProps = (\n instance: ReactTestInstance\n): ((props: { [propName: string]: any }) => Array<ReactTestInstance>) =>\n function getAllByPropsFn(props: { [propName: string]: any }) {\n const results = instance.findAllByProps(props);\n if (results.length === 0) {\n throw new ErrorWithStack(\n `No instances found with props:\\n${prettyFormat(props)}`,\n getAllByPropsFn\n );\n }\n return results;\n };\n\nconst UNSAFE_queryByProps = (\n instance: ReactTestInstance\n): ((props: { [propName: string]: any }) => ReactTestInstance | null) =>\n function queryByPropsFn(props: { [propName: string]: any }) {\n try {\n return UNSAFE_getByProps(instance)(props);\n } catch (error) {\n return createQueryByError(error, queryByPropsFn);\n }\n };\n\nconst UNSAFE_queryAllByProps =\n (\n instance: ReactTestInstance\n ): ((props: { [propName: string]: any }) => Array<ReactTestInstance>) =>\n (props: { [propName: string]: any }) => {\n try {\n return UNSAFE_getAllByProps(instance)(props);\n } catch (error) {\n return [];\n }\n };\n\n// Unsafe aliases\nexport type UnsafeByPropsQueries = {\n UNSAFE_getByProps: (props: { [key: string]: any }) => ReactTestInstance;\n UNSAFE_getAllByProps: (props: {\n [key: string]: any;\n }) => Array<ReactTestInstance>;\n UNSAFE_queryByProps: (props: {\n [key: string]: any;\n }) => ReactTestInstance | null;\n UNSAFE_queryAllByProps: (props: {\n [key: string]: any;\n }) => Array<ReactTestInstance>;\n};\n\n// TODO: migrate to makeQueries pattern\nexport const bindUnsafeByPropsQueries = (\n instance: ReactTestInstance\n): UnsafeByPropsQueries => ({\n UNSAFE_getByProps: UNSAFE_getByProps(instance),\n UNSAFE_getAllByProps: UNSAFE_getAllByProps(instance),\n UNSAFE_queryByProps: UNSAFE_queryByProps(instance),\n UNSAFE_queryAllByProps: UNSAFE_queryAllByProps(instance),\n});\n"],"mappings":";;;;;;;AACA;;AACA;;;;AAGA,MAAMA,iBAAiB,GACrBC,QADwB,IAGxB,SAASC,YAAT,CAAsBC,KAAtB,EAA0D;EACxD,IAAI;IACF,OAAOF,QAAQ,CAACG,WAAT,CAAqBD,KAArB,CAAP;EACD,CAFD,CAEE,OAAOE,KAAP,EAAc;IACd,MAAM,IAAIC,sBAAJ,CAAmB,IAAAC,2BAAA,EAAoBF,KAApB,CAAnB,EAA+CH,YAA/C,CAAN;EACD;AACF,CATH;;AAWA,MAAMM,oBAAoB,GACxBP,QAD2B,IAG3B,SAASQ,eAAT,CAAyBN,KAAzB,EAA6D;EAC3D,MAAMO,OAAO,GAAGT,QAAQ,CAACU,cAAT,CAAwBR,KAAxB,CAAhB;;EACA,IAAIO,OAAO,CAACE,MAAR,KAAmB,CAAvB,EAA0B;IACxB,MAAM,IAAIN,sBAAJ,CACH,mCAAkC,IAAAO,qBAAA,EAAaV,KAAb,CAAoB,EADnD,EAEJM,eAFI,CAAN;EAID;;EACD,OAAOC,OAAP;AACD,CAZH;;AAcA,MAAMI,mBAAmB,GACvBb,QAD0B,IAG1B,SAASc,cAAT,CAAwBZ,KAAxB,EAA4D;EAC1D,IAAI;IACF,OAAOH,iBAAiB,CAACC,QAAD,CAAjB,CAA4BE,KAA5B,CAAP;EACD,CAFD,CAEE,OAAOE,KAAP,EAAc;IACd,OAAO,IAAAW,0BAAA,EAAmBX,KAAnB,EAA0BU,cAA1B,CAAP;EACD;AACF,CATH;;AAWA,MAAME,sBAAsB,GAExBhB,QADF,IAGCE,KAAD,IAAwC;EACtC,IAAI;IACF,OAAOK,oBAAoB,CAACP,QAAD,CAApB,CAA+BE,KAA/B,CAAP;EACD,CAFD,CAEE,OAAOE,KAAP,EAAc;IACd,OAAO,EAAP;EACD;AACF,CAVH,C,CAYA;;;AAcA;AACO,MAAMa,wBAAwB,GACnCjB,QADsC,KAEZ;EAC1BD,iBAAiB,EAAEA,iBAAiB,CAACC,QAAD,CADV;EAE1BO,oBAAoB,EAAEA,oBAAoB,CAACP,QAAD,CAFhB;EAG1Ba,mBAAmB,EAAEA,mBAAmB,CAACb,QAAD,CAHd;EAI1BgB,sBAAsB,EAAEA,sBAAsB,CAAChB,QAAD;AAJpB,CAFY,CAAjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"unsafeType.js","names":["UNSAFE_getByType","instance","getByTypeFn","type","findByType","error","ErrorWithStack","prepareErrorMessage","UNSAFE_getAllByType","getAllByTypeFn","results","findAllByType","length","UNSAFE_queryByType","queryByTypeFn","createQueryByError","UNSAFE_queryAllByType","bindUnsafeByTypeQueries"],"sources":["../../src/queries/unsafeType.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport * as React from 'react';\nimport { ErrorWithStack, prepareErrorMessage } from '../helpers/errors';\nimport { createQueryByError } from '../helpers/errors';\n\nconst UNSAFE_getByType = (\n instance: ReactTestInstance\n): ((type: React.ComponentType<any>) => ReactTestInstance) =>\n function getByTypeFn(type: React.ComponentType<any>) {\n try {\n return instance.findByType(type);\n } catch (error) {\n throw new ErrorWithStack(prepareErrorMessage(error), getByTypeFn);\n }\n };\n\nconst UNSAFE_getAllByType = (\n instance: ReactTestInstance\n): ((type: React.ComponentType<any>) => Array<ReactTestInstance>) =>\n function getAllByTypeFn(type: React.ComponentType<any>) {\n const results = instance.findAllByType(type);\n if (results.length === 0) {\n throw new ErrorWithStack('No instances found', getAllByTypeFn);\n }\n return results;\n };\n\nconst UNSAFE_queryByType = (\n instance: ReactTestInstance\n): ((type: React.ComponentType<any>) => ReactTestInstance | null) =>\n function queryByTypeFn(type: React.ComponentType<any>) {\n try {\n return UNSAFE_getByType(instance)(type);\n } catch (error) {\n return createQueryByError(error, queryByTypeFn);\n }\n };\n\nconst UNSAFE_queryAllByType =\n (\n instance: ReactTestInstance\n ): ((type: React.ComponentType<any>) => Array<ReactTestInstance>) =>\n (type: React.ComponentType<any>) => {\n try {\n return UNSAFE_getAllByType(instance)(type);\n } catch (error) {\n return [];\n }\n };\n\n// Unsafe aliases\nexport type UnsafeByTypeQueries = {\n UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;\n UNSAFE_getAllByType: <P>(\n type: React.ComponentType<P>\n ) => Array<ReactTestInstance>;\n UNSAFE_queryByType: <P>(\n type: React.ComponentType<P>\n ) => ReactTestInstance | null;\n UNSAFE_queryAllByType: <P>(\n type: React.ComponentType<P>\n ) => Array<ReactTestInstance>;\n};\n\n// TODO: migrate to makeQueries pattern\nexport const bindUnsafeByTypeQueries = (\n instance: ReactTestInstance\n): UnsafeByTypeQueries => ({\n UNSAFE_getByType: UNSAFE_getByType(instance),\n UNSAFE_getAllByType: UNSAFE_getAllByType(instance),\n UNSAFE_queryBy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AAD,CADT;EAEzBO,mBAAmB,EAAEA,mBAAmB,CAACP,QAAD,CAFf;EAGzBY,kBAAkB,EAAEA,kBAAkB,CAACZ,QAAD,CAHb;EAIzBe,qBAAqB,EAAEA,qBAAqB,CAACf,QAAD;AAJnB,CAFY,CAAhC"}
|
|
@@ -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
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import TestRenderer from 'react-test-renderer';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
declare type
|
|
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 }?:
|
|
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,"
|
|
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":";;;;;;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,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/renderHook.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { ComponentType } from 'react';
|
|
2
|
-
|
|
2
|
+
export declare type RenderHookResult<Result, Props> = {
|
|
3
3
|
rerender: (props: Props) => void;
|
|
4
4
|
result: {
|
|
5
5
|
current: Result;
|
|
6
6
|
};
|
|
7
7
|
unmount: () => void;
|
|
8
|
-
}
|
|
9
|
-
declare type RenderHookOptions<Props> = Props extends object | string | number | boolean ? {
|
|
8
|
+
};
|
|
9
|
+
export declare type RenderHookOptions<Props> = Props extends object | string | number | boolean ? {
|
|
10
10
|
initialProps: Props;
|
|
11
11
|
wrapper?: ComponentType<any>;
|
|
12
12
|
} : {
|
|
@@ -14,4 +14,3 @@ declare type RenderHookOptions<Props> = Props extends object | string | number |
|
|
|
14
14
|
initialProps?: never;
|
|
15
15
|
} | undefined;
|
|
16
16
|
export declare function renderHook<Result, Props>(renderCallback: (props: Props) => Result, options?: RenderHookOptions<Props>): RenderHookResult<Result, Props>;
|
|
17
|
-
export {};
|
package/build/renderHook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"renderHook.js","names":["renderHook","renderCallback","options","initialProps","wrapper","result","React","createRef","TestComponent","renderCallbackProps","renderResult","useEffect","current","rerender","baseRerender","unmount","render","rerenderCallbackProps"],"sources":["../src/renderHook.tsx"],"sourcesContent":["import React from 'react';\nimport type { ComponentType } from 'react';\nimport render from './render';\n\nexport type RenderHookResult<Result, Props> = {\n rerender: (props: Props) => void;\n result: { current: Result };\n unmount: () => void;\n};\n\nexport type RenderHookOptions<Props> = Props extends\n | object\n | string\n | number\n | boolean\n ? {\n initialProps: Props;\n wrapper?: ComponentType<any>;\n }\n : { wrapper?: ComponentType<any>; initialProps?: never } | undefined;\n\nexport function renderHook<Result, Props>(\n renderCallback: (props: Props) => Result,\n options?: RenderHookOptions<Props>\n): RenderHookResult<Result, Props> {\n const initialProps = options?.initialProps;\n const wrapper = options?.wrapper;\n\n const result: React.MutableRefObject<Result | null> = React.createRef();\n\n function TestComponent({\n renderCallbackProps,\n }: {\n renderCallbackProps: Props;\n }) {\n const renderResult = renderCallback(renderCallbackProps);\n\n React.useEffect(() => {\n result.current = renderResult;\n });\n\n return null;\n }\n\n const { rerender: baseRerender, unmount } = render(\n // @ts-expect-error since option can be undefined, initialProps can be undefined when it should'nt\n <TestComponent renderCallbackProps={initialProps} />,\n { wrapper }\n );\n\n function rerender(rerenderCallbackProps: Props) {\n return baseRerender(\n <TestComponent renderCallbackProps={rerenderCallbackProps} />\n );\n }\n\n // @ts-expect-error result is ill typed because ref is initialized to null\n return { result, rerender, unmount };\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;;;AAmBO,SAASA,UAAT,CACLC,cADK,EAELC,OAFK,EAG4B;EACjC,MAAMC,YAAY,GAAGD,OAAO,EAAEC,YAA9B;EACA,MAAMC,OAAO,GAAGF,OAAO,EAAEE,OAAzB;;EAEA,MAAMC,MAA6C,gBAAGC,cAAA,CAAMC,SAAN,EAAtD;;EAEA,SAASC,aAAT,CAAuB;IACrBC;EADqB,CAAvB,EAIG;IACD,MAAMC,YAAY,GAAGT,cAAc,CAACQ,mBAAD,CAAnC;;IAEAH,cAAA,CAAMK,SAAN,CAAgB,MAAM;MACpBN,MAAM,CAACO,OAAP,GAAiBF,YAAjB;IACD,CAFD;;IAIA,OAAO,IAAP;EACD;;EAED,MAAM;IAAEG,QAAQ,EAAEC,YAAZ;IAA0BC;EAA1B,IAAsC,IAAAC,eAAA;EAAA;EAC1C;EACA,6BAAC,aAAD;IAAe,mBAAmB,EAAEb;EAApC,EAF0C,EAG1C;IAAEC;EAAF,CAH0C,CAA5C;;EAMA,SAASS,QAAT,CAAkBI,qBAAlB,EAAgD;IAC9C,OAAOH,YAAY,eACjB,6BAAC,aAAD;MAAe,mBAAmB,EAAEG;IAApC,EADiB,CAAnB;EAGD,CA9BgC,CAgCjC;;;EACA,OAAO;IAAEZ,MAAF;IAAUQ,QAAV;IAAoBE;EAApB,CAAP;AACD"}
|
package/build/screen.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"screen.js","names":["SCREEN_ERROR","notImplemented","Error","notImplementedDebug","shallow","defaultScreen","container","debug","update","unmount","rerender","toJSON","getByLabelText","getAllByLabelText","queryByLabelText","queryAllByLabelText","findByLabelText","findAllByLabelText","getByHintText","getAllByHintText","queryByHintText","queryAllByHintText","findByHintText","findAllByHintText","getByA11yHint","getAllByA11yHint","queryByA11yHint","queryAllByA11yHint","findByA11yHint","findAllByA11yHint","getByAccessibilityHint","getAllByAccessibilityHint","queryByAccessibilityHint","queryAllByAccessibilityHint","findByAccessibilityHint","findAllByAccessibilityHint","getByRole","getAllByRole","queryByRole","queryAllByRole","findByRole","findAllByRole","getByA11yState","getAllByA11yState","queryByA11yState","queryAllByA11yState","findByA11yState","findAllByA11yState","getByAccessibilityState","getAllByAccessibilityState","queryByAccessibilityState","queryAllByAccessibilityState","findByAccessibilityState","findAllByAccessibilityState","getByA11yValue","getAllByA11yValue","queryByA11yValue","queryAllByA11yValue","findByA11yValue","findAllByA11yValue","getByAccessibilityValue","getAllByAccessibilityValue","queryByAccessibilityValue","queryAllByAccessibilityValue","findByAccessibilityValue","findAllByAccessibilityValue","UNSAFE_getByProps","UNSAFE_getAllByProps","UNSAFE_queryByProps","UNSAFE_queryAllByProps","UNSAFE_getByType","UNSAFE_getAllByType","UNSAFE_queryByType","UNSAFE_queryAllByType","getByPlaceholderText","getAllByPlaceholderText","queryByPlaceholderText","queryAllByPlaceholderText","findByPlaceholderText","findAllByPlaceholderText","getByDisplayValue","getAllByDisplayValue","queryByDisplayValue","queryAllByDisplayValue","findByDisplayValue","findAllByDisplayValue","getByTestId","getAllByTestId","queryByTestId","queryAllByTestId","findByTestId","findAllByTestId","getByText","getAllByText","queryByText","queryAllByText","findByText","findAllByText","screen","setRenderResult","output","clearRenderResult"],"sources":["../src/screen.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { RenderResult } from './render';\n\nconst SCREEN_ERROR = '`render` method has not been called';\n\nconst notImplemented = () => {\n throw new Error(SCREEN_ERROR);\n};\n\nconst notImplementedDebug = () => {\n throw new Error(SCREEN_ERROR);\n};\nnotImplementedDebug.shallow = notImplemented;\n\nconst defaultScreen: RenderResult = {\n get container(): ReactTestInstance {\n throw new Error(SCREEN_ERROR);\n },\n debug: notImplementedDebug,\n update: notImplemented,\n unmount: notImplemented,\n rerender: notImplemented,\n toJSON: notImplemented,\n getByLabelText: notImplemented,\n getAllByLabelText: notImplemented,\n queryByLabelText: notImplemented,\n queryAllByLabelText: notImplemented,\n findByLabelText: notImplemented,\n findAllByLabelText: notImplemented,\n getByHintText: notImplemented,\n getAllByHintText: notImplemented,\n queryByHintText: notImplemented,\n queryAllByHintText: notImplemented,\n findByHintText: notImplemented,\n findAllByHintText: notImplemented,\n getByA11yHint: notImplemented,\n getAllByA11yHint: notImplemented,\n queryByA11yHint: notImplemented,\n queryAllByA11yHint: notImplemented,\n findByA11yHint: notImplemented,\n findAllByA11yHint: notImplemented,\n getByAccessibilityHint: notImplemented,\n getAllByAccessibilityHint: notImplemented,\n queryByAccessibilityHint: notImplemented,\n queryAllByAccessibilityHint: notImplemented,\n findByAccessibilityHint: notImplemented,\n findAllByAccessibilityHint: notImplemented,\n getByRole: notImplemented,\n getAllByRole: notImplemented,\n queryByRole: notImplemented,\n queryAllByRole: notImplemented,\n findByRole: notImplemented,\n findAllByRole: notImplemented,\n getByA11yState: notImplemented,\n getAllByA11yState: notImplemented,\n queryByA11yState: notImplemented,\n queryAllByA11yState: notImplemented,\n findByA11yState: notImplemented,\n findAllByA11yState: notImplemented,\n getByAccessibilityState: notImplemented,\n getAllByAccessibilityState: notImplemented,\n queryByAccessibilityState: notImplemented,\n queryAllByAccessibilityState: notImplemented,\n findByAccessibilityState: notImplemented,\n findAllByAccessibilityState: notImplemented,\n getByA11yValue: notImplemented,\n getAllByA11yValue: notImplemented,\n queryByA11yValue: notImplemented,\n queryAllByA11yValue: notImplemented,\n findByA11yValue: notImplemented,\n findAllByA11yValue: notImplemented,\n getByAccessibilityValue: notImplemented,\n getAllByAccessibilityValue: notImplemented,\n queryByAccessibilityValue: notImplemented,\n queryAllByAccessibilityValue: notImplemented,\n findByAccessibilityValue: notImplemented,\n findAllByAccessibilityValue: notImplemented,\n UNSAFE_getByProps: notImplemented,\n UNSAFE_getAllByProps: notImplemented,\n UNSAFE_queryByProps: notImplemented,\n UNSAFE_queryAllByProps: notImplemented,\n UNSAFE_getByType: notImplemented,\n UNSAFE_getAllByType: notImplemented,\n UNSAFE_queryByType: notImplemented,\n UNSAFE_queryAllByType: notImplemented,\n getByPlaceholderText: notImplemented,\n getAllByPlaceholderText: notImplemented,\n queryByPlaceholderText: notImplemented,\n queryAllByPlaceholderText: notImplemented,\n findByPlaceholderText: notImplemented,\n findAllByPlaceholderText: notImplemented,\n getByDisplayValue: notImplemented,\n getAllByDisplayValue: notImplemented,\n queryByDisplayValue: notImplemented,\n queryAllByDisplayValue: notImplemented,\n findByDisplayValue: notImplemented,\n findAllByDisplayValue: notImplemented,\n getByTestId: notImplemented,\n getAllByTestId: notImplemented,\n queryByTestId: notImplemented,\n queryAllByTestId: notImplemented,\n findByTestId: notImplemented,\n findAllByTestId: notImplemented,\n getByText: notImplemented,\n getAllByText: notImplemented,\n queryByText: notImplemented,\n queryAllByText: notImplemented,\n findByText: notImplemented,\n findAllByText: notImplemented,\n};\n\nexport let screen: RenderResult = defaultScreen;\n\nexport function setRenderResult(output: RenderResult) {\n screen = output;\n}\n\nexport function clearRenderResult() {\n screen = defaultScreen;\n}\n"],"mappings":";;;;;;;;AAGA,MAAMA,YAAY,GAAG,qCAArB;;AAEA,MAAMC,cAAc,GAAG,MAAM;EAC3B,MAAM,IAAIC,KAAJ,CAAUF,YAAV,CAAN;AACD,CAFD;;AAIA,MAAMG,mBAAmB,GAAG,MAAM;EAChC,MAAM,IAAID,KAAJ,CAAUF,YAAV,CAAN;AACD,CAFD;;AAGAG,mBAAmB,CAACC,OAApB,GAA8BH,cAA9B;AAEA,MAAMI,aAA2B,GAAG;EAClC,IAAIC,SAAJ,GAAmC;IACjC,MAAM,IAAIJ,KAAJ,CAAUF,YAAV,CAAN;EACD,CAHiC;;EAIlCO,KAAK,EAAEJ,mBAJ2B;EAKlCK,MAAM,EAAEP,cAL0B;EAMlCQ,OAAO,EAAER,cANyB;EAOlCS,QAAQ,EAAET,cAPwB;EAQlCU,MAAM,EAAEV,cAR0B;EASlCW,cAAc,EAAEX,cATkB;EAUlCY,iBAAiB,EAAEZ,cAVe;EAWlCa,gBAAgB,EAAEb,cAXgB;EAYlCc,mBAAmB,EAAEd,cAZa;EAalCe,eAAe,EAAEf,cAbiB;EAclCgB,kBAAkB,EAAEhB,cAdc;EAelCiB,aAAa,EAAEjB,cAfmB;EAgBlCkB,gBAAgB,EAAElB,cAhBgB;EAiBlCmB,eAAe,EAAEnB,cAjBiB;EAkBlCoB,kBAAkB,EAAEpB,cAlBc;EAmBlCqB,cAAc,EAAErB,cAnBkB;EAoBlCsB,iBAAiB,EAAEtB,cApBe;EAqBlCuB,aAAa,EAAEvB,cArBmB;EAsBlCwB,gBAAgB,EAAExB,cAtBgB;EAuBlCyB,eAAe,EAAEzB,cAvBiB;EAwBlC0B,kBAAkB,EAAE1B,cAxBc;EAyBlC2B,cAAc,EAAE3B,cAzBkB;EA0BlC4B,iBAAiB,EAAE5B,cA1Be;EA2BlC6B,sBAAsB,EAAE7B,cA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F,aAAT;AACD"}
|
package/build/shallow.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"shallow.js","names":["shallowInternal","instance","renderer","ShallowRenderer","render","React","createElement","type","props","output","getRenderOutput"],"sources":["../src/shallow.ts"],"sourcesContent":["import * as React from 'react';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport ShallowRenderer from 'react-test-renderer/shallow'; // eslint-disable-line import/no-extraneous-dependencies\n\n/**\n * Renders test component shallowly using react-test-renderer/shallow\n */\nexport function shallowInternal(\n instance: ReactTestInstance | React.ReactElement<any>\n): { output: any } {\n const renderer = new (ShallowRenderer as any)();\n\n renderer.render(React.createElement(instance.type, instance.props));\n\n return {\n output: renderer.getRenderOutput(),\n };\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;;;;;;;AAA2D;;AAE3D;AACA;AACA;AACO,SAASA,eAAT,CACLC,QADK,EAEY;EACjB,MAAMC,QAAQ,GAAG,IAAKC,gBAAL,EAAjB;EAEAD,QAAQ,CAACE,MAAT,eAAgBC,KAAK,CAACC,aAAN,CAAoBL,QAAQ,CAACM,IAA7B,EAAmCN,QAAQ,CAACO,KAA5C,CAAhB;EAEA,OAAO;IACLC,MAAM,EAAEP,QAAQ,CAACQ,eAAT;EADH,CAAP;AAGD"}
|
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,"sources":["../src/waitFor.ts"],"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","handleTimeout","usingFakeTimers","checkExpectation","fakeTimeRemaining","error","Error","jest","advanceTimersByTime","setInterval","checkRealTimersCallback","onDone","done","clearInterval","type","result","then","promiseResult","resolvedValue","rejectedValue","waitFor","options","ErrorWithStack","optionsWithStackTrace"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAJA;AAWA,MAAMA,eAAe,GAAG,IAAxB;AACA,MAAMC,gBAAgB,GAAG,EAAzB;;AAEA,SAASC,wBAAT,CAAkCC,KAAlC,EAAiDC,KAAjD,EAAyE;AACvE,MAAIC,KAAK,CAACC,OAAN,KAAkBC,SAAtB,EAAiC,OAAO,KAAP;AACjC,QAAM,CAACC,WAAD,EAAcC,WAAd,IAA6BJ,KAAK,CAACC,OAAN,CAAcI,KAAd,CAAoB,GAApB,EAAyBC,GAAzB,CAA6BC,MAA7B,CAAnC;AAEA,SAAOJ,WAAW,GAAGL,KAAd,IAAwBK,WAAW,KAAKL,KAAhB,IAAyBM,WAAW,IAAIL,KAAvE;AACD;;AASD,SAASS,eAAT,CACEC,WADF,EAEE;AACEC,EAAAA,OAAO,GAAGf,eADZ;AAEEgB,EAAAA,QAAQ,GAAGf,gBAFb;AAGEgB,EAAAA,eAHF;AAIEC,EAAAA;AAJF,CAFF,EAQc;AACZ,MAAI,OAAOJ,WAAP,KAAuB,UAA3B,EAAuC;AACrC,UAAM,IAAIK,SAAJ,CAAc,+CAAd,CAAN;AACD,GAHW,CAKZ;;;AACA,SAAO,IAAIC,OAAJ,CAAY,OAAOC,OAAP,EAAgBC,MAAhB,KAA2B;AAC5C,QAAIC,SAAJ,EAAwBC,UAAxB;AACA,QAAIC,QAAQ,GAAG,KAAf;AACA,QAAIC,a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AACA,UAAIT,SAAJ,EAAe;AACbS,QAAAA,KAAK,GAAGT,SAAR;;AACA,YAAIN,eAAJ,EAAqB;AACnB,sCAAee,KAAf,EAAsBf,eAAtB;AACD;AACF,OALD,MAKO;AACLe,QAAAA,KAAK,GAAG,IAAIC,KAAJ,CAAU,uBAAV,CAAR;;AACA,YAAIhB,eAAJ,EAAqB;AACnB,sCAAee,KAAf,EAAsBf,eAAtB;AACD;AACF;;AACD,UAAI,OAAOC,SAAP,KAAqB,UAAzB,EAAqC;AACnCA,QAAAA,SAAS,CAACc,KAAD,CAAT;AACD;;AACDM,MAAAA,MAAM,CAAC;AAAEG,QAAAA,IAAI,EAAE,OAAR;AAAiBT,QAAAA;AAAjB,OAAD,CAAN;AACD;AACF,GA/IM,CAAP;AAgJD;;AAEc,eAAee,OAAf,CACbjC,WADa,EAEbkC,OAFa,EAGD;AACZ;AACA,QAAM/B,eAAe,GAAG,IAAIgC,sBAAJ,CAAmB,mBAAnB,EAAwCF,OAAxC,CAAxB;AACA,QAAMG,qBAAqB,GAAG;AAAEjC,IAAAA,eAAF;AAAmB,OAAG+B;AAAtB,GAA9B;;AAEA,MAAI,CAAC9C,wBAAwB,CAAC,EAAD,EAAK,CAAL,CAA7B,EAAsC;AACpC,WAAOW,eAAe,CAACC,WAAD,EAAcoC,qBAAd,CAAtB;AACD;;AAED,MAAIR,MAAJ;AAEA,QAAM,kBAAI,YAAY;AACpBA,IAAAA,MAAM,GAAG,MAAM7B,eAAe,CAACC,WAAD,EAAcoC,qBAAd,CAA9B;AACD,GAFK,CAAN,CAXY,CAeZ;;AACA,SAAOR,MAAP;AACD","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"],"file":"waitFor.js"}
|
|
1
|
+
{"version":3,"file":"waitFor.js","names":["DEFAULT_TIMEOUT","DEFAULT_INTERVAL","waitForInternal","expectation","timeout","interval","stackTraceError","onTimeout","TypeError","Promise","resolve","reject","lastError","intervalId","finished","promiseStatus","overallTimeoutTimer","setTimeout","handleTimeout","usingFakeTimers","jestFakeTimersAreEnabled","checkExpectation","fakeTimeRemaining","error","Error","copyStackTrace","jest","advanceTimersByTime","setImmediate","setInterval","checkRealTimersCallback","onDone","done","clearTimeout","clearInterval","type","result","then","promiseResult","resolvedValue","rejectedValue","waitFor","options","ErrorWithStack","optionsWithStackTrace","checkReactVersionAtLeast","previousActEnvironment","getIsReactActEnvironment","setReactActEnvironment","act"],"sources":["../src/waitFor.ts"],"sourcesContent":["/* globals jest */\nimport act, { setReactActEnvironment, getIsReactActEnvironment } from './act';\nimport { ErrorWithStack, copyStackTrace } from './helpers/errors';\nimport {\n setTimeout,\n clearTimeout,\n setImmediate,\n jestFakeTimersAreEnabled,\n} from './helpers/timers';\nimport { checkReactVersionAtLeast } from './react-versions';\n\nconst DEFAULT_TIMEOUT = 1000;\nconst DEFAULT_INTERVAL = 50;\n\nexport type WaitForOptions = {\n timeout?: number;\n interval?: number;\n stackTraceError?: ErrorWithStack;\n onTimeout?: (error: unknown) => Error;\n};\n\nfunction waitForInternal<T>(\n expectation: () => T,\n {\n timeout = DEFAULT_TIMEOUT,\n interval = DEFAULT_INTERVAL,\n stackTraceError,\n onTimeout,\n }: WaitForOptions\n): Promise<T> {\n if (typeof expectation !== 'function') {\n throw new TypeError('Received `expectation` arg must be a function');\n }\n\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n let lastError: unknown, intervalId: ReturnType<typeof setTimeout>;\n let finished = false;\n let promiseStatus = 'idle';\n\n const overallTimeoutTimer = setTimeout(handleTimeout, timeout);\n\n const usingFakeTimers = jestFakeTimersAreEnabled();\n\n if (usingFakeTimers) {\n checkExpectation();\n // this is a dangerous rule to disable because it could lead to an\n // infinite loop. However, eslint isn't smart enough to know that we're\n // setting finished inside `onDone` which will be called when we're done\n // waiting or when we've timed out.\n // eslint-disable-next-line no-unmodified-loop-condition\n let fakeTimeRemaining = timeout;\n while (!finished) {\n if (!jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n reject(error);\n return;\n }\n\n // when fake timers are used we want to simulate the interval time passing\n if (fakeTimeRemaining <= 0) {\n return;\n } else {\n fakeTimeRemaining -= interval;\n }\n\n // we *could* (maybe should?) use `advanceTimersToNextTimer` but it's\n // possible that could make this loop go on forever if someone is using\n // third party code that's setting up recursive timers so rapidly that\n // the user's timer's don't get a chance to resolve. So we'll advance\n // by an interval instead. (We have a test for this case).\n jest.advanceTimersByTime(interval);\n\n // It's really important that checkExpectation is run *before* we flush\n // in-flight promises. To be honest, I'm not sure why, and I can't quite\n // think of a way to reproduce the problem in a test, but I spent\n // an entire day banging my head against a wall on this.\n checkExpectation();\n\n // In this rare case, we *need* to wait for in-flight promises\n // to resolve before continuing. We don't need to take advantage\n // of parallelization so we're fine.\n // https://stackoverflow.com/a/59243586/971592\n // eslint-disable-next-line no-await-in-loop\n await new Promise((resolve) => setImmediate(resolve));\n }\n } else {\n intervalId = setInterval(checkRealTimersCallback, interval);\n checkExpectation();\n }\n\n function onDone(\n done: { type: 'result'; result: T } | { type: 'error'; error: unknown }\n ) {\n finished = true;\n clearTimeout(overallTimeoutTimer);\n\n if (!usingFakeTimers) {\n clearInterval(intervalId);\n }\n\n if (done.type === 'error') {\n reject(done.error);\n } else {\n resolve(done.result);\n }\n }\n\n function checkRealTimersCallback() {\n if (jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n return reject(error);\n } else {\n return checkExpectation();\n }\n }\n\n function checkExpectation() {\n if (promiseStatus === 'pending') return;\n try {\n const result = expectation();\n\n // @ts-ignore result can be a promise\n // eslint-disable-next-line promise/prefer-await-to-then\n if (typeof result?.then === 'function') {\n const promiseResult: Promise<T> = result as any;\n promiseStatus = 'pending';\n // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then\n promiseResult.then(\n (resolvedValue) => {\n promiseStatus = 'resolved';\n onDone({ type: 'result', result: resolvedValue });\n return;\n },\n (rejectedValue) => {\n promiseStatus = 'rejected';\n lastError = rejectedValue;\n return;\n }\n );\n } else {\n onDone({ type: 'result', result: result });\n }\n // If `callback` throws, wait for the next mutation, interval, or timeout.\n } catch (error) {\n // Save the most recent callback error to reject the promise with it in the event of a timeout\n lastError = error;\n }\n }\n\n function handleTimeout() {\n let error;\n if (lastError) {\n error = lastError;\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n } else {\n error = new Error('Timed out in waitFor.');\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n }\n if (typeof onTimeout === 'function') {\n onTimeout(error);\n }\n onDone({ type: 'error', error });\n }\n });\n}\n\nexport default async function waitFor<T>(\n expectation: () => T,\n options?: WaitForOptions\n): Promise<T> {\n // Being able to display a useful stack trace requires generating it before doing anything async\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', waitFor);\n const optionsWithStackTrace = { stackTraceError, ...options };\n\n if (checkReactVersionAtLeast(18, 0)) {\n const previousActEnvironment = getIsReactActEnvironment();\n setReactActEnvironment(false);\n\n try {\n return await waitForInternal(expectation, optionsWithStackTrace);\n } finally {\n setReactActEnvironment(previousActEnvironment);\n }\n }\n\n if (!checkReactVersionAtLeast(16, 9)) {\n return waitForInternal(expectation, optionsWithStackTrace);\n }\n\n let result: T;\n\n await act(async () => {\n result = await waitForInternal(expectation, optionsWithStackTrace);\n });\n\n // Either we have result or `waitFor` threw error\n return result!;\n}\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AAMA;;;;;;AATA;AAWA,MAAMA,eAAe,GAAG,IAAxB;AACA,MAAMC,gBAAgB,GAAG,EAAzB;;AASA,SAASC,eAAT,CACEC,WADF,EAEE;EACEC,OAAO,GAAGJ,eADZ;EAEEK,QAAQ,GAAGJ,gBAFb;EAGEK,eAHF;EAIEC;AAJF,CAFF,EAQc;EACZ,IAAI,OAAOJ,WAAP,KAAuB,UAA3B,EAAuC;IACrC,MAAM,IAAIK,SAAJ,CAAc,+CAAd,CAAN;EACD,CAHW,CAKZ;;;EACA,OAAO,IAAIC,OAAJ,CAAY,OAAOC,OAAP,EAAgBC,MAAhB,KAA2B;IAC5C,IAAIC,SAAJ,EAAwBC,UAAxB;IACA,IAAIC,QAAQ,GAAG,KAAf;IACA,IAAIC,aAAa,GAAG,MAApB;IAEA,MAAMC,mBAAm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1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"waitForElementToBeRemoved.js","names":["isRemoved","result","Array","isArray","length","waitForElementToBeRemoved","expectation","options","timeoutError","ErrorWithStack","initialElements","waitFor","error"],"sources":["../src/waitForElementToBeRemoved.ts"],"sourcesContent":["import waitFor from './waitFor';\nimport type { WaitForOptions } from './waitFor';\nimport { ErrorWithStack } from './helpers/errors';\n\nfunction isRemoved<T>(result: T): boolean {\n return !result || (Array.isArray(result) && !result.length);\n}\n\nexport default async function waitForElementToBeRemoved<T>(\n expectation: () => T,\n options?: WaitForOptions\n): Promise<T> {\n // Created here so we get a nice stacktrace\n const timeoutError = new ErrorWithStack(\n 'Timed out in waitForElementToBeRemoved.',\n waitForElementToBeRemoved\n );\n\n // Elements have to be present initally and then removed.\n const initialElements = expectation();\n if (isRemoved(initialElements)) {\n throw new ErrorWithStack(\n 'The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.',\n waitForElementToBeRemoved\n );\n }\n\n return waitFor(() => {\n let result;\n try {\n result = expectation();\n } catch (error) {\n return initialElements;\n }\n\n if (!isRemoved(result)) {\n throw timeoutError;\n }\n\n return initialElements;\n }, options);\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;;;AAEA,SAASA,SAAT,CAAsBC,MAAtB,EAA0C;EACxC,OAAO,CAACA,MAAD,IAAYC,KAAK,CAACC,OAAN,CAAcF,MAAd,KAAyB,CAACA,MAAM,CAACG,MAApD;AACD;;AAEc,eAAeC,yBAAf,CACbC,WADa,EAEbC,OAFa,EAGD;EACZ;EACA,MAAMC,YAAY,GAAG,IAAIC,sBAAJ,CACnB,yCADmB,EAEnBJ,yBAFmB,CAArB,CAFY,CAOZ;;EACA,MAAMK,eAAe,GAAGJ,WAAW,EAAnC;;EACA,IAAIN,SAAS,CAACU,eAAD,CAAb,EAAgC;IAC9B,MAAM,IAAID,sBAAJ,CACJ,oKADI,EAEJJ,yBAFI,CAAN;EAID;;EAED,OAAO,IAAAM,gBAAA,EAAQ,MAAM;IACnB,IAAIV,MAAJ;;IACA,IAAI;MACFA,MAAM,GAAGK,WAAW,EAApB;IACD,CAFD,CAEE,OAAOM,KAAP,EAAc;MACd,OAAOF,eAAP;IACD;;IAED,IAAI,CAACV,SAAS,CAACC,MAAD,CAAd,EAAwB;MACtB,MAAMO,YAAN;IACD;;IAED,OAAOE,eAAP;EACD,CAbM,EAaJH,OAbI,CAAP;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/build/within.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"within.js","names":["within","instance","bindByTextQueries","bindByTestIdQueries","bindByDisplayValueQueries","bindByPlaceholderTextQueries","bindByLabelTextQueries","bindByHintTextQueries","bindByRoleQueries","bindByA11yStateQueries","bindByA11yValueQueries","bindUnsafeByTypeQueries","bindUnsafeByPropsQueries","getQueriesForElement"],"sources":["../src/within.ts"],"sourcesContent":["import type { ReactTestInstance } from 'react-test-renderer';\nimport { bindByTextQueries } from './queries/text';\nimport { bindByTestIdQueries } from './queries/testId';\nimport { bindByDisplayValueQueries } from './queries/displayValue';\nimport { bindByPlaceholderTextQueries } from './queries/placeholderText';\nimport { bindByLabelTextQueries } from './queries/labelText';\nimport { bindByHintTextQueries } from './queries/hintText';\nimport { bindByRoleQueries } from './queries/role';\nimport { bindByA11yStateQueries } from './queries/a11yState';\nimport { bindByA11yValueQueries } from './queries/a11yValue';\nimport { bindUnsafeByTypeQueries } from './queries/unsafeType';\nimport { bindUnsafeByPropsQueries } from './queries/unsafeProps';\n\nexport function within(instance: ReactTestInstance) {\n return {\n ...bindByTextQueries(instance),\n ...bindByTestIdQueries(instance),\n ...bindByDisplayValueQueries(instance),\n ...bindByPlaceholderTextQueries(instance),\n ...bindByLabelTextQueries(instance),\n ...bindByHintTextQueries(instance),\n ...bindByRoleQueries(instance),\n ...bindByA11yStateQueries(instance),\n ...bindByA11yValueQueries(instance),\n ...bindUnsafeByTypeQueries(instance),\n ...bindUnsafeByPropsQueries(instance),\n };\n}\n\nexport const getQueriesForElement = within;\n"],"mappings":";;;;;;;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEO,SAASA,MAAT,CAAgBC,QAAhB,EAA6C;EAClD,OAAO,EACL,GAAG,IAAAC,uBAAA,EAAkBD,QAAlB,CADE;IAEL,GAAG,IAAAE,2BAAA,EAAoBF,QAApB,CAFE;IAGL,GAAG,IAAAG,uCAAA,EAA0BH,QAA1B,CAHE;IAIL,GAAG,IAAAI,6CAAA,EAA6BJ,QAA7B,CAJE;IAKL,GAAG,IAAAK,iCAAA,EAAuBL,QAAvB,CALE;IAML,GAAG,IAAAM,+BAAA,EAAsBN,QAAtB,CANE;IAOL,GAAG,IAAAO,uBAAA,EAAkBP,QAAlB,CAPE;IAQL,GAAG,IAAAQ,iCAAA,EAAuBR,QAAvB,CARE;IASL,GAAG,IAAAS,iCAAA,EAAuBT,QAAvB,CATE;IAUL,GAAG,IAAAU,mCAAA,EAAwBV,QAAxB,CAVE;IAWL,GAAG,IAAAW,qCAAA,EAAyBX,QAAzB;EAXE,CAAP;AAaD;;AAEM,MAAMY,oBAAoB,GAAGb,MAA7B"}
|