Skip to content

Commit aefee74

Browse files
author
Caitlin Potter
committed
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
1 parent 08f376f commit aefee74

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
@@ -478,9 +478,9 @@ var trim = (function() {
478478
* @returns {boolean} True if `value` is a DOM element (or wrapped jQuery element).
479479
*/
480480
function isElement(node) {
481-
return node &&
481+
return !!(node &&
482482
(node.nodeName // we are a direct element
483-
|| (node.on && node.find)); // we have an on and find method part of jQuery API
483+
|| (node.on && node.find))); // we have an on and find method part of jQuery API
484484
}
485485

486486
/**

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)