Jasmine 2.0:异步测试用例

时间:2014-08-01 14:07:53

标签: angularjs jasmine jasmine-async

我正在尝试执行异步单元测试:

 it('Async thing', function (done) {
      scope.$on('async-stuff-happened', function (e) {
         console.log(e);
         done();
         expect(e.stuff).toEqual("stuff");
     });
     scope.ayncStuff();
 });

我可以在控制台中看到行console.log(e)已执行,但测试结果为:

SPEC HAS NO EXPECTATIONS Async thing

我错过了什么?

1 个答案:

答案 0 :(得分:6)

只需在断言语句后移动done()调用:

it('Async thing', function (done) {
  scope.$on('async-stuff-happened', function (e) {
    console.log(e);
    expect(e.stuff).toEqual("stuff");
    done();
  });
  scope.ayncStuff();
});