@testing-library/react-native 13.3.0 → 13.3.2

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.
@@ -1,11 +1,12 @@
1
1
  import * as React from 'react';
2
+ import type { RefObject } from './types';
2
3
  export type RenderHookResult<Result, Props> = {
3
- result: React.RefObject<Result>;
4
+ result: RefObject<Result>;
4
5
  rerender: (props: Props) => void;
5
6
  unmount: () => void;
6
7
  };
7
8
  export type RenderHookAsyncResult<Result, Props> = {
8
- result: React.RefObject<Result>;
9
+ result: RefObject<Result>;
9
10
  rerenderAsync: (props: Props) => Promise<void>;
10
11
  unmountAsync: () => Promise<void>;
11
12
  };
@@ -25,5 +26,5 @@ export type RenderHookOptions<Props> = {
25
26
  */
26
27
  concurrentRoot?: boolean;
27
28
  };
28
- export declare function renderHook<Result, Props>(hookToRender: (props: Props) => Result, options?: RenderHookOptions<Props>): RenderHookResult<Result, Props>;
29
- export declare function renderHookAsync<Result, Props>(hookToRender: (props: Props) => Result, options?: RenderHookOptions<Props>): Promise<RenderHookAsyncResult<Result, Props>>;
29
+ export declare function renderHook<Result, Props>(hookToRender: (props: Props) => Result, options?: RenderHookOptions<NoInfer<Props>>): RenderHookResult<Result, Props>;
30
+ export declare function renderHookAsync<Result, Props>(hookToRender: (props: Props) => Result, options?: RenderHookOptions<NoInfer<Props>>): Promise<RenderHookAsyncResult<Result, Props>>;
@@ -35,7 +35,6 @@ function renderHook(hookToRender, options) {
35
35
  hookProps: initialProps
36
36
  }), renderOptions);
