From 02cf958a076b140690ab9ea4ed00c490f52cbf91 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Tue, 3 Apr 2012 17:26:09 -0700 Subject: chore(directive): correct file names for booleanAttrs --- angularFiles.js | 2 +- src/ng/directive/booleanAttrDirs.js | 324 ------------------------------- src/ng/directive/booleanAttrs.js | 324 +++++++++++++++++++++++++++++++ test/ng/directive/booleanAttrDirSpecs.js | 144 -------------- test/ng/directive/booleanAttrsSpec.js | 144 ++++++++++++++ 5 files changed, 469 insertions(+), 469 deletions(-) delete mode 100644 src/ng/directive/booleanAttrDirs.js create mode 100644 src/ng/directive/booleanAttrs.js delete mode 100644 test/ng/directive/booleanAttrDirSpecs.js create mode 100644 test/ng/directive/booleanAttrsSpec.js diff --git a/angularFiles.js b/angularFiles.js index 8d2ffbbb..c819b629 100644 --- a/angularFiles.js +++ b/angularFiles.js @@ -39,7 +39,7 @@ angularFiles = { 'src/ng/directive/directives.js', 'src/ng/directive/a.js', - 'src/ng/directive/booleanAttrDirs.js', + 'src/ng/directive/booleanAttrs.js', 'src/ng/directive/form.js', 'src/ng/directive/input.js', 'src/ng/directive/ngBind.js', diff --git a/src/ng/directive/booleanAttrDirs.js b/src/ng/directive/booleanAttrDirs.js deleted file mode 100644 index fee10ed8..00000000 --- a/src/ng/directive/booleanAttrDirs.js +++ /dev/null @@ -1,324 +0,0 @@ -'use strict'; - -/** - * @ngdoc directive - * @name angular.module.ng.$compileProvider.directive.ng-href - * @restrict A - * - * @description - * Using markup like {{hash}} in an href attribute makes - * the page open to a wrong URL, if the user clicks that link before - * angular has a chance to replace the {{hash}} with actual URL, the - * link will be broken and will most likely return a 404 error. - * The `ng-href` solves this problem by placing the `href` in the - * `ng-` namespace. - * - * The buggy way to write it: - *
- * 
- * 
- * - * The correct way to write it: - *
- * 
- * 
- * - * @element A - * @param {template} ng-href any string which can contain `{{}}` markup. - * - * @example - * This example uses `link` variable inside `href` attribute: - - -
-
link 1 (link, don't reload)
- link 2 (link, don't reload)
- link 3 (link, reload!)
- anchor (link, don't reload)
- anchor (no link)
- link (link, change hash) - - - it('should execute ng-click but not reload when href without value', function() { - element('#link-1').click(); - expect(input('value').val()).toEqual('1'); - expect(element('#link-1').attr('href')).toBe(""); - }); - - it('should execute ng-click but not reload when href empty string', function() { - element('#link-2').click(); - expect(input('value').val()).toEqual('2'); - expect(element('#link-2').attr('href')).toBe(""); - }); - - it('should execute ng-click and change url when ng-href specified', function() { - expect(element('#link-3').attr('href')).toBe("/123"); - - element('#link-3').click(); - expect(browser().window().path()).toEqual('/123'); - }); - - it('should execute ng-click but not reload when href empty string and name specified', function() { - element('#link-4').click(); - expect(input('value').val()).toEqual('4'); - expect(element('#link-4').attr('href')).toBe(""); - }); - - it('should execute ng-click but not reload when no href but name specified', function() { - element('#link-5').click(); - expect(input('value').val()).toEqual('5'); - expect(element('#link-5').attr('href')).toBe(""); - }); - - it('should only change url when only ng-href', function() { - input('value').enter('6'); - expect(element('#link-6').attr('href')).toBe("/6"); - - element('#link-6').click(); - expect(browser().window().path()).toEqual('/6'); - }); - - - */ - -/** - * @ngdoc directive - * @name angular.module.ng.$compileProvider.directive.ng-src - * @restrict A - * - * @description - * Using markup like `{{hash}}` in a `src` attribute doesn't - * work right: The browser will fetch from the URL with the literal - * text `{{hash}}` until replaces the expression inside - * `{{hash}}`. The `ng-src` attribute solves this problem by placing - * the `src` attribute in the `ng-` namespace. - * - * The buggy way to write it: - *
- * 
- * 
- * - * The correct way to write it: - *
- * 
- * 
- * - * @element IMG - * @param {template} ng-src any string which can contain `{{}}` markup. - */ - -/** - * @ngdoc directive - * @name angular.module.ng.$compileProvider.directive.ng-disabled - * @restrict A - * - * @description - * - * The following markup will make the button enabled on Chrome/Firefox but not on IE8 and older IEs: - *
- * 
- * - *
- *
- * - * The HTML specs do not require browsers to preserve the special attributes such as disabled. - * (The presence of them means true and absence means false) - * This prevents the angular compiler from correctly retrieving the binding expression. - * To solve this problem, we introduce ng-disabled. - * - * @example - - - Click me to toggle:
- -
- - it('should toggle button', function() { - expect(element('.doc-example-live :button').prop('disabled')).toBeFalsy(); - input('checked').check(); - expect(element('.doc-example-live :button').prop('disabled')).toBeTruthy(); - }); - -
- * - * @element INPUT - * @param {string} expression Angular expression that will be evaluated. - */ - - -/** - * @ngdoc directive - * @name angular.module.ng.$compileProvider.directive.ng-checked - * @restrict A - * - * @description - * The HTML specs do not require browsers to preserve the special attributes such as checked. - * (The presence of them means true and absence means false) - * This prevents the angular compiler from correctly retrieving the binding expression. - * To solve this problem, we introduce ng-checked. - * @example - - - Check me to check both:
- -
- - it('should check both checkBoxes', function() { - expect(element('.doc-example-live #checkSlave').prop('checked')).toBeFalsy(); - input('master').check(); - expect(element('.doc-example-live #checkSlave').prop('checked')).toBeTruthy(); - }); - -
- * - * @element INPUT - * @param {string} expression Angular expression that will be evaluated. - */ - - -/** - * @ngdoc directive - * @name angular.module.ng.$compileProvider.directive.ng-multiple - * @restrict A - * - * @description - * The HTML specs do not require browsers to preserve the special attributes such as multiple. - * (The presence of them means true and absence means false) - * This prevents the angular compiler from correctly retrieving the binding expression. - * To solve this problem, we introduce ng-multiple. - * - * @example - - - Check me check multiple:
- -
- - it('should toggle multiple', function() { - expect(element('.doc-example-live #select').prop('multiple')).toBeFalsy(); - input('checked').check(); - expect(element('.doc-example-live #select').prop('multiple')).toBeTruthy(); - }); - -
- * - * @element SELECT - * @param {string} expression Angular expression that will be evaluated. - */ - - -/** - * @ngdoc directive - * @name angular.module.ng.$compileProvider.directive.ng-readonly - * @restrict A - * - * @description - * The HTML specs do not require browsers to preserve the special attributes such as readonly. - * (The presence of them means true and absence means false) - * This prevents the angular compiler from correctly retrieving the binding expression. - * To solve this problem, we introduce ng-readonly. - * @example - - - Check me to make text readonly:
- -
- - it('should toggle readonly attr', function() { - expect(element('.doc-example-live :text').prop('readonly')).toBeFalsy(); - input('checked').check(); - expect(element('.doc-example-live :text').prop('readonly')).toBeTruthy(); - }); - -
- * - * @element INPUT - * @param {string} expression Angular expression that will be evaluated. - */ - - -/** - * @ngdoc directive - * @name angular.module.ng.$compileProvider.directive.ng-selected - * @restrict A - * - * @description - * The HTML specs do not require browsers to preserve the special attributes such as selected. - * (The presence of them means true and absence means false) - * This prevents the angular compiler from correctly retrieving the binding expression. - * To solve this problem, we introduce ng-selected. - * @example - - - Check me to select:
- -
- - it('should select Greetings!', function() { - expect(element('.doc-example-live #greet').prop('selected')).toBeFalsy(); - input('selected').check(); - expect(element('.doc-example-live #greet').prop('selected')).toBeTruthy(); - }); - -
- * - * @element OPTION - * @param {string} expression Angular expression that will be evaluated. - */ - - -var ngAttributeAliasDirectives = {}; - - -// boolean attrs are evaluated -forEach(BOOLEAN_ATTR, function(propName, attrName) { - var normalized = directiveNormalize('ng-' + attrName); - ngAttributeAliasDirectives[normalized] = function() { - return { - priority: 100, - compile: function(tpl, attr) { - return function(scope, element, attr) { - attr.$$observers[attrName] = []; - scope.$watch(attr[normalized], function(value) { - attr.$set(attrName, !!value); - }); - }; - } - }; - }; -}); - - -// ng-src, ng-href are interpolated -forEach(['src', 'href'], function(attrName) { - var normalized = directiveNormalize('ng-' + attrName); - ngAttributeAliasDirectives[normalized] = function() { - return { - priority: 99, // it needs to run after the attributes are interpolated - compile: function(tpl, attr) { - return function(scope, element, attr) { - var value = attr[normalized]; - if (value == undefined) { - // undefined value means that the directive is being interpolated - // so just register observer - attr.$$observers[attrName] = []; - attr.$observe(normalized, function(value) { - attr.$set(attrName, value); - }); - } else { - // value present means that no interpolation, so copy to native attribute. - attr.$set(attrName, value); - } - }; - } - }; - }; -}); diff --git a/src/ng/directive/booleanAttrs.js b/src/ng/directive/booleanAttrs.js new file mode 100644 index 00000000..fee10ed8 --- /dev/null +++ b/src/ng/directive/booleanAttrs.js @@ -0,0 +1,324 @@ +'use strict'; + +/** + * @ngdoc directive + * @name angular.module.ng.$compileProvider.directive.ng-href + * @restrict A + * + * @description + * Using markup like {{hash}} in an href attribute makes + * the page open to a wrong URL, if the user clicks that link before + * angular has a chance to replace the {{hash}} with actual URL, the + * link will be broken and will most likely return a 404 error. + * The `ng-href` solves this problem by placing the `href` in the + * `ng-` namespace. + * + * The buggy way to write it: + *
+ * 
+ * 
+ * + * The correct way to write it: + *
+ * 
+ * 
+ * + * @element A + * @param {template} ng-href any string which can contain `{{}}` markup. + * + * @example + * This example uses `link` variable inside `href` attribute: + + +
+
link 1 (link, don't reload)
+ link 2 (link, don't reload)
+ link 3 (link, reload!)
+ anchor (link, don't reload)
+ anchor (no link)
+ link (link, change hash) + + + it('should execute ng-click but not reload when href without value', function() { + element('#link-1').click(); + expect(input('value').val()).toEqual('1'); + expect(element('#link-1').attr('href')).toBe(""); + }); + + it('should execute ng-click but not reload when href empty string', function() { + element('#link-2').click(); + expect(input('value').val()).toEqual('2'); + expect(element('#link-2').attr('href')).toBe(""); + }); + + it('should execute ng-click and change url when ng-href specified', function() { + expect(element('#link-3').attr('href')).toBe("/123"); + + element('#link-3').click(); + expect(browser().window().path()).toEqual('/123'); + }); + + it('should execute ng-click but not reload when href empty string and name specified', function() { + element('#link-4').click(); + expect(input('value').val()).toEqual('4'); + expect(element('#link-4').attr('href')).toBe(""); + }); + + it('should execute ng-click but not reload when no href but name specified', function() { + element('#link-5').click(); + expect(input('value').val()).toEqual('5'); + expect(element('#link-5').attr('href')).toBe(""); + }); + + it('should only change url when only ng-href', function() { + input('value').enter('6'); + expect(element('#link-6').attr('href')).toBe("/6"); + + element('#link-6').click(); + expect(browser().window().path()).toEqual('/6'); + }); + + + */ + +/** + * @ngdoc directive + * @name angular.module.ng.$compileProvider.directive.ng-src + * @restrict A + * + * @description + * Using markup like `{{hash}}` in a `src` attribute doesn't + * work right: The browser will fetch from the URL with the literal + * text `{{hash}}` until replaces the expression inside + * `{{hash}}`. The `ng-src` attribute solves this problem by placing + * the `src` attribute in the `ng-` namespace. + * + * The buggy way to write it: + *
+ * 
+ * 
+ * + * The correct way to write it: + *
+ * 
+ * 
+ * + * @element IMG + * @param {template} ng-src any string which can contain `{{}}` markup. + */ + +/** + * @ngdoc directive + * @name angular.module.ng.$compileProvider.directive.ng-disabled + * @restrict A + * + * @description + * + * The following markup will make the button enabled on Chrome/Firefox but not on IE8 and older IEs: + *
+ * 
+ * + *
+ *
+ * + * The HTML specs do not require browsers to preserve the special attributes such as disabled. + * (The presence of them means true and absence means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduce ng-disabled. + * + * @example + + + Click me to toggle:
+ +
+ + it('should toggle button', function() { + expect(element('.doc-example-live :button').prop('disabled')).toBeFalsy(); + input('checked').check(); + expect(element('.doc-example-live :button').prop('disabled')).toBeTruthy(); + }); + +
+ * + * @element INPUT + * @param {string} expression Angular expression that will be evaluated. + */ + + +/** + * @ngdoc directive + * @name angular.module.ng.$compileProvider.directive.ng-checked + * @restrict A + * + * @description + * The HTML specs do not require browsers to preserve the special attributes such as checked. + * (The presence of them means true and absence means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduce ng-checked. + * @example + + + Check me to check both:
+ +
+ + it('should check both checkBoxes', function() { + expect(element('.doc-example-live #checkSlave').prop('checked')).toBeFalsy(); + input('master').check(); + expect(element('.doc-example-live #checkSlave').prop('checked')).toBeTruthy(); + }); + +
+ * + * @element INPUT + * @param {string} expression Angular expression that will be evaluated. + */ + + +/** + * @ngdoc directive + * @name angular.module.ng.$compileProvider.directive.ng-multiple + * @restrict A + * + * @description + * The HTML specs do not require browsers to preserve the special attributes such as multiple. + * (The presence of them means true and absence means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduce ng-multiple. + * + * @example + + + Check me check multiple:
+ +
+ + it('should toggle multiple', function() { + expect(element('.doc-example-live #select').prop('multiple')).toBeFalsy(); + input('checked').check(); + expect(element('.doc-example-live #select').prop('multiple')).toBeTruthy(); + }); + +
+ * + * @element SELECT + * @param {string} expression Angular expression that will be evaluated. + */ + + +/** + * @ngdoc directive + * @name angular.module.ng.$compileProvider.directive.ng-readonly + * @restrict A + * + * @description + * The HTML specs do not require browsers to preserve the special attributes such as readonly. + * (The presence of them means true and absence means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduce ng-readonly. + * @example + + + Check me to make text readonly:
+ +
+ + it('should toggle readonly attr', function() { + expect(element('.doc-example-live :text').prop('readonly')).toBeFalsy(); + input('checked').check(); + expect(element('.doc-example-live :text').prop('readonly')).toBeTruthy(); + }); + +
+ * + * @element INPUT + * @param {string} expression Angular expression that will be evaluated. + */ + + +/** + * @ngdoc directive + * @name angular.module.ng.$compileProvider.directive.ng-selected + * @restrict A + * + * @description + * The HTML specs do not require browsers to preserve the special attributes such as selected. + * (The presence of them means true and absence means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduce ng-selected. + * @example + + + Check me to select:
+ +
+ + it('should select Greetings!', function() { + expect(element('.doc-example-live #greet').prop('selected')).toBeFalsy(); + input('selected').check(); + expect(element('.doc-example-live #greet').prop('selected')).toBeTruthy(); + }); + +
+ * + * @element OPTION + * @param {string} expression Angular expression that will be evaluated. + */ + + +var ngAttributeAliasDirectives = {}; + + +// boolean attrs are evaluated +forEach(BOOLEAN_ATTR, function(propName, attrName) { + var normalized = directiveNormalize('ng-' + attrName); + ngAttributeAliasDirectives[normalized] = function() { + return { + priority: 100, + compile: function(tpl, attr) { + return function(scope, element, attr) { + attr.$$observers[attrName] = []; + scope.$watch(attr[normalized], function(value) { + attr.$set(attrName, !!value); + }); + }; + } + }; + }; +}); + + +// ng-src, ng-href are interpolated +forEach(['src', 'href'], function(attrName) { + var normalized = directiveNormalize('ng-' + attrName); + ngAttributeAliasDirectives[normalized] = function() { + return { + priority: 99, // it needs to run after the attributes are interpolated + compile: function(tpl, attr) { + return function(scope, element, attr) { + var value = attr[normalized]; + if (value == undefined) { + // undefined value means that the directive is being interpolated + // so just register observer + attr.$$observers[attrName] = []; + attr.$observe(normalized, function(value) { + attr.$set(attrName, value); + }); + } else { + // value present means that no interpolation, so copy to native attribute. + attr.$set(attrName, value); + } + }; + } + }; + }; +}); diff --git a/test/ng/directive/booleanAttrDirSpecs.js b/test/ng/directive/booleanAttrDirSpecs.js deleted file mode 100644 index d58ffced..00000000 --- a/test/ng/directive/booleanAttrDirSpecs.js +++ /dev/null @@ -1,144 +0,0 @@ -'use strict'; - -describe('boolean attr directives', function() { - var element; - - afterEach(function() { - dealoc(element); - }); - - - it('should bind href', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) - $rootScope.url = 'http://server'; - $rootScope.$digest(); - expect(element.attr('href')).toEqual('http://server'); - })); - - - it('should bind href even if no interpolation', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) - $rootScope.$digest(); - expect(element.attr('href')).toEqual('http://server'); - })); - - - it('should properly evaluate 0 as false', inject(function($rootScope, $compile) { - // jQuery does not treat 0 as false, when setting attr() - element = $compile('')($rootScope) - $rootScope.isDisabled = 0; - $rootScope.$digest(); - expect(element.attr('disabled')).toBeFalsy(); - $rootScope.isDisabled = 1; - $rootScope.$digest(); - expect(element.attr('disabled')).toBeTruthy(); - })); - - - it('should bind disabled', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) - $rootScope.isDisabled = false; - $rootScope.$digest(); - expect(element.attr('disabled')).toBeFalsy(); - $rootScope.isDisabled = true; - $rootScope.$digest(); - expect(element.attr('disabled')).toBeTruthy(); - })); - - - it('should bind checked', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) - $rootScope.isChecked = false; - $rootScope.$digest(); - expect(element.attr('checked')).toBeFalsy(); - $rootScope.isChecked=true; - $rootScope.$digest(); - expect(element.attr('checked')).toBeTruthy(); - })); - - - it('should bind selected', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) - jqLite(document.body).append(element) - $rootScope.isSelected=false; - $rootScope.$digest(); - expect(element.children()[1].selected).toBeFalsy(); - $rootScope.isSelected=true; - $rootScope.$digest(); - expect(element.children()[1].selected).toBeTruthy(); - })); - - - it('should bind readonly', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) - $rootScope.isReadonly=false; - $rootScope.$digest(); - expect(element.attr('readOnly')).toBeFalsy(); - $rootScope.isReadonly=true; - $rootScope.$digest(); - expect(element.attr('readOnly')).toBeTruthy(); - })); - - - it('should bind multiple', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) - $rootScope.isMultiple=false; - $rootScope.$digest(); - expect(element.attr('multiple')).toBeFalsy(); - $rootScope.isMultiple='multiple'; - $rootScope.$digest(); - expect(element.attr('multiple')).toBeTruthy(); - })); - - - it('should bind src', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope) - $rootScope.url = 'http://localhost/'; - $rootScope.$digest(); - expect(element.attr('src')).toEqual('http://localhost/'); - })); - - - it('should bind href and merge with other attrs', inject(function($rootScope, $compile) { - element = $compile('')($rootScope); - $rootScope.url = 'http://server'; - $rootScope.rel = 'REL'; - $rootScope.$digest(); - expect(element.attr('href')).toEqual('http://server'); - expect(element.attr('rel')).toEqual('REL'); - })); -}); - - -describe('ng-src', function() { - - it('should interpolate the expression and bind to src', inject(function($compile, $rootScope) { - var element = $compile('
')($rootScope) - $rootScope.$digest(); - 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() { - - it('should interpolate the expression and bind to href', inject(function($compile, $rootScope) { - var element = $compile('
')($rootScope) - $rootScope.$digest(); - 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/ng/directive/booleanAttrsSpec.js b/test/ng/directive/booleanAttrsSpec.js new file mode 100644 index 00000000..d58ffced --- /dev/null +++ b/test/ng/directive/booleanAttrsSpec.js @@ -0,0 +1,144 @@ +'use strict'; + +describe('boolean attr directives', function() { + var element; + + afterEach(function() { + dealoc(element); + }); + + + it('should bind href', inject(function($rootScope, $compile) { + element = $compile('')($rootScope) + $rootScope.url = 'http://server'; + $rootScope.$digest(); + expect(element.attr('href')).toEqual('http://server'); + })); + + + it('should bind href even if no interpolation', inject(function($rootScope, $compile) { + element = $compile('')($rootScope) + $rootScope.$digest(); + expect(element.attr('href')).toEqual('http://server'); + })); + + + it('should properly evaluate 0 as false', inject(function($rootScope, $compile) { + // jQuery does not treat 0 as false, when setting attr() + element = $compile('')($rootScope) + $rootScope.isDisabled = 0; + $rootScope.$digest(); + expect(element.attr('disabled')).toBeFalsy(); + $rootScope.isDisabled = 1; + $rootScope.$digest(); + expect(element.attr('disabled')).toBeTruthy(); + })); + + + it('should bind disabled', inject(function($rootScope, $compile) { + element = $compile('')($rootScope) + $rootScope.isDisabled = false; + $rootScope.$digest(); + expect(element.attr('disabled')).toBeFalsy(); + $rootScope.isDisabled = true; + $rootScope.$digest(); + expect(element.attr('disabled')).toBeTruthy(); + })); + + + it('should bind checked', inject(function($rootScope, $compile) { + element = $compile('')($rootScope) + $rootScope.isChecked = false; + $rootScope.$digest(); + expect(element.attr('checked')).toBeFalsy(); + $rootScope.isChecked=true; + $rootScope.$digest(); + expect(element.attr('checked')).toBeTruthy(); + })); + + + it('should bind selected', inject(function($rootScope, $compile) { + element = $compile('')($rootScope) + jqLite(document.body).append(element) + $rootScope.isSelected=false; + $rootScope.$digest(); + expect(element.children()[1].selected).toBeFalsy(); + $rootScope.isSelected=true; + $rootScope.$digest(); + expect(element.children()[1].selected).toBeTruthy(); + })); + + + it('should bind readonly', inject(function($rootScope, $compile) { + element = $compile('')($rootScope) + $rootScope.isReadonly=false; + $rootScope.$digest(); + expect(element.attr('readOnly')).toBeFalsy(); + $rootScope.isReadonly=true; + $rootScope.$digest(); + expect(element.attr('readOnly')).toBeTruthy(); + })); + + + it('should bind multiple', inject(function($rootScope, $compile) { + element = $compile('')($rootScope) + $rootScope.isMultiple=false; + $rootScope.$digest(); + expect(element.attr('multiple')).toBeFalsy(); + $rootScope.isMultiple='multiple'; + $rootScope.$digest(); + expect(element.attr('multiple')).toBeTruthy(); + })); + + + it('should bind src', inject(function($rootScope, $compile) { + element = $compile('
')($rootScope) + $rootScope.url = 'http://localhost/'; + $rootScope.$digest(); + expect(element.attr('src')).toEqual('http://localhost/'); + })); + + + it('should bind href and merge with other attrs', inject(function($rootScope, $compile) { + element = $compile('')($rootScope); + $rootScope.url = 'http://server'; + $rootScope.rel = 'REL'; + $rootScope.$digest(); + expect(element.attr('href')).toEqual('http://server'); + expect(element.attr('rel')).toEqual('REL'); + })); +}); + + +describe('ng-src', function() { + + it('should interpolate the expression and bind to src', inject(function($compile, $rootScope) { + var element = $compile('
')($rootScope) + $rootScope.$digest(); + 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() { + + it('should interpolate the expression and bind to href', inject(function($compile, $rootScope) { + var element = $compile('
')($rootScope) + $rootScope.$digest(); + expect(element.attr('href')).toEqual('some/'); + + $rootScope.$apply(function() { + $rootScope.id = 1; + }); + expect(element.attr('href')).toEqual('some/1'); + + dealoc(element); + })); +}); -- cgit v1.2.3