From 60cdeac33390ab972aec3562c8e43939df0ce289 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Thu, 5 Oct 2017 10:57:58 +0200 Subject: [PATCH] add documentation for the usage with jest Closes #143 Heavily inspired by the solution of @AlanFoster and with the help of @levito --- docs/Guide.Jest.md | 59 ++++++++++++++++++++++++++++++++++++++++++++++ docs/README.md | 1 + 2 files changed, 60 insertions(+) create mode 100644 docs/Guide.Jest.md diff --git a/docs/Guide.Jest.md b/docs/Guide.Jest.md new file mode 100644 index 0000000000..ee68c273f8 --- /dev/null +++ b/docs/Guide.Jest.md @@ -0,0 +1,59 @@ +# Jest as Test Runner + +## Usage + +### 0. Use the [Getting Started](Introduction.GettingStarted.md) Guide to set up detox + +Except that you need to skip the install mocha step. + +### 1. Install Jest + +```sh +npm install --save-dev jest +``` + +### 2. Remove mocha specific files + +You should remove `e2e/mocha.opts`, you no longer need it. + +### 3. Write a detox setup file + +```js +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(); +}); + +// optional, you may remove this part +beforeEach(async () => { + await device.reloadReactNative(); +}); +``` + +### 4. Run jest + +```json +{ + ... + "scripts": { + "test:e2e": "jest e2e --setupTestFrameworkScriptFile=./jest/setup-e2e-tests.js" + } +} +``` + + +> Side Note: Don't worry about mocks being used, detox works on the compiled version of your app. + +## How to run unit test and E2E tests in the same project + +- If you have a setup file for the unit tests pass it into jest by passing `--setupTestFrameworkScriptFile=./path/to/setup-unit-tests.js` to your jest unit test call. You need to remove this option from your `jest` configuration in the package.json. +- Call your E2E tests like mentioned above \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index beec5ace36..b87f5cb243 100644 --- a/docs/README.md +++ b/docs/README.md @@ -36,6 +36,7 @@ - [Debugging Apps in Xcode During a Test](Guide.DebuggingInXcode.md) - [Advanced Mocking With Detox](Guide.Mocking.md) - [Migration Between Detox Versions](Guide.Migration.md) +- [Use Jest as Test Runner](Guide.Jest.md) ## Under The Hood