angularjs - $httpBackend.verifyNoOutstandingExpectation() leading to "No response defined !" error -
my understanding of $httpbackend.verifynooutstandingexpectation() says "make sure of requests $httpbackend.expect()
-ed tests made code. if of them weren’t, i’ll throw exception."
1) seems redundant. isn't case corresponding $httpbackend.expect()
fail, , alert you?
2) i'm getting no response defined !
error when use $httpbackend.verifynooutstandingexpectation()
. error goes away , test passes when remove $httpbackend.verifynooutstandingexpectation()
. why be?
admin.controller.spec.js:14
refers $httpbackend.verifynooutstandingexpectation()
call.
admin.controller.spec.js
describe('admincontroller', function() { var admincontroller, scope, $httpbackend; beforeeach(module('mean-starter')); beforeeach(inject(function($controller, $rootscope, _$httpbackend_) { $httpbackend = _$httpbackend_; scope = $rootscope.$new(); admincontroller = $controller('admincontroller', { $scope: scope }); })); aftereach(function() { $httpbackend.verifynooutstandingexpectation(); // $httpbackend.verifynooutstandingrequest(); }); it('gets users', function() { $httpbackend.expectget('/users'); }); });
admin.controller.js
angular .module('mean-starter') .controller('admincontroller', admincontroller); function admincontroller(user, auth, $state) { var vm = this; user .list() .success(function(data) { vm.users = data; }) .error(function() { console.log('problem getting users.'); }); vm.delete = function(id) { user .delete(id) .success(function(data) { if (auth.getcurrentuser()._id === id) auth.logout(); // deleting else $state.reload(); }) .error(function() { console.log('problem deleting user.'); }); }; }
the error message states problem - need define expected response before can verify expectation has been satisfied.
change
$httpbackend.expectget('/users');
to
$httpbackend.expectget('/users').respond([{ //response object or array }]);
Comments
Post a Comment