我正在尝试测试一个角度控制器,模拟使用jasmine对服务进行的调用。我想检查一下是成功还是错误。我尝试用$ q来做这件事,但它对我的回归没有影响。这该怎么做? 我试过这样:
$scope.savestuff = function () {
return some.method.test($scope.data, {
success: function () {
return true;
},
error: function (error) {
$scope.error= error.data.message;
}
});
}
[mycode的] [1]
服务:
.service('some', ['$http', '$q', function ($http, $q) {
var service = {};
service.method = {
test: function (data, config) {
return service.run({
call: $http({
method: "POST",
}),
success: config.success,
error: config.error
});
}
};
return service;
}]);
答案 0 :(得分:0)
service.run,
spyOn(service, 'run').and.callFake(function(obj){
return obj.success();
//or obj.error({data: {message: 'Server error'}});
});
$http
$httpBackend
$httpBackend.expect('POST','/user/edit').respond({
response: {something: here}
});
spyOn(action.user, 'update')...