Create test that verifies ReactHost.destroy() works as expected (#37983)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37983

Create test ReactHostTest.testDestroy() that verifies ReactHost.destroy() works as expected

changelog: [internal] internal

Reviewed By: cortinico

Differential Revision: D46813611

fbshipit-source-id: 65432dae1b69412af3dec23265f57f73d49cca68
This commit is contained in:
David Vacca
2023-06-26 16:58:14 -07:00
committed by Facebook GitHub Bot
parent 93ec2206e3
commit de786cddbc
@@ -124,6 +124,10 @@ public class ReactHostTest {
@Test
public void testStart() throws Exception {
statAndTestReactHost();
}
private void statAndTestReactHost() throws Exception {
TaskCompletionSource<Boolean> taskCompletionSource = new TaskCompletionSource<>();
taskCompletionSource.setResult(true);
whenNew(TaskCompletionSource.class).withAnyArguments().thenReturn(taskCompletionSource);
@@ -137,6 +141,15 @@ public class ReactHostTest {
verify(mMemoryPressureRouter).addMemoryPressureListener((MemoryPressureListener) any());
}
@Test
public void testDestroy() throws Exception {
statAndTestReactHost();
waitForTaskUIThread(mReactHost.destroy("Destroying from testing infra", null));
assertThat(mReactHost.isInstanceInitialized()).isFalse();
assertThat(mReactHost.getCurrentReactContext()).isNull();
}
private static <T> void waitForTaskUIThread(Task<T> task) throws InterruptedException {
boolean isTaskCompleted = false;
while (!isTaskCompleted) {