aboutsummaryrefslogtreecommitdiffstats
path: root/test/ng/controllerSpec.js
diff options
context:
space:
mode:
authorMisko Hevery2012-03-23 14:03:24 -0700
committerMisko Hevery2012-03-28 11:16:35 -0700
commit2430f52bb97fa9d682e5f028c977c5bf94c5ec38 (patch)
treee7529b741d70199f36d52090b430510bad07f233 /test/ng/controllerSpec.js
parent944098a4e0f753f06b40c73ca3e79991cec6c2e2 (diff)
downloadangular.js-2430f52bb97fa9d682e5f028c977c5bf94c5ec38.tar.bz2
chore(module): move files around in preparation for more modules
Diffstat (limited to 'test/ng/controllerSpec.js')
-rw-r--r--test/ng/controllerSpec.js73
1 files changed, 73 insertions, 0 deletions
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);
+ });
+});