Detox : Please add both arguments to super() call in your environment constructor

Viewed 449

I followed the Readme guide to setup detox in a react native project.

detox build works fine. But when I run detox test

I get this error

 FAIL  e2e/firstTest.e2e.jsrun...
  ● Test suite failed to run

    Please add both arguments to super() call in your environment constructor, e.g.:
    
     class CustomDetoxEnvironment extends DetoxCircusEnvironment {
    -  constructor(config) {
    -    super(config);
    +  constructor(config, context) {
    +    super(config, context);
    
    Cannot proceed further. Please fix your custom Detox environment class.
      
      at new CustomDetoxEnvironment (environment.js:9:5)
          at Generator.next (<anonymous>)

detox[227765] ERROR: [cli.js] Error: Command failed: jest --config e2e/config.json --testNamePattern '^((?!:ios:).)*$' --maxWorkers 1 e2e

2 Answers

Both Jest and jest-circus must be of same version.

Looks like you installed v18 of Detox.

There are some extra steps you need to make in order to make it work that are not yet included in the documentation but they can be found here: Detox guide for migration to v18

Quick solution:

  1. If you replace constructor and super with the new syntax

    class CustomDetoxEnvironment extends DetoxCircusEnvironment {

    • constructor(config) {
    • super(config);
    • constructor(config, context) {
    • super(config, context);
  2. You can no longer open the app for the tests to run with detox.init(). You need to run device.launchApp() for that (mandatory)

Related