id | title |
---|---|
Guide.Jest |
Jest |
0. Use the Getting Started Guide to set up detox
Except that you need to skip the install mocha step.
npm install --save-dev jest
You should remove e2e/mocha.opts
, you no longer need it.
const detox = require('detox');
const config = require('../package.json').detox;
// Set the default test timeout of 120s
jest.setTimeout(120000);
beforeAll(async () => {
await detox.init(config);
});
afterAll(async () => {
await detox.cleanup();
});
Add a Jest config file e2e/config.json
:
{
"setupTestFrameworkScriptFile" : "./init.js"
}
In package.json
:
"scripts": {
"test:e2e": "detox test -c ios.sim.debug",
"test:e2e:build": "detox build"
},
"detox": {
"test-runner": "jest",
"runner-config": "e2e/config.json"
...
}
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 globalexpect
object.
- If you have a setup file for the unit tests pass
./jest/setup
implementation into your unit setup. - Call your E2E tests using
detox-cli
:detox test