【问题标题】:I am getting Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL Error我收到超时 - 在 jasmine.DEFAULT_TIMEOUT_INTERVAL 错误指定的超时内未调用异步回调
【发布时间】:2020-03-29 06:51:25
【问题描述】:

消息:

   Error: Timeout - Async callback was not invoked within timeout specified 
   by jasmine.DEFAULT_TIMEOUT_INTERVAL.

  Stack:
     Error: Timeout - Async callback was not invoked within timeout   
      specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
        at ontimeout (timers.js:365:14)
        at tryOnTimeout (timers.js:237:5)
        at Timer.listOnTimeout (timers.js:207:5)

【问题讨论】:

  • 我们需要您的代码和描述...请添加,否则此问题将被删除

标签: jasmine


【解决方案1】:

jasmine.DEFAULT_TIMEOUT_INTERVAL 是 Jasmine 在抛出超时错误之前等待单个 it 块的时间段(以毫秒为单位)。

超时错误可能表明您的代码有问题,或者只是需要更多时间运行。如另一个答案所述,您可以增加全局 Jasmine 超时间隔,或者对于单个测试,将超时设置如下:

const myTestTimeout: number = 2 * 60 * 1000; //explicitly set for readabilty

it('should validate something', (() => { ...your test code }), myTestTimeout);

我的方法是增加特定测试的超时时间,以确保测试有足够的时间(例如 3 分钟)。如果测试再次失败,您可以非常确定错误的原因是您的代码中的问题。

【讨论】:

  • 您好,除了加个超时,还有其他解决办法吗?
【解决方案2】:

增加 jasmin 默认时间间隔。您将以下代码添加到 conf.js 文件中。

代码:

    jasmineNodeOpts: {
      showColors: true,
      includeStackTrace: true,
      defaultTimeoutInterval: 1440000
     }

【讨论】:

    【解决方案3】:

    将此添加到 karma.conf.js

    module.exports = function(config) {
      config.set({
        client: {
          jasmine: {
            random: true,
            seed: '4321',
            oneFailurePerSpec: true,
            failFast: true,
            timeoutInterval: 1000
          }
        }
      })
    }

    来源https://github.com/karma-runner/karma-jasmine#configuration

    【讨论】:

      猜你喜欢
      • 2016-05-30
      • 1970-01-01
      • 1970-01-01
      • 2017-07-24
      • 2016-04-21
      • 2019-01-07
      • 1970-01-01
      • 2020-05-28
      相关资源
      最近更新 更多