Detox: best way to send parameters to app

Viewed 636

I implemented Detox for e2e tests in my react-native application, I have 2 tests:

  1. Launch -> Not logged -> display login form -> Main screen
  2. Launch -> Logged -> Main screen

auth informations are stored with AsyncStorage, I implemented a mockup store.e2e.js using Repackager. Fine, but I need to start app with two different sets of data storage: one empty for test1 and another with username/password for test2.

So I add a hack with launchApp + url parameter or device.sendUrl, catched by Store mock at init using Linking.addEventListener('url', callback). Ok problem solved. But it forced me to activate deeplinking on Android and iOS, which I don't want in my app... Made a special case in the code only for testing, it is bad.

I understand it is a well known problem, and repackager was made for that: https://github.com/wix/detox/issues/91

But how to inject some parameters in app at launch for specific tests, is it possible ? What is your best practice for such problem ?

1 Answers

On iOS, you can send launch argument to your process, which you can query during runtime. You can also create a mock file for your JS, where, instead of replacing your logic, you just set some variable to hold the value you want to pass, and then load your normal logic.

Related