我正在尝试执行异步单元测试:
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
我错过了什么?
答案 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();
});