angularjs - Unknown provider: $scopeProvider <- $scope -
i trying make small test work validates wether controller defined.
the error receiving is:
myapp.orders module order controller should .... failed error: [$injector:unpr] unknown provider: $scopeprovider <- $scope <- ordersctrl
reading similar errors has dependencies, don't know what's wrong.
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(); })); }); });
this because not passing $scope variabl einside controller when creating in test. , controller tries define $scope.changeview, finds $scope undefined. need pass $scope variable controller in test.
var $rootscope, $scope, $controller; beforeeach(function() { module('myapp.orders'); inject(function (_$rootscope_, _$controller_) { $rootscope = _$rootscope_; $scope = _$rootscope_.$new(); $controller = _$controller_; }); });
and in test,
var ordersctrl = $controller('ordersctrl', { $scope: $scope });
Comments
Post a Comment