Here is a controller that utilizes a submit function:
$scope.submit = function(){
$http.post('/api/project', $scope.project)
.success(function(data, status){
$modalInstance.dismiss(true);
})
.error(function(data){
console.log(data);
})
}
}
This is my test scenario:
it('should send a POST request to /api/project on submit and close the modal on success', function() {
scope.submit();
$httpBackend.expectPOST('/api/project').respond(200, 'test');
$httpBackend.flush();
expect(modalInstance.dismiss).toHaveBeenCalledWith(true);
});
An error message is displayed as:
Error: Unexpected request: GET views/appBar.html
The templateUrl points to views/appBar.html:
.state('project', {
url: '/',
templateUrl:'views/appBar.html',
controller: 'ProjectsCtrl'
})
It seems that ui-router is causing $httpBackend to target the templateUrl instead of the submit function. This issue persists in all tests using $httpBackend.
Is there a possible solution for this problem?