setup-detox-jest.mo
Last updated
Last updated
Running Detox (on iOS) requires the following:
Mac with macOS (>= macOS El Capitan 10.11)
Xcode 8.3+ with Xcode command line tools
A working app
A Javascript test Runner installed (Jest in our example. Detox also works with Mocha)
Node 7.6.0 or above for native async-await support
Go to detox getting started for more details.
Collection of utils to communicate with the simulator
TIP:
detox -h
gives the list of available commands
The basic configuration for Detox should be in your package.json
file under the detox
property where you can replace YOURAPP with your app name:
For iOS apps in a workspace (eg: CocoaPods) use -workspace ios/example.xcworkspace
instead of -project
.
Also make sure the simulator model specified under the key "name"
(iPhone 7
above) is actually available on your machine (it was installed by Xcode). Check this by typing xcrun simctl list
in terminal to display all available simulators.
TIP: To test a release version, replace 'Debug' with 'Release' in the binaryPath and build properties.
Create a folder e2e at the root of your project
Add a jest config file e2e/config.json
:
In your package.json
detox config add a reference to your config file:
Create an init file e2e/init.js
:
Add a Regexp to your test files in the config file e2e/config.json
:
NOTE: Here I'm matching all files that end in
.e2e.js
Add a testID to your component.
Custom component: Detox will only find components thanks to their testID if they directly come from react-native. Make sure your custom components transfer the testID prop to a built-in react-native component such as Text, TouchableOpacity, ...
Create your 1st test file e2e/test.e2e.js
to check that your title exists
Add to your package.json
:
Build & Test your app:
Install plugin:
Add plugin to your .eslintrc
:
Add line at the top of every detox file:
Detox will only find components thanks to their testID if they directly come from react-native. Make sure your custom components transfer the testID prop to a built-in react-native component such as Text, TouchableOpacity, ...
waitFor & withTimeout (In our example, you wait for two seconds before checking for the title)
Use a waitFor with a temporary (de)synchronisation of your app
NOTE: Sometimes the synchronization engine is stuck on a never ending asynchronous activity. Use --debug-synchronization to debug synchronization issues
NOTE: You will find the bitrise.yml to automate your E2E tests on a CI
Check the bitrise.yml of the repository to automate on Bitrise.
Don't hesitate to refer to : An open source repo I created to test Detox :)