3
我想单元测试一个Angular.js $timeout
来检查它是否被调用了正确的持续时间/延迟值。
断言将是这个样子:
expect($timeout).toHaveBeenCalledWith(n);
我的角度代码看起来大致如下所示:
$timeout(function() {
// do something
}, attrs.timeout || 30000);
我希望确保没有覆盖(attrs.timeout
)它被称为与30000
并且用覆盖它会被覆盖调用。
我已经尝试了装饰是这样的:
// from: http://stackoverflow.com/a/21536245/633056
beforeEach(module(function($provide) {
$provide.decorator('$timeout', function($delegate) {
return jasmine.createSpy($delegate);
});
}));
加上其他几种方法,但我似乎无法得到它的工作。
我采用了棱角分明1.3.20,茉莉花2.3.4
感激地接受任何建议。
漂亮的工作。谢谢:) – atwright147
@ atwright147不客气。 :) – PSL