diff options
| author | Vojta Jina | 2012-03-23 15:53:04 -0700 |
|---|---|---|
| committer | Vojta Jina | 2012-03-26 21:14:09 -0700 |
| commit | a08cbc02e78e789a66e9af771c410e8ad1646e25 (patch) | |
| tree | bc7081b11d6d1ed4cd5bde3a9e059e5c964e75a8 /test/directive | |
| parent | 55027132f3d57e5dcf94683e6e6bd7b0aae0087d (diff) | |
| download | angular.js-a08cbc02e78e789a66e9af771c410e8ad1646e25.tar.bz2 | |
feat($compile): do not interpolate boolean attributes, rather evaluate them
So that we can have non string values, e.g. ng-value="true" for radio inputs
Breaks boolean attrs are evaluated rather than interpolated
To migrate your code, change: <input ng-disabled="{{someBooleanVariable}}">
to: <input ng-disabled="someBooleanVariabla">
Affected directives:
* ng-multiple
* ng-selected
* ng-checked
* ng-disabled
* ng-readonly
* ng-required
Diffstat (limited to 'test/directive')
| -rw-r--r-- | test/directive/booleanAttrDirSpecs.js | 46 | ||||
| -rw-r--r-- | test/directive/inputSpec.js | 4 | ||||
| -rw-r--r-- | test/directive/selectSpec.js | 2 |
3 files changed, 33 insertions, 19 deletions
diff --git a/test/directive/booleanAttrDirSpecs.js b/test/directive/booleanAttrDirSpecs.js index 8d71c2d8..7a4244a8 100644 --- a/test/directive/booleanAttrDirSpecs.js +++ b/test/directive/booleanAttrDirSpecs.js @@ -17,7 +17,7 @@ describe('boolean attr directives', function() { it('should bind disabled', inject(function($rootScope, $compile) { - element = $compile('<button ng-disabled="{{isDisabled}}">Button</button>')($rootScope) + element = $compile('<button ng-disabled="isDisabled">Button</button>')($rootScope) $rootScope.isDisabled = false; $rootScope.$digest(); expect(element.attr('disabled')).toBeFalsy(); @@ -28,7 +28,7 @@ describe('boolean attr directives', function() { it('should bind checked', inject(function($rootScope, $compile) { - element = $compile('<input type="checkbox" ng-checked="{{isChecked}}" />')($rootScope) + element = $compile('<input type="checkbox" ng-checked="isChecked" />')($rootScope) $rootScope.isChecked = false; $rootScope.$digest(); expect(element.attr('checked')).toBeFalsy(); @@ -39,7 +39,7 @@ describe('boolean attr directives', function() { it('should bind selected', inject(function($rootScope, $compile) { - element = $compile('<select><option value=""></option><option ng-selected="{{isSelected}}">Greetings!</option></select>')($rootScope) + element = $compile('<select><option value=""></option><option ng-selected="isSelected">Greetings!</option></select>')($rootScope) jqLite(document.body).append(element) $rootScope.isSelected=false; $rootScope.$digest(); @@ -51,7 +51,7 @@ describe('boolean attr directives', function() { it('should bind readonly', inject(function($rootScope, $compile) { - element = $compile('<input type="text" ng-readonly="{{isReadonly}}" />')($rootScope) + element = $compile('<input type="text" ng-readonly="isReadonly" />')($rootScope) $rootScope.isReadonly=false; $rootScope.$digest(); expect(element.attr('readOnly')).toBeFalsy(); @@ -62,7 +62,7 @@ describe('boolean attr directives', function() { it('should bind multiple', inject(function($rootScope, $compile) { - element = $compile('<select ng-multiple="{{isMultiple}}"></select>')($rootScope) + element = $compile('<select ng-multiple="isMultiple"></select>')($rootScope) $rootScope.isMultiple=false; $rootScope.$digest(); expect(element.attr('multiple')).toBeFalsy(); @@ -88,24 +88,38 @@ describe('boolean attr directives', function() { expect(element.attr('href')).toEqual('http://server'); expect(element.attr('rel')).toEqual('REL'); })); +}); - it('should bind Text with no Bindings', inject(function($compile, $rootScope) { - forEach(['checked', 'disabled', 'multiple', 'readonly', 'selected'], function(name) { - element = $compile('<div ng-' + name + '="some"></div>')($rootScope) - $rootScope.$digest(); - expect(element.attr(name)).toBe(name); - dealoc(element); - }); +describe('ng-src', function() { - element = $compile('<div ng-src="some"></div>')($rootScope) + it('should interpolate the expression and bind to src', inject(function($compile, $rootScope) { + var element = $compile('<div ng-src="some/{{id}}"></div>')($rootScope) $rootScope.$digest(); - expect(element.attr('src')).toEqual('some'); + expect(element.attr('src')).toEqual('some/'); + + $rootScope.$apply(function() { + $rootScope.id = 1; + }); + expect(element.attr('src')).toEqual('some/1'); + dealoc(element); + })); +}); + + +describe('ng-href', function() { - element = $compile('<div ng-href="some"></div>')($rootScope) + it('should interpolate the expression and bind to href', inject(function($compile, $rootScope) { + var element = $compile('<div ng-href="some/{{id}}"></div>')($rootScope) $rootScope.$digest(); - expect(element.attr('href')).toEqual('some'); + expect(element.attr('href')).toEqual('some/'); + + $rootScope.$apply(function() { + $rootScope.id = 1; + }); + expect(element.attr('href')).toEqual('some/1'); + dealoc(element); })); }); diff --git a/test/directive/inputSpec.js b/test/directive/inputSpec.js index 8d0e44b3..e5f083b3 100644 --- a/test/directive/inputSpec.js +++ b/test/directive/inputSpec.js @@ -941,8 +941,8 @@ describe('input', function() { describe('required', function() { - it('should allow bindings on required', function() { - compileInput('<input type="text" ng-model="value" required="{{required}}" />'); + it('should allow bindings on ng-required', function() { + compileInput('<input type="text" ng-model="value" ng-required="required" />'); scope.$apply(function() { scope.required = false; diff --git a/test/directive/selectSpec.js b/test/directive/selectSpec.js index 3f8fb56e..2e3cfaaf 100644 --- a/test/directive/selectSpec.js +++ b/test/directive/selectSpec.js @@ -780,7 +780,7 @@ describe('select', function() { createSelect({ 'ng-model': 'value', 'ng-options': 'item.name for item in values', - 'ng-required': '{{required}}' + 'ng-required': 'required' }, true); |
