无限的茉莉花超时 [英] Infinite jasmine timeout

查看:111
本文介绍了无限的茉莉花超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这基本上是删除单个茉莉花规格的超时 github问题的后续行动。

This is basically a follow-up to Remove timeout for single jasmine spec github issue.

问题:

是否有可能从未进行过一次测试超时?

Is it possible to make a single test never timeout?

问题:

可以设置超时值全球通过 DEFAULT_TIMEOUT_INTERVAL 或每个描述 beforeEach / afterEach 或单个 it() block:

It is possible to set a timeout value globally via DEFAULT_TIMEOUT_INTERVAL or for every describe with beforeEach/afterEach or on a single it() block:

it('Has a custom timeout', function() {
  expect(true).toBeTruthy();
}, value in msec)

我很感兴趣在单个规范永远不会超时。我试图按照上面提到的github问题提出的建议,并使用 Infinity

I'm interested in having a single spec never timeout. I've tried to follow the advice proposed in the mentioned github issue and use Infinity:

it('Has a custom timeout', function() {
  expect(true).toBeTruthy();
}, Infinity)

但是,我在测试进入 it()后立即出现以下错误阻止:

but, I've got the following error immediately after the tests got into the it() block:


错误:超时 - 在jasmine.DEFAULT_TIMEOUT_INTERVAL

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

我想我不能使用 Infinity 作为超时值,或者我做错了。

I guess I cannot use Infinity as a timeout value, or I'm doing something wrong.

作为一种解决方法,我可以使用硬编码的大数字,但我想避免这种情况。

As a workaround, I can use a hardcoded large number instead, but I'd like to avoid that.

推荐答案

Jasmine在内部使用 setTimeout 等待规范在规定的时间内完成。

Jasmine internally uses setTimeout to wait for specs to finish for a defined period of time.

根据此Q / A - 为什么setTimeout()中断?对于大毫秒延迟值?

According to this Q/A - Why does setTimeout() "break" for large millisecond delay values?:


setTimeout使用32位int来存储延迟

setTimeout using a 32 bit int to store the delay

...

超时值太大而不适合签名的32位整数可能导致FF,Safari中的
溢出和Chrome,导致超时为
立即安排。更简单的是没有安排这些超时的
,因为24.8天超出浏览器保持开放的
的合理预期。

Timeout values too big to fit into a signed 32-bit integer may cause overflow in FF, Safari, and Chrome, resulting in the timeout being scheduled immediately. It makes more sense simply not to schedule these timeouts, since 24.8 days is beyond a reasonable expectation for the browser to stay open.

只要 Infinity 大于任何其他数字,就会发生溢出。

As soon as Infinity is greater than any other number the overflow occurs.

在这种情况下,最大安全整数是2 31 -1 = 2147483647.这个值是有限的,所以测试实际上不会无限长地运行,但正如我所说的那样24.8天是足够长的。

The max safe integer in this case is 231-1 = 2147483647. This value is finite, so the test won't actually run infinitely long, but as said I think 24.8 days is long enough.

您可以定义一个常量来存储此值:

You can define a constant to store this value:

jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000;

var MAX_SAFE_TIMEOUT = Math.pow(2, 31) - 1;

describe('suite', function () {

  it('should work infinitely long', function (done) {

    setTimeout(function () {
      expect(true).toBe(true);
      done();
    }, 3000)

  }, MAX_SAFE_TIMEOUT);

});

请参阅此处的工作示例

这篇关于无限的茉莉花超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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