diff options
| author | Misko Hevery | 2010-10-06 17:01:41 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-10-08 16:23:26 -0700 |
| commit | 772e32c220193f026c6f4b4674b44ab915e6f0f0 (patch) | |
| tree | 83620adb4d35c0ce63d4cf4d1a92e30a1d59eabd /test | |
| parent | c30807d1413ea9942bcb065a02997082bf4291aa (diff) | |
| download | angular.js-772e32c220193f026c6f4b4674b44ab915e6f0f0.tar.bz2 | |
change ng:controller to create new scope hence allow nesting
Diffstat (limited to 'test')
| -rw-r--r-- | test/directivesSpec.js | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 10400ead..42a4879a 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -254,23 +254,53 @@ describe("directives", function(){ }); describe('ng:controller', function(){ - it('should bind', function(){ - window.Greeter = function(){ + + var temp; + + beforeEach(function(){ + temp = window.temp = {}; + temp.Greeter = function(){ + this.$root.greeter = this; this.greeting = 'hello'; + this.suffix = '!'; }; - window.Greeter.prototype = { - init: function(){ - this.suffix = '!'; - }, + temp.Greeter.prototype = { greet: function(name) { return this.greeting + ' ' + name + this.suffix; } }; - var scope = compile('<div ng:controller="Greeter"></div>'); - expect(scope.greeting).toEqual('hello'); - expect(scope.greet('misko')).toEqual('hello misko!'); - window.Greeter = undefined; }); + + afterEach(function(){ + window.temp = undefined; + }); + + it('should bind', function(){ + var scope = compile('<div ng:controller="temp.Greeter"></div>'); + expect(scope.greeter.greeting).toEqual('hello'); + expect(scope.greeter.greet('misko')).toEqual('hello misko!'); + }); + + it('should support nested controllers', function(){ + temp.ChildGreeter = function() { + this.greeting = 'hey'; + this.$root.childGreeter = this; + }; + temp.ChildGreeter.prototype = { + greet: function() { + return this.greeting + ' dude' + this.suffix; + } + }; + var scope = compile('<div ng:controller="temp.Greeter"><div ng:controller="temp.ChildGreeter">{{greet("misko")}}</div></div>'); + expect(scope.greeting).not.toBeDefined(); + expect(scope.greeter.greeting).toEqual('hello'); + expect(scope.greeter.greet('misko')).toEqual('hello misko!'); + expect(scope.greeter.greeting).toEqual('hello'); + expect(scope.childGreeter.greeting).toEqual('hey'); + expect(scope.childGreeter.$parent.greeting).toEqual('hello'); + expect(scope.$element.text()).toEqual('hey dude!'); + }); + }); it('should eval things according to ng:eval-order', function(){ |
