【发布时间】:2014-04-09 08:39:37
【问题描述】:
在使用 Jasmine 的 spyOn 方法测试同时使用 $timeout 和 $timeout.cancel 的 AngularJS 应用程序的一部分时。
describe('<whatever>', function() {
beforeEach(function() {
spyOn(this, '$timeout').andCallThrough();
spyOn(this.$timeout, 'cancel').andCallThrough();
this.createController();
});
it('should <whatever>', function() {
expect(this.$timeout).toHaveBeenCalled();
expect(this.$timeout.cancel).toHaveBeenCalled();
});
});
您应该在您的应用程序代码中遇到以下错误,该错误正在使用您的测试注入其中的内容。
TypeError: 'undefined' is not a function (evaluating '$timeout.cancel(timeoutPromise)');
【问题讨论】: