diff options
| author | Misko Hevery | 2010-03-22 13:58:04 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-03-22 13:58:04 -0700 |
| commit | 84552f7f8ac3f39c4dbd7d946ae2938d63302840 (patch) | |
| tree | d3a4433d12bcbfb9d42f92a7b8ec12762ae7df3a /test/directivesSpec.js | |
| parent | f6664ed7f6f6dd1f4f9756f57611a316089149cb (diff) | |
| download | angular.js-84552f7f8ac3f39c4dbd7d946ae2938d63302840.tar.bz2 | |
got few directives working
Diffstat (limited to 'test/directivesSpec.js')
| -rw-r--r-- | test/directivesSpec.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test/directivesSpec.js b/test/directivesSpec.js new file mode 100644 index 00000000..176f9e70 --- /dev/null +++ b/test/directivesSpec.js @@ -0,0 +1,71 @@ +describe("directives", function(){ + + var compile, element; + + beforeEach(function() { + var compiler = new Compiler(angularMarkup, angularDirective, angularWidget); + compile = function(html) { + element = jqLite(html); + var view = compiler.compile(element.element)(element.element); + view.init(); + return view.scope; + }; + }); + + it("should ng-init", function() { + var scope = compile('<div ng-init="a=123"></div>'); + expect(scope.get('a')).toEqual(123); + }); + + it("should ng-eval", function() { + var scope = compile('<div ng-init="a=0" ng-eval="a = a + 1"></div>'); + expect(scope.get('a')).toEqual(0); + scope.updateView(); + expect(scope.get('a')).toEqual(1); + scope.updateView(); + expect(scope.get('a')).toEqual(2); + }); + + it('should ng-bind', function() { + var scope = compile('<div ng-bind="a"></div>'); + expect(element.text()).toEqual(''); + scope.set('a', 'misko'); + scope.updateView(); + expect(element.text()).toEqual('misko'); + }); + + it('should ng-bind-attr', function(){ + var scope = compile('<img ng-bind-attr="{src:\'mysrc\', alt:\'myalt\'}"/>'); + expect(element.attr('src')).toEqual(null); + expect(element.attr('alt')).toEqual(null); + scope.updateView(); + expect(element.attr('src')).toEqual('mysrc'); + expect(element.attr('alt')).toEqual('myalt'); + }); + + it('should ng-non-bindable', function(){ + var scope = compile('<div ng-non-bindable><span ng-bind="name"></span></div>'); + scope.set('name', 'misko'); + scope.updateView(); + expect(element.text()).toEqual(''); + }); + + it('should ng-repeat over array', function(){ + var scope = compile('<ul><li ng-repeat="item in items" ng-init="suffix = \';\'" ng-bind="item + suffix"></li></ul>'); + + scope.set('items', ['misko', 'shyam']); + scope.updateView(); + expect(element.text()).toEqual('misko;shyam;'); + + scope.set('items', ['adam', 'kai', 'brad']); + scope.updateView(); + expect(element.text()).toEqual('adam;kai;brad;'); + + scope.set('items', ['brad']); + scope.updateView(); + expect(element.text()).toEqual('brad;'); + }); + + it('should ng-repeat over object', function(){}); + it('should error on wrong parsing of ng-repeat', function(){}); +}); |
