I have a function in my scope to retrieve the status of my service when the user clicks a button, or
when some event are triggered and this function is automatically called.
This is my function, defined in the controller I am using:
$scope.getStatus = function() {
$http({method: 'GET', url: config.entrypoint + config.api + '/outbound/service/' + $scope.serviceId})
.success(function(data) {
$scope.errorMessage = '';
$scope.serviceAllGood = data;
})
.error(function() {
$scope.serviceAllGood = '';
$scope.errorMessage = 'We are experiencing problems retrieving your service status.';
});
}
The unit test is made like:
describe('SendServiceCtrl', function(){
var scope, ctrl, $httpBackend, configuration;
beforeEach(function () {
module('papi', 'ngUpload');
});
beforeEach(inject(function(_$httpBackend_, $rootScope, $controller, config) {
configuration = config;
$httpBackend = _$httpBackend_;
$httpBackend.expectGET(configuration.entrypoint + configuration.api + "/user/outboundstatus/").respond(200, {"meta":{"apiVersion":"0.1","code":200,"errors":null},"response":{"allowed":false}});
scope = $rootScope.$new();
ctrl = $controller('SendServiceCtrl', {$scope: scope});
}));
it('Should get the status', function() {
scope.serviceId = '09bb5943fa2881e1';
scope.getStatus();
$httpBackend.whenGET(configuration.entrypoint + configuration.api + '/outbound/service/' + scope.serviceId).respond(200, {"meta":{"apiVersion":"0.1","code":200,"errors":null}});
});
});
In the unit test I have also other $httpBackend tests on the same controller, but all of them works just somoothely. What am I doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…