我收到超时 - 在jasmine.DEFAULT_TIMEOUT_INTERVAL错误指定的超时内未调用异步回调错误

时间:2016-12-27 11:20:12

标签: jasmine

消息:

   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)

3 个答案:

答案 0 :(得分:5)

jasmine.DEFAULT_TIMEOUT_INTERVAL是以毫秒为单位的时间段,Jas​​mine将在抛出超时错误之前等待单个it块。

超时错误可能表示您的代码出现问题,或者只是需要花费更多时间。如另一个答案中所述,您可以增加全局Jasmine超时间隔,或者,对于单个测试,可以像这样设置超时:

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

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

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

答案 1 :(得分:4)

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

<强>代码:

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

答案 2 :(得分:0)

将此添加到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

相关问题