7
ho questo semplice test:Perché il mio test di karma non funziona?
describe('My Controller', function() {
beforeEach(function() {
module('myApp');
return inject(function($injector) {
var $controller = $injector.get('$controller');
this.rootScope = $injector.get('$rootScope');
this.scope = this.rootScope.$new();
this.controller = $controller('MyCtrl', {
'$scope': this.scope,
});
});
});
it('should have a controller', function() {
expect(this.controller).toBeDefined();
});
});
il controller è simile al seguente:
angular.module('myApp').controller('MyCtrl', ['$scope', '$state', '$filter', '$q', 'BookingService', 'ngToast', '$uibModal',
function($scope, $state, $filter, $q, BookingService, ngToast, $uibModal) {
$scope.bs = BookingService;
$scope.roundTrip = false;
$scope.reservationDetails = {};
$scope.originAddress = false;
$scope.destinationAddress = false;
$scope.reservationDetails.roundTrip = false;
$scope.seatReservationDepart = {};
$scope.charter = false;
}]);
Il test mantiene in mancanza e il terminale non è in realtà dando tutte le informazioni utili sul perché.
Si potrebbe andare a http: // localhost: 9876/debug.html, questo vi permetterà di eseguire il debug nella console, come si farebbe normalmente che preferisco sul terminale. A supposizione di ciò che va storto, il tuo controller ha un sacco di dipendenze che non fornisci nei tuoi test. - edit: prova ad aggiungere lo stack degli errori, perché il debugging è molto difficile :) – Pjetr