spyOn 给出方法不存在错误
spyOn gives method does not exist error
我正在 运行对 angular 应用程序进行 Karma 测试,在测试中我有以下内容:
return inject(function($injector) {
this.Service = {
functionWithPromise: function(postdata){
var deferred = $q.defer();
deferred.resolve({
data: {}
});
return deferred.promise;
}
};
};
和
it('should call the functionWithPromise function when the create function is called', function() {
res = {}
this.scope.create(res);
this.scope.$digest();
spyOn(Service, "functionWithPromise");
expect(this.Service.functionWithPromise).toHaveBeenCalled();
});
当我 运行 测试时它给出了这个错误:
functionWithPromise() method does not exist
如何获得识别 functionWithPromise() 函数的测试?
明白了,我需要监视 this.Service
而不是服务,就像这样:
spyOn(this.Service, "functionWithPromise");
我正在 运行对 angular 应用程序进行 Karma 测试,在测试中我有以下内容:
return inject(function($injector) {
this.Service = {
functionWithPromise: function(postdata){
var deferred = $q.defer();
deferred.resolve({
data: {}
});
return deferred.promise;
}
};
};
和
it('should call the functionWithPromise function when the create function is called', function() {
res = {}
this.scope.create(res);
this.scope.$digest();
spyOn(Service, "functionWithPromise");
expect(this.Service.functionWithPromise).toHaveBeenCalled();
});
当我 运行 测试时它给出了这个错误:
functionWithPromise() method does not exist
如何获得识别 functionWithPromise() 函数的测试?
明白了,我需要监视 this.Service
而不是服务,就像这样:
spyOn(this.Service, "functionWithPromise");