I'm struggling to understand why I have to use $rootScope.$digest()
before my test can pass with $httpBackend.flush()
.
If I skip it, I end up with
Error: No pending request to flush!
This is the code for my test:
it('should post a new task to the server', function() {
$httpBackend.when('POST', $rootScope.serverRoot + '/task/create').respond({});
var created = false;
mockBoardService.addTask({name: 'Add dynamic categories'})
.then(function(response) {
created = true;
}
);
$rootScope.$digest();
$httpBackend.flush();
expect(created).toBe(true);
})
The service function being called is:
this.addTask = function(data) {
return $http.post($rootScope.serverRoot + '/task/create', data);
}
I'm wondering about the necessity of using $rootScope.$digest
.