Questo è un controller con una funzione di conferma:
$scope.submit = function(){
$http.post('/api/project', $scope.project)
.success(function(data, status){
$modalInstance.dismiss(true);
})
.error(function(data){
console.log(data);
})
}
}
Questa è la mia prova
it('should make a post 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);
});
L'errore che ottengo è:
Error: Unexpected request: GET views/appBar.html
viste/appBar.html è il mio TemplateURL:
.state('project', {
url: '/',
templateUrl:'views/appBar.html',
controller: 'ProjectsCtrl'
})
Quindi in qualche modo ui-router sta facendo il mio $ httpBackend punta a questo invece della mia funzione di invio. Ho lo stesso problema in tutti i miei test usando $ httpBackend.
C'è qualche soluzione a questo?
Problema correlato all'interfaccia utente n. 212 con alcuni suggerimenti: https://github.com/angular-ui/ui-router/issues/212#issuecomment-69974072 –