【问题标题】:How to increase the time out value using jest.setTimeout如何使用 jest.setTimeout 增加超时值
【发布时间】:2021-10-19 00:26:46
【问题描述】:

我想验证一个可以在一分钟后更新的函数,我在我的代码中设置了一些睡眠,但我的默认超时值是 15000 毫秒,我的代码有睡眠 60000 毫秒所以它返回此错误:

thrown: "Exceeded timeout of 15000 ms for a test.
    Use jest.setTimeout(newTimeout) to increase the timeout value,
    if this is a long-running test."

我的代码在这里

it('shows that timeline can get updated after one minute', async () => {
    await selectTimeForTimeLine.selectTime('Last 5 minutes');
    await page.waitForTimeout(3000);
    const defaultTime = await alarmTimeLine.xAxisValues();
    await page.evaluate(() => {
      return new Promise((resolve) => setTimeout(resolve, 60000));
    });
    const correntTime = await alarmTimeLine.xAxisValues();
    expect(defaultTime).not.toEqual(correntTime);
  });

问题是我应该把“Jest.setTimeOut()”放在哪里。我想将超出的超时值增加到 70000 毫秒,以确保我的代码运行良好。

【问题讨论】:

  • 没有测试应该花费 70 秒:测试您实际需要测试的功能而不是一整分钟的人工等待时间。
  • 这个测试用例我应该等一分钟,70秒是jest超时值,问题是我应该把jest.settimeout放在哪里,
  • 您确实不应该这样做:您正在测试的内容不需要通过 70 秒,它需要您的代码认为通过 70 秒。模拟那个,而不是让你的测试花费一分钟以上什么都不做:这绝对是糟糕的测试。
  • 啊,普通人,是的,我花了几分钟什么都没做,但是我的页面更新数据,检查点是时间线,可以在几分钟后更新,
  • 70 秒超过超时值,实际上我的测试在 60 秒页面更新后完成,

标签: javascript jestjs playwright


【解决方案1】:

这样就解决了

 it('testing balabala', async () => {}, 70000);

只需在此处添加时间数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-27
    • 2023-02-06
    • 1970-01-01
    • 1970-01-01
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多