Mocha Setup Guide
Mocha Setup Guide
This guide describes how to install Mocha as a test runner to be used by Detox for running the E2E tests.
Note that while Mocha is lightweight and easy to set up, we nevertheless encourage usage of Jest instead, for 2 main reasons:
- Mocha does not support parallel-test execution (i.e. splitting the test suites between concurrently running test devices/emulators).
- Advanced integration features such as taking device screenshots on failures will not be as timely accurate as with working with Jest.
Installation
Disclaimer: Here we focus on installing Detox on new projects. If you’re migrating a project with an existing Detox installation, please apply some common sense while using this guide.
1. Install Mocha
Before starting with Mocha setup, be sure to complete the preliminary sections of the Getting Started guide.
- npm
- Yarn
- pnpm
npm install mocha --save-dev --no-package-lock
yarn add mocha --dev --no-lockfile
pnpm add mocha --save-dev --frozen-lockfile
2. Set up Test-code Scaffolds
detox init -r mocha
Note: errors occurring in the process may appear in red.
If things go well, you should to have this set up: