DeviceInfo breaks Detox Tests
See original GitHub issueSummary
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:
- Created 6 years ago
- Reactions:2
- Comments:16 (1 by maintainers)
Top GitHub Comments
I temporary fix it by stubbing
WebSettings.getDefaultUserAgent()
usingmockito-android
in my Detox test code.@ghsdh3409 's answer fixed it for me.
I had to put:
androidTestImplementation 'org.mockito:mockito-android:2.7.22'
toapp/build.gradle
or for previous versions of gradle:androidTestCompile 'org.mockito:mockito-android:2.7.22'
These are imports:
And at the end, I have put @ghsdh3409 's code in
DetoxTest.java
fromandroidTest
directory.(For those lazy like me, so that you don’t have to look for your correct imports yourself 😃 )