mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-06-16 18:29:57 +08:00
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
This commit is contained in:
committed by
Igor Minar
parent
785a5fd7c1
commit
2dbb6f9a54
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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]);
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user