diff options
Diffstat (limited to 'test/service')
| -rw-r--r-- | test/service/formFactorySpec.js | 22 | ||||
| -rw-r--r-- | test/service/routeSpec.js | 21 | ||||
| -rw-r--r-- | test/service/scopeSpec.js | 31 |
3 files changed, 21 insertions, 53 deletions
diff --git a/test/service/formFactorySpec.js b/test/service/formFactorySpec.js index fbe601c6..1a23aa49 100644 --- a/test/service/formFactorySpec.js +++ b/test/service/formFactorySpec.js @@ -13,23 +13,24 @@ describe('$formFactory', function() { var scope; var log; - function WidgetCtrl($formFactory){ - this.$formFactory = $formFactory; + function WidgetCtrl($formFactory, $scope) { log += '<init>'; - this.$render = function() { + $scope.$render = function() { log += '$render();'; }; - this.$on('$validate', function(e){ + $scope.$on('$validate', function(e){ log += '$validate();'; }); + + this.$formFactory = $formFactory; } - WidgetCtrl.$inject = ['$formFactory']; + WidgetCtrl.$inject = ['$formFactory', '$scope']; WidgetCtrl.prototype = { - getFormFactory: function() { - return this.$formFactory; - } + getFormFactory: function() { + return this.$formFactory; + } }; beforeEach(inject(function($rootScope, $formFactory) { @@ -70,11 +71,6 @@ describe('$formFactory', function() { expect(widget.$modelValue).toEqual('xyz'); })); - - - it('should have controller prototype methods', inject(function($rootScope, $formFactory) { - expect(widget.getFormFactory()).toEqual($formFactory); - })); }); diff --git a/test/service/routeSpec.js b/test/service/routeSpec.js index 95560d29..1bb1312f 100644 --- a/test/service/routeSpec.js +++ b/test/service/routeSpec.js @@ -112,7 +112,7 @@ describe('$route', function() { inject(function($route, $location, $rootScope) { var onChangeSpy = jasmine.createSpy('onChange'); - function NotFoundCtrl() {this.notFoundProp = 'not found!';} + function NotFoundCtrl($scope) {$scope.notFoundProp = 'not found!';} $route.when('/foo', {template: 'foo.html'}); $route.otherwise({template: '404.html', controller: NotFoundCtrl}); @@ -169,10 +169,11 @@ describe('$route', function() { it('should infer arguments in injection', inject(function($route, $location, $rootScope) { - $route.when('/test', {controller: function($route){ this.$route = $route; }}); + var injectedRoute; + $route.when('/test', {controller: function($route) {injectedRoute = $route;}}); $location.path('/test'); $rootScope.$digest(); - expect($route.current.scope.$route).toBe($route); + expect(injectedRoute).toBe($route); })); @@ -304,9 +305,9 @@ describe('$route', function() { $route.when('/foo', {controller: FooCtrl, reloadOnSearch: false}); $rootScope.$on('$beforeRouteChange', reloaded); - function FooCtrl() { + function FooCtrl($scope) { reloaded(); - this.$on('$routeUpdate', routeUpdateEvent); + $scope.$on('$routeUpdate', routeUpdateEvent); } expect(reloaded).not.toHaveBeenCalled(); @@ -368,8 +369,8 @@ describe('$route', function() { $route.when('/foo', {controller: FooCtrl}); $route.when('/bar/:barId', {controller: FooCtrl, reloadOnSearch: false}); - function FooCtrl() { - this.$watch(function() { + function FooCtrl($scope) { + $scope.$watch(function() { return $route.current.params; }, function(scope, value) { routeParams(value); @@ -414,10 +415,10 @@ describe('$route', function() { } function createController(name) { - return function() { + return function($scope) { log.push('init-' + name); - this.$on('$destroy', logger('destroy-' + name)); - this.$on('$routeUpdate', logger('route-update')); + $scope.$on('$destroy', logger('destroy-' + name)); + $scope.$on('$routeUpdate', logger('route-update')); }; } diff --git a/test/service/scopeSpec.js b/test/service/scopeSpec.js index 96271bc9..68ef2834 100644 --- a/test/service/scopeSpec.js +++ b/test/service/scopeSpec.js @@ -53,35 +53,6 @@ describe('Scope', function() { $rootScope.a = 123; expect(child.a).toEqual(123); })); - - - it('should instantiate controller and bind functions', inject(function($rootScope) { - function Cntl($browser, name) { - this.$browser = $browser; - this.callCount = 0; - this.name = name; - } - Cntl.$inject = ['$browser', 'name']; - - Cntl.prototype = { - myFn: function() { - expect(this).toEqual(cntl); - this.callCount++; - } - }; - - var cntl = $rootScope.$new(Cntl, {name:'misko'}); - - expect($rootScope.$browser).toBeUndefined(); - expect($rootScope.myFn).toBeUndefined(); - - expect(cntl.$browser).toBeDefined(); - expect(cntl.name).toEqual('misko'); - - cntl.myFn(); - cntl.$new().myFn(); - expect(cntl.callCount).toEqual(2); - })); }); @@ -341,7 +312,7 @@ describe('Scope', function() { $rootScope.$digest(); expect(isNaN(log.shift())).toBe(true); //jasmine's toBe and toEqual don't work well with NaNs expect(log).toEqual([undefined, '', false, {}, 23]); - log = [] + log = []; $rootScope.$digest(); expect(log).toEqual([]); })); |
