Detox: ReferenceError: device is not defined - in init (Detox: 5.9.2, Jest 21.1.2, RN 0.42.0)

Created on 25 Oct 2017  路  1Comment  路  Source: wix/Detox

Description

After I follow the instructions for setting up jest, I get an error when I run the tests as the beforEach call should use device to reload react native, but there is no reference.

//init.js
require('babel-polyfill');
const detox = require('detox');
const config = require('../package.json').detox;

// Set the default timeout
jasmine.DEFAULT_TIMEOUT_INTERVAL = 12000;

beforeAll(async () => {
  await detox.init(config);
});

afterAll(async () => {
  await detox.cleanup();
});

beforeEach(async () => {
  await device.reloadReactNative();
});

As I run specs, it has a bunch of errors:

     ReferenceError: device is not defined

      at Object.<anonymous>.beforeEach (e2e/init.js:17:16)
          at Promise (<anonymous>)
          at <anonymous>

I'm not sure how the device is being loaded, but I would have assumed it would have come in during the require

Steps to Reproduce

In command line, when I run build, it succeeds.

detox build --configuration ios.sim.debug

Then I run

detox test --configuration ios.sim.debug

Detox, Node, Device, Xcode and macOS Versions

  • Detox: 5.9.2
  • Node: 0.8.2
  • Device: iOS
  • Xcode: 9.0
  • macOS: 10.12.6 Sierra
  • Jest: 21.1.2

Device and verbose Detox logs

     ReferenceError: device is not defined

      at Object.<anonymous>.beforeEach (e2e/init.js:17:16)
          at Promise (<anonymous>)
          at <anonymous>
questiostack overflow

Most helpful comment

Actually the issue must have been the detox.init not being called before the device.reloadReactNative.

Not sure why the beforeAll was not being called before the beforeEach. My quick hack for now was to put:

beforeEach(async () => {
  if (typeof(device) == 'undefined') {
    await detox.init(config);
  }
  await device.reloadReactNative();
});

>All comments

Actually the issue must have been the detox.init not being called before the device.reloadReactNative.

Not sure why the beforeAll was not being called before the beforeEach. My quick hack for now was to put:

beforeEach(async () => {
  if (typeof(device) == 'undefined') {
    await detox.init(config);
  }
  await device.reloadReactNative();
});
Was this page helpful?
0 / 5 - 0 ratings