aboutsummaryrefslogtreecommitdiffstats
path: root/test/directive/booleanAttrDirSpecs.js
diff options
context:
space:
mode:
authorVojta Jina2012-03-23 15:53:04 -0700
committerVojta Jina2012-03-26 21:14:09 -0700
commita08cbc02e78e789a66e9af771c410e8ad1646e25 (patch)
treebc7081b11d6d1ed4cd5bde3a9e059e5c964e75a8 /test/directive/booleanAttrDirSpecs.js
parent55027132f3d57e5dcf94683e6e6bd7b0aae0087d (diff)
downloadangular.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/booleanAttrDirSpecs.js')
-rw-r--r--test/directive/booleanAttrDirSpecs.js46
1 files changed, 30 insertions, 16 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);
}));
});