Ich versuche, einen kleinen Test durchzuführen, der überprüft, ob der Controller definiert ist.
Der Fehler Ich erhalte ist:
myApp.orders module Order controller should .... FAILED
Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- OrdersCtrl
Lesen ähnliche Fehler es etwas mit den Abhängigkeiten zu tun hat, aber ich weiß nicht, was los ist.
Controller:
'use strict';
angular.module('myApp.orders', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/orders', {
templateUrl: 'orders/orders.template.html',
controller: 'OrdersCtrl'
});
}])
.controller('OrdersCtrl', function($scope, $location) {
$scope.changeView = function(view){
$location.path(view); // path not hash
}
});
Test:
'use strict';
describe('myApp.orders module', function() {
beforeEach(module('myApp.orders'));
describe('Order controller', function(){
it('should ....', inject(function($controller) {
//spec body
var OrdersCtrl = $controller('OrdersCtrl');
expect(OrdersCtrl).toBeDefined();
}));
});
});
Dies sollte nicht der Fall sein, aber man kann mit .Controller ('OrdersCtrl' [ '$ scope', '$ location', function versuchen ($ scope, $ location) { $ scope.changeView = Funktion (view) { $ location.path (view); // Pfad nicht Hash } }]); – Indra