diff options
| author | Caitlin Potter | 2013-10-19 15:41:06 -0400 |
|---|---|---|
| committer | Igor Minar | 2013-12-05 17:14:05 -0800 |
| commit | 2dbb6f9a54eb5ff5847eed11c85ac4cf119eb41c (patch) | |
| tree | a75288d7f421c25d411ad392d504a18c68c2af23 | |
| parent | 785a5fd7c182f39f4ae80d603c0098bc63ce41a4 (diff) | |
| download | angular.js-2dbb6f9a54eb5ff5847eed11c85ac4cf119eb41c.tar.bz2 | |
fix(isElement): return boolean value rather than `truthy` value.
angular.isElement currently returns a truthy object/function, or false. This
patch aims to correct this behaviour by casting the result of the isElement
expression to a boolean value via double-negation.
Closes #4519
Closes #4534
| -rw-r--r-- | src/Angular.js | 4 | ||||
| -rw-r--r-- | test/AngularSpec.js | 13 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/Angular.js b/src/Angular.js index 691ddbc6..478ef2a2 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -565,9 +565,9 @@ var trim = (function() { * @returns {boolean} True if `value` is a DOM element (or wrapped jQuery element). */ function isElement(node) { - return node && + return !!(node && (node.nodeName // we are a direct element - || (node.on && node.find)); // we have an on and find method part of jQuery API + || (node.on && node.find))); // we have an on and find method part of jQuery API } /** diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 1b08a18e..36d4926e 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -1079,4 +1079,17 @@ describe('angular', function() { } }); + describe('isElement', function() { + it('should return a boolean value', inject(function($compile, $document, $rootScope) { + var element = $compile('<p>Hello, world!</p>')($rootScope), + body = $document.find('body')[0], + expected = [false, false, false, false, false, false, false, true, true], + tests = [null, undefined, "string", 1001, {}, 0, false, body, element]; + angular.forEach(tests, function(value, idx) { + var result = angular.isElement(value); + expect(typeof result).toEqual('boolean'); + expect(result).toEqual(expected[idx]); + }); + })); + }); }); |
