jasmine 2 - 在jasmine.DEFAULT_TIMEOUT_INTERVAL指定的超时时间内未调用异步回调

lfe*_*445 17 javascript jasmine

遇到茉莉花2问题并获得异步规格:

define(['foo'], function(foo) {
  return describe('foo', function() {
    beforeEach(function(done) {
      window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
      return setTimeout((function() {
        console.log('inside timeout');
        return done();
      }), window.jasmine.DEFAULT_TIMEOUT_INTERVAL);
    });
    return it('passes', function() {
      return expect({}).toBeDefined();
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

当我通过业力奔跑时,我会回来

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

然后规格失败了.我试图覆盖默认超时但我无法通过错误

Eit*_*eer 20

您正在使用与Jasmine用于在超时时测试失败相同的超时间隔,即您的超时被触发以使用Jasmine的默认时间间隔触发,这导致测试失败.

如果将超时设置为小于jasmine默认超时,则测试通过.

describe('foo', function () {
    beforeEach(function (done) {
        window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
        setTimeout(function () {
            console.log('inside timeout');
            done();
        }, 500);
    });
    it('passes', function () {
        expect({}).toBeDefined();
    });
});
Run Code Online (Sandbox Code Playgroud)

请看这里的小提琴


Tya*_*esh 6

我的2美分.我在另一个场景中也遇到了问题中提到的这个错误.

我有一个非常简单的规范:

describe('login feature', function() {
    it('should show the logged in user name after successful login', function(done) {
        expect({}).toBeDefined();
        //done(); // if you don't call this done here, then also above error comes
    });
});
Run Code Online (Sandbox Code Playgroud)

在'it'中查看注释掉的// done()函数