question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DeviceInfo breaks Detox Tests

See original GitHub issue

Summary

We are testing our app with detox and mocha (also tried jest) and noticed that our tests fail on Android. Debugging the failure suggests that importing react-native-device-info (var DeviceInfo = require(‘react-native-device-info’) in any module) gets the test stuck in the splash screen (i.e. the initialisation phase).

Here is an example project: https://github.com/ewyso/react-native-detox-e-android/ Just uncomment https://github.com/ewyso/react-native-detox-e-android/blob/master/App.js#L17

Version 0.15.3 (other seem to have the same issue)
Affected OS Android
OS Version Detox Testing on Nexus_5X_API_27

Current behavior

The app works fine running in the Android simulator. The app gets stuck in the splash screen when run from detox. As soon as import or var DeviceInfo = require('react-native-device-info' are added. There are no visible error messages in react-native log-android or adb logcat. The debugger is not connected when running tests.

Steps to reproduce: git clone https://github.com/ewyso/react-native-detox-e-android.git cd react-native-detox-e-android yarn && detox build --configuration android.emu.debug && detox test --configuration android.emu.debug -l verbose

Compare with line 17 in /App.js added / removed.

Expected behavior

Line 17 should not change the behavior of the test at all.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
ghsdh3409commented, May 9, 2018

I temporary fix it by stubbing WebSettings.getDefaultUserAgent() using mockito-android in my Detox test code.

@Test
public void runDetoxTests() throws InterruptedException {
  Context reactContext = InstrumentationRegistry.getTargetContext().getApplicationContext();
  WebSettings webSettings = spy(WebSettings.class);
  doReturn("getDefaultUserAgentMock").when(webSettings).getDefaultUserAgent(reactContext);

  Detox.runTests(mActivityRule);
}
6reactions
kormangcommented, May 16, 2018

@ghsdh3409 's answer fixed it for me.

I had to put: androidTestImplementation 'org.mockito:mockito-android:2.7.22' to app/build.gradle or for previous versions of gradle: androidTestCompile 'org.mockito:mockito-android:2.7.22'

These are imports:

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.webkit.WebSettings;
import static org.mockito.Mockito.*;

And at the end, I have put @ghsdh3409 's code in DetoxTest.java from androidTest directory.

(For those lazy like me, so that you don’t have to look for your correct imports yourself 😃 )

Read more comments on GitHub >

github_iconTop Results From Across the Web

DeviceInfo breaks Detox Tests · Issue #335 - GitHub
Summary We are testing our app with detox and mocha (also tried jest) and noticed that our tests fail on Android.
Read more >
Dealing With Problems With Running Tests | Detox
This page is about issues related to executing your Detox tests, typically triggered when running detox test (and not detox build, for example)....
Read more >
Detox tests are breaking - react native - Stack Overflow
The issue here is, as soon as my first test executes, the app is getting logged out and all the consecutive tests are...
Read more >
referenceerror: fetch is not defined react native detox - You.com
My team initially made some E2E tests using Detox when we were using React Native 0.59 on our app. Since then, we upgraded...
Read more >
Flush your system of drugs - Chiara Gabbani
We have broken it all down 2 de ago. These drug detox kits are made differently depending on drug use. Flushing out your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found