In the SampleController below , as a unit test, the postAttributes function calls sampleService.updateMethod . I'm having problems since updateMethod returns a promise.
angular.module('sampleModule')
.controller('SampleController', SampleController);
SampleController.$inject =['sampleService'];
function SampleController(sampleService){
this.postAttributes = function() {
sampleService.updateMethod(number,attributes)
.then(function(response){
},function(response){
});
};
}
Here is the factory service that I have:
angular.module('sampleModule')
.factory('sampleService', sampleService);
sampleService.$inject = ['$http'];
function sampleService($http) {
return {
getMethod: function(acctNumber){
return $http({
method: 'GET',
url:
});
},
updateMethod: function(number, attributes){
return $http({
method: 'PUT',
url:
data:
});
}
};
}
I would like to mock the factory service in the controller specification, rather than inject the actual service directly into $ controller, since most unit testing guides test an isolated device.
Controller Specification Example:
describe('SampleController Test', function(){
var $controller;
var service;
beforeEach(angular.mock.module('sampleModule'));
beforeEach(angular.mock.inject(function(_$controller_){
$controller = _$controller_;
}));
it('Testing $scope variable', function(){
var sampleController = $controller('SampleController', {
sampleService: service,
});
sampleController.postAttributes();
});
});