Skip to content

Commit 34ba384

Browse files
Caitlin Potterjamesdaily
Caitlin Potter
authored andcommitted
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 angular#4519 Closes angular#4534
1 parent e89ff76 commit 34ba384

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Angular.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,9 @@ var trim = (function() {
565565
* @returns {boolean} True if `value` is a DOM element (or wrapped jQuery element).
566566
*/
567567
function isElement(node) {
568-
return node &&
568+
return !!(node &&
569569
(node.nodeName // we are a direct element
570-
|| (node.on && node.find)); // we have an on and find method part of jQuery API
570+
|| (node.on && node.find))); // we have an on and find method part of jQuery API
571571
}
572572

573573
/**

test/AngularSpec.js

+13
Original file line numberDiff line numberDiff line change
@@ -1079,4 +1079,17 @@ describe('angular', function() {
10791079
}
10801080
});
10811081

1082+
describe('isElement', function() {
1083+
it('should return a boolean value', inject(function($compile, $document, $rootScope) {
1084+
var element = $compile('<p>Hello, world!</p>')($rootScope),
1085+
body = $document.find('body')[0],
1086+
expected = [false, false, false, false, false, false, false, true, true],
1087+
tests = [null, undefined, "string", 1001, {}, 0, false, body, element];
1088+
angular.forEach(tests, function(value, idx) {
1089+
var result = angular.isElement(value);
1090+
expect(typeof result).toEqual('boolean');
1091+
expect(result).toEqual(expected[idx]);
1092+
});
1093+
}));
1094+
});
10821095
});

0 commit comments

Comments
 (0)