@testing-library/react-native 14.0.0-alpha.2 → 14.0.0-alpha.3
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/render-async.d.ts +1 -1
- package/build/render.d.ts +3 -3
- package/build/render.js +11 -1
- package/build/render.js.map +1 -1
- package/package.json +3 -3
package/build/render-async.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export default function renderAsync<T>(component: React.ReactElement<T>, options
|
|
|
21
21
|
updateAsync: (component: React.ReactElement) => Promise<void>;
|
|
22
22
|
unmount: () => never;
|
|
23
23
|
unmountAsync: () => Promise<void>;
|
|
24
|
-
toJSON: () => import("universal-test-renderer").
|
|
24
|
+
toJSON: () => import("universal-test-renderer").JsonElement | null;
|
|
25
25
|
debug: DebugFunction;
|
|
26
26
|
container: HostElement;
|
|
27
27
|
root: HostElement | null;
|
package/build/render.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type { HostElement } from 'universal-test-renderer';
|
|
2
|
+
import type { HostElement, JsonElement } from 'universal-test-renderer';
|
|
3
3
|
import type { DebugOptions } from './helpers/debug';
|
|
4
4
|
export interface RenderOptions {
|
|
5
5
|
/**
|
|
@@ -21,7 +21,7 @@ export default function render<T>(component: React.ReactElement<T>, options?: Re
|
|
|
21
21
|
updateAsync: (component: React.ReactElement) => Promise<void>;
|
|
22
22
|
unmount: () => void;
|
|
23
23
|
unmountAsync: () => Promise<void>;
|
|
24
|
-
toJSON: () =>
|
|
24
|
+
toJSON: () => JsonElement | null;
|
|
25
25
|
debug: DebugFunction;
|
|
26
26
|
container: HostElement;
|
|
27
27
|
root: HostElement | null;
|
|
@@ -87,7 +87,7 @@ export declare function renderInternal<T>(component: React.ReactElement<T>, opti
|
|
|
87
87
|
updateAsync: (component: React.ReactElement) => Promise<void>;
|
|
88
88
|
unmount: () => void;
|
|
89
89
|
unmountAsync: () => Promise<void>;
|
|
90
|
-
toJSON: () =>
|
|
90
|
+
toJSON: () => JsonElement | null;
|
|
91
91
|
debug: DebugFunction;
|
|
92
92
|
container: HostElement;
|
|
93
93
|
root: HostElement | null;
|
package/build/render.js
CHANGED
|
@@ -56,6 +56,16 @@ function buildRenderResult(renderer, wrap) {
|
|
|
56
56
|
renderer.unmount();
|
|
57
57
|
});
|
|
58
58
|
};
|
|
59
|
+
const toJSON = () => {
|
|
60
|
+
const json = renderer.container.toJSON();
|
|
61
|
+
if (json?.children?.length === 0) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (json?.children?.length === 1 && typeof json.children[0] !== 'string') {
|
|
65
|
+
return json.children[0];
|
|
66
|
+
}
|
|
67
|
+
return json;
|
|
68
|
+
};
|
|
59
69
|
(0, _cleanup.addToCleanupQueue)(unmountAsync);
|
|
60
70
|
const result = {
|
|
61
71
|
...(0, _within.getQueriesForElement)(renderer.container),
|
|
@@ -67,7 +77,7 @@ function buildRenderResult(renderer, wrap) {
|
|
|
67
77
|
// alias for `rerenderAsync`
|
|
68
78
|
unmount,
|
|
69
79
|
unmountAsync,
|
|
70
|
-
toJSON
|
|
80
|
+
toJSON,
|
|
71
81
|
debug: makeDebug(renderer),
|
|
72
82
|
get container() {
|
|
73
83
|
return renderer.container;
|
package/build/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","names":["React","_interopRequireWildcard","require","_act","_interopRequireDefault","_cleanup","_config","_debug","_renderAct","_screen","_within","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","render","component","options","renderInternal","wrapper","Wrapper","rendererOptions","wrap","element","createElement","renderer","renderWithAct","buildRenderResult","rerender","act","rerenderAsync","unmount","unmountAsync","
|
|
1
|
+
{"version":3,"file":"render.js","names":["React","_interopRequireWildcard","require","_act","_interopRequireDefault","_cleanup","_config","_debug","_renderAct","_screen","_within","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","render","component","options","renderInternal","wrapper","Wrapper","rendererOptions","wrap","element","createElement","renderer","renderWithAct","buildRenderResult","rerender","act","rerenderAsync","unmount","unmountAsync","toJSON","json","container","children","length","addToCleanupQueue","result","getQueriesForElement","update","updateAsync","debug","makeDebug","root","firstChild","Error","setRenderResult","debugImpl","defaultDebugOptions","getConfig","debugOptions"],"sources":["../src/render.tsx"],"sourcesContent":["import * as React from 'react';\nimport type { HostElement, JsonElement, Root, RootOptions } from 'universal-test-renderer';\n\nimport act from './act';\nimport { addToCleanupQueue } from './cleanup';\nimport { getConfig } from './config';\nimport type { DebugOptions } from './helpers/debug';\nimport { debug } from './helpers/debug';\nimport { renderWithAct } from './render-act';\nimport { setRenderResult } from './screen';\nimport { getQueriesForElement } from './within';\n\nexport interface RenderOptions {\n /**\n * Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating\n * reusable custom render functions for common data providers.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wrapper?: React.ComponentType<any>;\n\n createNodeMock?: (element: React.ReactElement) => unknown;\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>(component: React.ReactElement<T>, options: RenderOptions = {}) {\n return renderInternal(component, options);\n}\n\nexport function renderInternal<T>(component: React.ReactElement<T>, options?: RenderOptions) {\n const { wrapper: Wrapper } = options || {};\n\n // TODO allow passing some options\n const rendererOptions: RootOptions = {};\n\n const wrap = (element: React.ReactElement) => (Wrapper ? <Wrapper>{element}</Wrapper> : element);\n const renderer = renderWithAct(wrap(component), rendererOptions);\n return buildRenderResult(renderer, wrap);\n}\n\nfunction buildRenderResult(\n renderer: Root,\n wrap: (element: React.ReactElement) => React.JSX.Element,\n) {\n const rerender = (component: React.ReactElement) => {\n void act(() => {\n renderer.render(wrap(component));\n });\n };\n const rerenderAsync = async (component: React.ReactElement) => {\n // eslint-disable-next-line require-await\n await act(async () => {\n renderer.render(wrap(component));\n });\n };\n\n const unmount = () => {\n void act(() => {\n renderer.unmount();\n });\n };\n const unmountAsync = async () => {\n // eslint-disable-next-line require-await\n await act(async () => {\n renderer.unmount();\n });\n };\n\n const toJSON = (): JsonElement | null => {\n const json = renderer.container.toJSON();\n if (json?.children?.length === 0) {\n return null;\n }\n\n if (json?.children?.length === 1 && typeof json.children[0] !== 'string') {\n return json.children[0];\n }\n\n return json;\n };\n\n addToCleanupQueue(unmountAsync);\n\n const result = {\n ...getQueriesForElement(renderer.container),\n rerender,\n rerenderAsync,\n update: rerender, // alias for 'rerender'\n updateAsync: rerenderAsync, // alias for `rerenderAsync`\n unmount,\n unmountAsync,\n toJSON,\n debug: makeDebug(renderer),\n get container(): HostElement {\n return renderer.container;\n },\n get root(): HostElement | null {\n const firstChild = renderer.container.children[0];\n if (typeof firstChild === 'string') {\n throw new Error(\n 'Invariant Violation: Root element must be a host element. Detected attempt to render a string within the root element.',\n );\n }\n\n return firstChild;\n },\n };\n\n setRenderResult(result);\n\n return result;\n}\n\nexport type DebugFunction = (options?: DebugOptions) => void;\n\nfunction makeDebug(renderer: Root): DebugFunction {\n function debugImpl(options?: DebugOptions) {\n const { defaultDebugOptions } = getConfig();\n const debugOptions = { ...defaultDebugOptions, ...options };\n const json = renderer.container.toJSON();\n if (json) {\n return debug(json, debugOptions);\n }\n }\n return debugImpl;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,IAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AAAgD,SAAAE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AGT,QAAQ,CAACU,SAAS,CAACF,MAAM,CAAC,CAAC;IACxC,IAAIC,IAAI,EAAE;MACR,OAAO,IAAAS,YAAK,EAACT,IAAI,EAAEkB,YAAY,CAAC;IAClC;EACF;EACA,OAAOH,SAAS;AAClB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testing-library/react-native",
|
|
3
|
-
"version": "14.0.0-alpha.
|
|
3
|
+
"version": "14.0.0-alpha.3",
|
|
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",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"jest": ">=29.0.0",
|
|
60
60
|
"react": ">=19.0.0",
|
|
61
61
|
"react-native": ">=0.71",
|
|
62
|
-
"universal-test-renderer": "~0.10.
|
|
62
|
+
"universal-test-renderer": "~0.10.1"
|
|
63
63
|
},
|
|
64
64
|
"peerDependenciesMeta": {
|
|
65
65
|
"jest": {
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"release-it": "^19.0.6",
|
|
96
96
|
"typescript": "^5.9.3",
|
|
97
97
|
"typescript-eslint": "^8.47.0",
|
|
98
|
-
"universal-test-renderer": "0.10.
|
|
98
|
+
"universal-test-renderer": "0.10.1"
|
|
99
99
|
},
|
|
100
100
|
"publishConfig": {
|
|
101
101
|
"registry": "https://registry.npmjs.org"
|