Skip to content

Commit

Permalink
add documentation for the usage with jest
Browse files Browse the repository at this point in the history
Closes #143
Heavily inspired by the solution of @AlanFoster and with the help of @levito
  • Loading branch information
Daniel Schmidt committed Oct 5, 2017
1 parent dd32eb3 commit af20ca4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
57 changes: 57 additions & 0 deletions docs/Guide.Jest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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

Add this part to your `package.json`:
```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
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit af20ca4

Please sign in to comment.