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
In command line, when I run build, it succeeds.
detox build --configuration ios.sim.debug
Then I run
detox test --configuration ios.sim.debug
ReferenceError: device is not defined
at Object.<anonymous>.beforeEach (e2e/init.js:17:16)
at Promise (<anonymous>)
at <anonymous>
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();
});
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: