Files
callstack__react-native-tes…/src/render-act.ts
T
Jarda Snajdr 6bf8d246e6 detectHostComponentNames: render test tree inside act to avoid timer leaks (#1371)
* detectHostComponentNames: render test tree inside act to avoid timer leaks

* chore: tweaks

* refactor: extract common renderWithAct function

* chore: tweaks

---------

Co-authored-by: Maciej Jastrzebski <mdjastrzebski@gmail.com>
2023-03-23 10:48:17 +01:00

20 lines
479 B
TypeScript

import TestRenderer from 'react-test-renderer';
import type {
ReactTestRenderer,
TestRendererOptions,
} from 'react-test-renderer';
export function renderWithAct(
component: React.ReactElement,
options?: TestRendererOptions
): ReactTestRenderer {
let renderer: ReactTestRenderer;
TestRenderer.act(() => {
renderer = TestRenderer.create(component, options);
});
// @ts-ignore act is synchronous, so renderer is already initialised here
return renderer;
}