Skip to content

Commit 78dfe07

Browse files
committed
[NetworkingModuleTest] Mock classes for testSuccessfulPostRequest
Fixes UnsatisfiedLinkError while running unit test
1 parent 9560789 commit 78dfe07

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

ReactAndroid/src/test/java/com/facebook/react/modules/network/NetworkingModuleTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ public WritableMap answer(InvocationOnMock invocation) throws Throwable {
200200

201201
@Test
202202
public void testSuccessfulPostRequest() throws Exception {
203+
RCTDeviceEventEmitter emitter = mock(RCTDeviceEventEmitter.class);
204+
ReactApplicationContext context = mock(ReactApplicationContext.class);
205+
when(context.getJSModule(any(Class.class))).thenReturn(emitter);
206+
203207
OkHttpClient httpClient = mock(OkHttpClient.class);
204208
when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
205209
@Override
@@ -211,12 +215,13 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
211215
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
212216
when(clientBuilder.build()).thenReturn(httpClient);
213217
when(httpClient.newBuilder()).thenReturn(clientBuilder);
214-
NetworkingModule networkingModule =
215-
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
218+
NetworkingModule networkingModule = new NetworkingModule(context, "", httpClient);
216219

217220
JavaOnlyMap body = new JavaOnlyMap();
218221
body.putString("string", "This is request body");
219222

223+
mockEvents();
224+
220225
networkingModule.sendRequest(
221226
"POST",
222227
"http://somedomain/bar",

0 commit comments

Comments
 (0)