在jest.setTimeout指定的5000ms超时内未调用异步回调 [英] Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout

查看:4009
本文介绍了在jest.setTimeout指定的5000ms超时内未调用异步回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用puppeteer和jest进行一些前端测试.

I'm using puppeteer and jest to run some front end tests.

我的测试如下:

describe("Profile Tab Exists and Clickable: /settings/user", () => {
    test(`Assert that you can click the profile tab`, async () => {
      await page.waitForSelector(PROFILE.TAB);
      await page.click(PROFILE.TAB);
    }, 30000);
});

有时候,当我运行测试时,一切都会按预期进行.其他时候,我得到一个错误:

Sometimes, when I run the tests, everything works as expectedly. Other times, I get an error:

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

      at node_modules/jest-jasmine2/build/queue_runner.js:68:21
      at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:633:19)

这很奇怪,因为:

  1. 我将超时设置为30000

  1. I specified the timeout to be 30000

我是否收到此错误似乎非常随机

Whether or not I get this error is seemingly very random

有人能猜出为什么会这样吗?

Can anyone guess why this is happening?

推荐答案

因此,您在此处指定的超时时间必须短于默认超时时间.

So the timeout you specify here needs to be shorter than the default timeout.

默认超时为5000,对于jest,默认情况下框架为jasmine.您可以通过添加

The default timeout is 5000 and the framework by default is jasmine in case of jest. You can specify the timeout inside the test by adding

jest.setTimeout(30000);

但这是特定于测试的.或者,您可以为框架设置配置文件.

But this would be specific to the test. Or you can setup the config file for the framework.

https://facebook.github.io/jest/docs/en/configuration.html#setuptestframeworkscriptfile-string

// jest.config.js
module.exports = {
  setupTestFrameworkScriptFile: './jest.setup.js'
}

// jest.setup.js
jest.setTimeout(30000)

另请参阅此线程

https://github.com/facebook/jest/issues/5055

https://github.com/facebook/jest/issues/652

这篇关于在jest.setTimeout指定的5000ms超时内未调用异步回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