From 2430f52bb97fa9d682e5f028c977c5bf94c5ec38 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 23 Mar 2012 14:03:24 -0700 Subject: chore(module): move files around in preparation for more modules --- test/ng/controllerSpec.js | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 test/ng/controllerSpec.js (limited to 'test/ng/controllerSpec.js') diff --git a/test/ng/controllerSpec.js b/test/ng/controllerSpec.js new file mode 100644 index 00000000..91389013 --- /dev/null +++ b/test/ng/controllerSpec.js @@ -0,0 +1,73 @@ +'use strict'; + +describe('$controller', function() { + var $controllerProvider, $controller; + + beforeEach(module(function(_$controllerProvider_) { + $controllerProvider = _$controllerProvider_; + })); + + + beforeEach(inject(function(_$controller_) { + $controller = _$controller_; + })); + + + describe('provider', function() { + + it('should allow registration of controllers', function() { + var FooCtrl = function($scope) { $scope.foo = 'bar' }, + scope = {}, + ctrl; + + $controllerProvider.register('FooCtrl', FooCtrl); + ctrl = $controller('FooCtrl', {$scope: scope}); + + expect(scope.foo).toBe('bar'); + expect(ctrl instanceof FooCtrl).toBe(true); + }); + + + it('should allow registration of controllers annotated with arrays', function() { + var FooCtrl = function($scope) { $scope.foo = 'bar' }, + scope = {}, + ctrl; + + $controllerProvider.register('FooCtrl', ['$scope', FooCtrl]); + ctrl = $controller('FooCtrl', {$scope: scope}); + + expect(scope.foo).toBe('bar'); + expect(ctrl instanceof FooCtrl).toBe(true); + }); + }); + + + it('should return instance of given controller class', function() { + var MyClass = function() {}, + ctrl = $controller(MyClass); + + expect(ctrl).toBeDefined(); + expect(ctrl instanceof MyClass).toBe(true); + }); + + it('should inject arguments', inject(function($http) { + var MyClass = function($http) { + this.$http = $http; + }; + + var ctrl = $controller(MyClass); + expect(ctrl.$http).toBe($http); + })); + + + it('should inject given scope', function() { + var MyClass = function($scope) { + this.$scope = $scope; + }; + + var scope = {}, + ctrl = $controller(MyClass, {$scope: scope}); + + expect(ctrl.$scope).toBe(scope); + }); +}); -- cgit v1.2.3