我设置了用于排毒测试的标准react-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属性。
原生Native:0.60.4
排毒:14.4.1
开玩笑:24.8.0
我不知道这是怎么回事。