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

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

问题描述

我正在使用 Puppeteer 和 Jest 运行一些前端测试.

我的测试如下:

describe("Profile Tab Exists and Clickable:/settings/user", () => {test(`断言你可以点击个人资料选项卡`, async () => {等待 page.waitForSelector(PROFILE.TAB);等待 page.click(PROFILE.TAB);}, 30000);});

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

<块引用>

超时 - 在 jest.setTimeout 指定的 5000 毫秒超时内未调用异步回调.

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

这很奇怪,因为:

  1. 我指定的超时时间为 30000

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

为什么会这样?

解决方案

您在此处指定的超时时间需要短于默认超时时间.

默认超时时间为5000,框架默认为jasmine,如果是jest.您可以通过添加

来指定测试内部的超时时间

jest.setTimeout(30000);

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

配置 Jest

//jest.config.js模块.出口 = {//setupTestFrameworkScriptFile 已被弃用//在 jest 24 中支持 setupFilesAfterEnvsetupFilesAfterEnv: ['./jest.setup.js']}//jest.setup.jsjest.setTimeout(30000)

另见这些主题:

每次测试的 setTimeout #5055

使 jasmine.DEFAULT_TIMEOUT_INTERVAL 可配置 #652

P.S.:拼写错误的setupFilesAfterEnv(即setupFileAfterEnv)也会抛出同样的错误.

I'm using Puppeteer and Jest to run some front end tests.

My tests look as follows:

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 5000 ms timeout specified by jest.setTimeout.

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

This is strange because:

  1. I specified the timeout to be 30000

  2. Whether or not I get this error is seemingly very random

Why is this happening?

解决方案

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

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 set up the configuration file for the framework.

Configuring Jest

// jest.config.js
module.exports = {
  // setupTestFrameworkScriptFile has been deprecated in
  // favor of setupFilesAfterEnv in jest 24
  setupFilesAfterEnv: ['./jest.setup.js']
}

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

See also these threads:

setTimeout per test #5055

Make jasmine.DEFAULT_TIMEOUT_INTERVAL configurable #652

P.S.: The misspelling setupFilesAfterEnv (i.e. setupFileAfterEnv) will also throw the same error.

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

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