ReferenceError: элемент не определен во время теста на детокс - PullRequest
0 голосов
/ 19 октября 2019

Я установил стандартный config-native для тестирования детоксикации. Эмулятор и приложение запускаются нормально, но во время первого теста я получаю сообщение об ошибке

ReferenceError: element is not defined
> 12 |   it('should have an Input for login', async () => {
     |                                        ^

и

  ReferenceError: device is not defined

      1 | describe('Example', () => {
      2 |   beforeEach(async () => {
    > 3 |     await device.reloadReactNative();
        |           ^

и тесты прерываются.

В то же время я

  Timeout - Async callback was not invoked within the 50000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 50000ms timeout specified by jest.setTimeout.

      at mapper (../node_modules/jest-jasmine2/build/queueRunner.js:25:45)

Ошибка.

Инициал детоксикации:

const detox = require('detox');
const adapter = require('detox/runners/jest/adapter');
const specReporter = require('detox/runners/jest/specReporter');
const config = require('../package.json').detox;

// Set the default timeout
// jest.setTimeout(12000);
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
jasmine.getEnv().addReporter(adapter);

// This takes care of generating status logs on a per-spec basis. By default, jest only reports at file-level.
// This is strictly optional.
jasmine.getEnv().addReporter(specReporter);

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

beforeEach(async () => {
  await adapter.beforeEach();
});

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

Тестовый файл:

describe('Example', () => {
  beforeEach(async () => {
    await device.reloadReactNative();
  });

  it('should have an Input for login', async () => {
    await expect(element(by.id('input'))).toBeVisible();
  });
});

package.json:

...
  "detox": {
    "test-runner": "jest",
    "configurations": {
      "android.emu.release": {
        "binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
        "build": "cd android && ./gradlew clean && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && cd ..",
        "type": "android.emulator",
        "name": "detox"
      }
    }
  }

Остальные файлы, такие как DetoxTest.java, идентичны рекомендуемым настройкам. TestID prop установлен на элементе Input.

React Native: 0.60.4
detox: 14.4.1
jest: 24.8.0

Я не знаю, что такоездесь происходит.

...