【问题标题】:Detox using jest timeout error: "is assigned to undefined"使用开玩笑超时错误进行排毒:“分配给未定义”
【发布时间】:2020-11-11 19:34:48
【问题描述】:

我正在尝试使用 jest 和 jest-circus 将排毒添加到我的 ReactNative 应用程序中,但我目前正在努力使其工作。最新版本从头开始添加了排毒、开玩笑和开玩笑马戏团。

在启动我的测试时,在成功构建后,它会启动模拟器,但在第一次测试时挂起,并因超时和is assigned to undefined 错误而停止。它似乎没有找到模拟器,但它运行正常,并且卸载/安装应用程序过程也正常工作。

这是代码。

environment.js

const {
  DetoxCircusEnvironment,
  SpecReporter,
  WorkerAssignReporter,
} = require('detox/runners/jest-circus')

class CustomDetoxEnvironment extends DetoxCircusEnvironment {
  constructor(config) {
    super(config)

    // Can be safely removed, if you are content with the default value (=300000ms)
    this.initTimeout = 30000

    // This takes care of generating status logs on a per-spec basis. By default, Jest only reports at file-level.
    // This is strictly optional.
    this.registerListeners({
      SpecReporter,
      WorkerAssignReporter,
    })
  }
}

module.exports = CustomDetoxEnvironment

config.json 开玩笑的

{
    "testEnvironment": "./environment",
    "testRunner": "jest-circus/runner",
    "testTimeout": 120000,
    "testRegex": "\\.spec\\.js$",
    "reporters": ["detox/runners/jest/streamlineReporter"],
    "verbose": true
}

.detoxrc.json

{
  "testRunner": "jest",
  "runnerConfig": "test/tdd/config.json",
  "specs": "test/tdd",
  "configurations": {
    "ios.sim.release": {
      "binaryPath": "ios/build/Build/Products/Release-iphonesimulator/BetaSeriesNative.app",
      "build": "export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -workspace ios/BetaSeriesNative.xcworkspace -UseNewBuildSystem=NO -scheme BetaSeriesNative -configuration Release -sdk iphonesimulator -derivedDataPath ios/build -quiet",
      "type": "ios.simulator",
      "device": {
        "type": "iPhone 8"
      },
      "artifacts": {
        "pathBuilder": "./test/tdd/detox.pathbuilder.ios.js"
      }
    }
  }
}

login.spec.js 测试

describe('When on the incentive page', () => {
  beforeEach(async () => {
    await device.reloadReactNative()
  })

  it('it should open the login view', async () => {
    await expect(element(by.id('LoginView'))).toBeVisible()
    await expect(element(by.id('LoginView_button'))).toBeVisible()
    await element(by.id('LoginView_button')).tap()

    await expect(element(by.id('LoginView_form'))).toBeVisible()
  })
})

这是错误。

谢谢!

【问题讨论】:

    标签: react-native jestjs detox jest-circus


    【解决方案1】:

    好的,看来我找到了问题所在。

    我在beforeEach 挂钩中添加了await device.disableSynchronization() 并删除了await device.reloadReactNative()

    我还在我的应用程序中注释了很多代码,并在我的第一个主页视图渲染中返回了null

    我当然尝试在我的渲染中返回null,而不在我的测试中添加/删除这些行,但是没有它,它仍然不起作用。

    虽然很奇怪。有时在启动测试时它仍然挂起,我仍然遇到与以前相同的错误:is assigned to undefined。当我重新启动它时,有时它会像下面的屏幕截图一样工作。我会说它现在可以正常工作,可能是 3 分之 2。也许我的应用程序中仍有一些代码挂起测试然后超时,所以我会继续寻找。

    无论如何,我认为更好的错误或可能来自其他地方或应用程序本身的警告会更好地理解这种错误。现在还不清楚错误的来源,即使启用了调试和详细信息。

    希望对你们中的一些人有所帮助。 干杯。

    P.S 在屏幕截图中我的测试仍然失败,因为我没有编辑测试,但至少它可以正常运行测试:)

    【讨论】:

    • 我昨天也遇到了同样的问题。我没有完美的解决方案,但通过切换到 Android,我能够让我的测试完全运行。我不得不将我的 targetSdkVersion 更改为 29,并且我成功使用了 Pixel 2 API 27 模拟器。我的测试无法在任何其他 API 模拟器上正常运行。
    猜你喜欢
    • 2020-09-11
    • 1970-01-01
    • 1970-01-01
    • 2021-10-12
    • 2022-07-12
    • 1970-01-01
    • 2023-03-03
    • 2018-08-23
    • 2021-09-17
    相关资源
    最近更新 更多