i dont know if valid question long inject ngroute app $scope undefined.
the app without ng-route looks this
angular.module('dummyapp', []) .controller('dummyctrl', ['$scope', function ($scope) { $scope.name = "world"; }]);
the test case this
describe( 'dummy controller', function(){ var scope, http, dummyctrl; beforeeach(module('dummyapp')); beforeeach(inject(function($controller, $rootscope) { scope = $rootscope.$new(); dummyctrl = $controller('dummyctrl', { $scope: scope }); })); it('should contain word world', function(){ expect(scope.name).toequal("world"); }); });
passing without error
but if inject ngroute app
angular.module('dummyapp', ['ngroute']) .controller('dummyctrl', ['$scope', function ($scope) { $scope.name = "world"; }]);
typeerror: 'undefined' not object (evaluating 'scope.name')
i tried configure $routeprovider see below don't know how write test if ngroute injected
angular.module('dummyapp', ['ngroute']).app.config(['$routeprovider', function ($routeprovider) { $routeprovider. when('/smth', { templateurl: 'smth.html', controller: 'testcontroller' }); }]) .controller('dummyctrl', ['$scope', function ($scope) { $scope.name = "world"; }]);
Comments
Post a Comment