Skip to content

Commit ab7d2fa

Browse files
jsnajdrmdjastrzebski
authored andcommitted
detectHostComponentNames: render test tree inside act to avoid timer leaks
1 parent f79d41d commit ab7d2fa

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/helpers/host-component-names.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { Text, TextInput, View } from 'react-native';
33
import TestRenderer from 'react-test-renderer';
4+
import type { ReactTestRenderer } from 'react-test-renderer';
45
import { configureInternal, getConfig, HostComponentNames } from '../config';
56
import { getQueriesForElement } from '../within';
67

@@ -29,12 +30,19 @@ export function configureHostComponentNamesIfNeeded() {
2930

3031
function detectHostComponentNames(): HostComponentNames {
3132
try {
32-
const renderer = TestRenderer.create(
33-
<View>
34-
<Text testID="text">Hello</Text>
35-
<TextInput testID="textInput" />
36-
</View>
37-
);
33+
const renderer = (() => {
34+
let result: ReactTestRenderer;
35+
TestRenderer.act(() => {
36+
result = TestRenderer.create(
37+
<View>
38+
<Text testID="text">Hello</Text>
39+
<TextInput testID="textInput" />
40+
</View>
41+
);
42+
});
43+
// @ts-ignore act is sync, so renderer is always initialised here
44+
return result;
45+
})();
3846

3947
const { getByTestId } = getQueriesForElement(renderer.root);
4048
const textHostName = getByTestId('text').type;

0 commit comments

Comments
 (0)