0. Use the Getting Started Guide to set up detox
Except that you need to skip the install mocha step.
npm install --save-dev jestYou should remove e2e/mocha.opts, you no longer need it.
const detox = require('detox');
const config = require('../package.json').detox;
// Set the default timeout
jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;
beforeAll(async () => {
await detox.init(config);
});
afterAll(async () => {
await detox.cleanup();
});
beforeEach(async () => {
await device.reloadReactNative();
});Add this part to your package.json:
"jest": {
"setupTestFrameworkScriptFile": "./e2e/init.js"
},
"scripts": {
"test:e2e": "detox test -c ios.sim.debug",
"test:e2e:build": "detox build"
},
"detox": {
"runner": "jest",
...
}There are some things you should notice:
- Don't worry about mocks being used, detox works on the compiled version of your app.
- Detox exposes it's primitives (
expect,device, ...) globally, it will override Jest's globalexpectobject.
- If you have a setup file for the unit tests pass
./jest/setupimplementation into your unit setup. - Call your E2E tests like mentioned above