mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Create method to test reload of ReactHost (#37981)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37981 This diff introduces a the test ReactHost.testReload() to verify that reloading of react host works as expected changelog: [internal] internal Reviewed By: cortinico Differential Revision: D46813814 fbshipit-source-id: 59e23e2f296c81b7ca3decb81e1f53b5871bbff4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
de786cddbc
commit
015e7cbd93
+18
@@ -22,6 +22,7 @@ import android.app.Activity;
|
||||
import com.facebook.react.MemoryPressureRouter;
|
||||
import com.facebook.react.bridge.JSBundleLoader;
|
||||
import com.facebook.react.bridge.MemoryPressureListener;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.UIManager;
|
||||
import com.facebook.react.bridgeless.internal.bolts.Task;
|
||||
import com.facebook.react.bridgeless.internal.bolts.TaskCompletionSource;
|
||||
@@ -150,6 +151,23 @@ public class ReactHostTest {
|
||||
assertThat(mReactHost.getCurrentReactContext()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReload() throws Exception {
|
||||
statAndTestReactHost();
|
||||
|
||||
ReactContext oldReactContext = mReactHost.getCurrentReactContext();
|
||||
BridgelessReactContext newReactContext = mock(BridgelessReactContext.class);
|
||||
assertThat(newReactContext).isNotEqualTo(oldReactContext);
|
||||
whenNew(BridgelessReactContext.class).withAnyArguments().thenReturn(newReactContext);
|
||||
|
||||
waitForTaskUIThread(mReactHost.reload("Reload from testing infra"));
|
||||
|
||||
assertThat(mReactHost.isInstanceInitialized()).isTrue();
|
||||
assertThat(mReactHost.getCurrentReactContext()).isNotNull();
|
||||
assertThat(mReactHost.getCurrentReactContext()).isEqualTo(newReactContext);
|
||||
assertThat(mReactHost.getCurrentReactContext()).isNotEqualTo(oldReactContext);
|
||||
}
|
||||
|
||||
private static <T> void waitForTaskUIThread(Task<T> task) throws InterruptedException {
|
||||
boolean isTaskCompleted = false;
|
||||
while (!isTaskCompleted) {
|
||||
|
||||
Reference in New Issue
Block a user