37
37
  return {
38
- // Result should already be set after the first render effects are run.
39
38
  result: result,
40
39
  rerender: hookProps => rerenderComponent(/*#__PURE__*/React.createElement(HookContainer, {
41
40
  hookProps: hookProps
@@ -68,7 +67,6 @@ async function renderHookAsync(hookToRender, options) {
68
67
  hookProps: initialProps
69
68
  }), renderOptions);
70
69
  return {
71
- // Result should already be set after the first render effects are run.
72
70
  result: result,
73
71
  rerenderAsync: hookProps => rerenderComponentAsync(/*#__PURE__*/React.createElement(TestComponent, {
74
72
  hookProps: hookProps
@@ -1 +1 @@
1
- {"version":3,"file":"render-hook.js","names":["React","_interopRequireWildcard","require","_render","_interopRequireDefault","_renderAsync","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","renderHook","hookToRender","options","result","createRef","HookContainer","hookProps","renderResult","useEffect","current","initialProps","renderOptions","rerender","rerenderComponent","unmount","render","createElement","renderHookAsync","TestComponent","rerenderAsync","rerenderComponentAsync","unmountAsync","renderAsync"],"sources":["../src/render-hook.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport render from './render';\nimport renderAsync from './render-async';\n\nexport type RenderHookResult<Result, Props> = {\n result: React.RefObject<Result>;\n rerender: (props: Props) => void;\n unmount: () => void;\n};\n\nexport type RenderHookAsyncResult<Result, Props> = {\n result: React.RefObject<Result>;\n rerenderAsync: (props: Props) => Promise<void>;\n unmountAsync: () => Promise<void>;\n};\n\nexport type RenderHookOptions<Props> = {\n /**\n * The initial props to pass to the hook.\n */\n initialProps?: Props;\n\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 /**\n * Set to `false` to disable concurrent rendering.\n * Otherwise `renderHook` will default to concurrent rendering.\n */\n concurrentRoot?: boolean;\n};\n\nexport function renderHook<Result, Props>(\n hookToRender: (props: Props) => Result,\n options?: RenderHookOptions<Props>,\n): RenderHookResult<Result, Props> {\n const result: React.RefObject<Result | null> = React.createRef();\n\n function HookContainer({ hookProps }: { hookProps: Props }) {\n const renderResult = hookToRender(hookProps);\n React.useEffect(() => {\n result.current = renderResult;\n });\n\n return null;\n }\n\n const { initialProps, ...renderOptions } = options ?? {};\n const { rerender: rerenderComponent, unmount } = render(\n // @ts-expect-error since option can be undefined, initialProps can be undefined when it should'nt\n <HookContainer hookProps={initialProps} />,\n renderOptions,\n );\n\n return {\n // Result should already be set after the first render effects are run.\n result: result as React.RefObject<Result>,\n rerender: (hookProps: Props) => rerenderComponent(<HookContainer hookProps={hookProps} />),\n unmount,\n };\n}\n\nexport async function renderHookAsync<Result, Props>(\n hookToRender: (props: Props) => Result,\n options?: RenderHookOptions<Props>,\n): Promise<RenderHookAsyncResult<Result, Props>> {\n const result: React.RefObject<Result | null> = React.createRef();\n\n function TestComponent({ hookProps }: { hookProps: Props }) {\n const renderResult = hookToRender(hookProps);\n React.useEffect(() => {\n result.current = renderResult;\n });\n\n return null;\n }\n\n const { initialProps, ...renderOptions } = options ?? {};\n const { rerenderAsync: rerenderComponentAsync, unmountAsync } = await renderAsync(\n // @ts-expect-error since option can be undefined, initialProps can be undefined when it should'nt\n <TestComponent hookProps={initialProps} />,\n renderOptions,\n );\n\n return {\n // Result should already be set after the first render effects are run.\n result: result as React.RefObject<Result>,\n rerenderAsync: (hookProps: Props) =>\n rerenderComponentAsync(<TestComponent hookProps={hookProps} />),\n unmountAsync,\n };\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,YAAA,GAAAD,sBAAA,CAAAF,OAAA;AAAyC,SAAAE,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAT,uBAAA,YAAAA,CAAAK,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA,EAAAF,CAAA,i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AAE,CAAC,EAC1CC,aACF,CAAC;EAED,OAAO;IACL;IACAR,MAAM,EAAEA,MAAiC;IACzCS,QAAQ,EAAGN,SAAgB,IAAKO,iBAAiB,cAACtC,KAAA,CAAAyC,aAAA,CAACX,aAAa;MAACC,SAAS,EAAEA;IAAU,CAAE,CAAC,CAAC;IAC1FQ;EACF,CAAC;AACH;AAEO,eAAeG,eAAeA,CACnChB,YAAsC,EACtCC,OAAkC,EACa;EAC/C,MAAMC,MAAsC,gBAAG5B,KAAK,CAAC6B,SAAS,CAAC,CAAC;EAEhE,SAASc,aAAaA,CAAC;IAAEZ;EAAgC,CAAC,EAAE;IAC1D,MAAMC,YAAY,GAAGN,YAAY,CAACK,SAAS,CAAC;IAC5C/B,KAAK,CAACiC,SAAS,CAAC,MAAM;MACpBL,MAAM,CAACM,OAAO,GAAGF,YAAY;IAC/B,CAAC,CAAC;IAEF,OAAO,IAAI;EACb;EAEA,MAAM;IAAEG,YAAY;IAAE,GAAGC;EAAc,CAAC,GAAGT,OAAO,IAAI,CAAC,CAAC;EACxD,MAAM;IAAEiB,aAAa,EAAEC,sBAAsB;IAAEC;EAAa,CAAC,GAAG,MAAM,IAAAC,oBAAW;EAAA;EAC/E;EACA/C,KAAA,CAAAyC,aAAA,CAACE,aAAa;IAACZ,SAAS,EAAEI;EAAa,CAAE,CAAC,EAC1CC,aACF,CAAC;EAED,OAAO;IACL;IACAR,MAAM,EAAEA,MAAiC;IACzCgB,aAAa,EAAGb,SAAgB,IAC9Bc,sBAAsB,cAAC7C,KAAA,CAAAyC,aAAA,CAACE,aAAa;MAACZ,SAAS,EAAEA;IAAU,CAAE,CAAC,CAAC;IACjEe;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"render-hook.js","names":["React","_interopRequireWildcard","require","_render","_interopRequireDefault","_renderAsync","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","renderHook","hookToRender","options","result","createRef","HookContainer","hookProps","renderResult","useEffect","current","initialProps","renderOptions","rerender","rerenderComponent","unmount","render","createElement","renderHookAsync","TestComponent","rerenderAsync","rerenderComponentAsync","unmountAsync","renderAsync"],"sources":["../src/render-hook.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport render from './render';\nimport renderAsync from './render-async';\nimport type { RefObject } from './types';\n\nexport type RenderHookResult<Result, Props> = {\n result: RefObject<Result>;\n rerender: (props: Props) => void;\n unmount: () => void;\n};\n\nexport type RenderHookAsyncResult<Result, Props> = {\n result: RefObject<Result>;\n rerenderAsync: (props: Props) => Promise<void>;\n unmountAsync: () => Promise<void>;\n};\n\nexport type RenderHookOptions<Props> = {\n /**\n * The initial props to pass to the hook.\n */\n initialProps?: Props;\n\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 /**\n * Set to `false` to disable concurrent rendering.\n * Otherwise `renderHook` will default to concurrent rendering.\n */\n concurrentRoot?: boolean;\n};\n\nexport function renderHook<Result, Props>(\n hookToRender: (props: Props) => Result,\n options?: RenderHookOptions<NoInfer<Props>>,\n): RenderHookResult<Result, Props> {\n const result = React.createRef<Result>() as RefObject<Result>;\n\n function HookContainer({ hookProps }: { hookProps: Props }) {\n const renderResult = hookToRender(hookProps);\n React.useEffect(() => {\n result.current = renderResult;\n });\n\n return null;\n }\n\n const { initialProps, ...renderOptions } = options ?? {};\n const { rerender: rerenderComponent, unmount } = render(\n // @ts-expect-error since option can be undefined, initialProps can be undefined when it should'nt\n <HookContainer hookProps={initialProps} />,\n renderOptions,\n );\n\n return {\n result: result,\n rerender: (hookProps: Props) => rerenderComponent(<HookContainer hookProps={hookProps} />),\n unmount,\n };\n}\n\nexport async function renderHookAsync<Result, Props>(\n hookToRender: (props: Props) => Result,\n options?: RenderHookOptions<NoInfer<Props>>,\n): Promise<RenderHookAsyncResult<Result, Props>> {\n const result = React.createRef<Result>() as RefObject<Result>;\n\n function TestComponent({ hookProps }: { hookProps: Props }) {\n const renderResult = hookToRender(hookProps);\n React.useEffect(() => {\n result.current = renderResult;\n });\n\n return null;\n }\n\n const { initialProps, ...renderOptions } = options ?? {};\n const { rerenderAsync: rerenderComponentAsync, unmountAsync } = await renderAsync(\n // @ts-expect-error since option can be undefined, initialProps can be undefined when it should'nt\n <TestComponent hookProps={initialProps} />,\n renderOptions,\n );\n\n return {\n result: result,\n rerenderAsync: (hookProps: Props) =>\n rerenderComponentAsync(<TestComponent hookProps={hookProps} />),\n unmountAsync,\n };\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,YAAA,GAAAD,sBAAA,CAAAF,OAAA;AAAyC,SAAAE,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAT,uBAAA,YAAAA,CAAAK,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA,EAAAF,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAS,CAAA,MAAAF,CAAA,GAAAJ,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAE,CAAA,CAAAI,GAAA,CAAAX,CAAA,UAAAO,CAAA,CAAAK,GAAA,CAAAZ,CAAA,GAAAO,CAAA,CAAAM,GAAA,CAAAb,CAAA,EAAAS,CAAA,gBAAAN,CAAA,IAAAH,CA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EACI;EAC/C,MAAMC,MAAM,gBAAG5B,KAAK,CAAC6B,SAAS,CAAS,CAAsB;EAE7D,SAASc,aAAaA,CAAC;IAAEZ;EAAgC,CAAC,EAAE;IAC1D,MAAMC,YAAY,GAAGN,YAAY,CAACK,SAAS,CAAC;IAC5C/B,KAAK,CAACiC,SAAS,CAAC,MAAM;MACpBL,MAAM,CAACM,OAAO,GAAGF,YAAY;IAC/B,CAAC,CAAC;IAEF,OAAO,IAAI;EACb;EAEA,MAAM;IAAEG,YAAY;IAAE,GAAGC;EAAc,CAAC,GAAGT,OAAO,IAAI,CAAC,CAAC;EACxD,MAAM;IAAEiB,aAAa,EAAEC,sBAAsB;IAAEC;EAAa,CAAC,GAAG,MAAM,IAAAC,oBAAW;EAAA;EAC/E;EACA/C,KAAA,CAAAyC,aAAA,CAACE,aAAa;IAACZ,SAAS,EAAEI;EAAa,CAAE,CAAC,EAC1CC,aACF,CAAC;EAED,OAAO;IACLR,MAAM,EAAEA,MAAM;IACdgB,aAAa,EAAGb,SAAgB,IAC9Bc,sBAAsB,cAAC7C,KAAA,CAAAyC,aAAA,CAACE,aAAa;MAACZ,SAAS,EAAEA;IAAU,CAAE,CAAC,CAAC;IACjEe;EACF,CAAC;AACH","ignoreList":[]}
package/build/types.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /** `RefObject` type from React 19. */
2
+ export type RefObject<T> = {
3
+ current: T;
4
+ };
1
5
  /**
2
6
  * Location of an element.
3
7
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Location of an element.\n */\nexport interface Point {\n y: number;\n x: number;\n}\n\n/**\n * Size of an element.\n */\nexport interface Size {\n height: number;\n width: number;\n}\n\n// TS autocomplete trick\n// Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939\nexport type StringWithAutocomplete<T> = T | (string & {});\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/** `RefObject` type from React 19. */\nexport type RefObject<T> = {\n current: T;\n};\n\n/**\n * Location of an element.\n */\nexport interface Point {\n y: number;\n x: number;\n}\n\n/**\n * Size of an element.\n */\nexport interface Size {\n height: number;\n width: number;\n}\n\n// TS autocomplete trick\n// Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939\nexport type StringWithAutocomplete<T> = T | (string & {});\n"],"mappings":"","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/react-native",
3
- "version": "13.3.0",
3
+ "version": "13.3.2",
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",