-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DeviceInfo breaks Detox Tests #335
Comments
Hi @blumendorf, shouldn't you mock Here's how I do that for jest:
|
Fair point. Will give that a try. Thanks! I would still be interested to understand why it works when I run the app myself, but not when detox runs the app. |
Because it contains native code, something detox/jest can't make up |
Just documented it in the README file: https://github.com/rebeccahughes/react-native-device-info#troubleshooting Feel free to reopen if you still facing a problem with tests :) |
Not sure that I get it. The same bundle runs in the Android simulator and works fine when I "click the buttons". Jest runs the same code and connects to "click the buttons" for me. The exact same code and test (not the linked repository) works perfectly fine in iOS simulator. No mocking required. Thanks for your help and patience. |
From what I understand from https://facebook.github.io/jest/docs/en/tutorial-react-native.html#mock-native-modules-using-jestmock , jest comes with some default mocks, like buttons, which is how it works for you. For other libraries, like this one, you need to manually mock the objects. |
Hello @machour, thank you very much for your help here. I really appreciate it! Let me try to explain again what I am doing: I added the iOS code to https://github.com/ewyso/react-native-detox-e-android and this seems to be the minimum implementation to demonstrate the issue. Once the import (line 17 in App.js) is in, ios.sim.debug still runs fine while android.emu.debug hangs with no apparent error. Since it is the module import that makes the difference, I am not sure where to look next ... |
My bad, I didn't really get that you were doing e2e tests 😄 I just cloned your project and first tried on iOS. Shouldn't it be passing? (the line in App.js is still commented) |
Should have been more clear about the e2e part. Sorry. I am running it with I fixed the yarn command in the repo. |
I was unable to run detox with iOS, but it worked for Android :) I've successfully reproduced your problem and pinpointed it to this particular line. Could you try commenting it in your |
Someone seems to have faced the same problem here: wix/Detox#395 (comment) |
Removing this line brings me past the splash screen in both the react-native-detox-e-android and our project. Thanks for taking the time to look into it. I am very curious about the solution now. |
No worries, I always wanted to see how e2e tests works :) |
I temporary fix it by stubbing @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);
} |
@ghsdh3409 's answer fixed it for me. I had to put: 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 (For those lazy like me, so that you don't have to look for your correct imports yourself :) ) |
Many thanks to both of you! |
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
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
orvar DeviceInfo = require('react-native-device-info'
are added. There are no visible error messages inreact-native log-android
oradb 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.
The text was updated successfully, but these errors were encountered: