Permalink
Browse files

_.isEqual correctly checks for DOM elements.

  • Loading branch information...
1 parent a843d1a commit d34a223360a95166a6eec53ce0ac3d0ac5b02375 @rudasn committed Jan 17, 2013
Showing with 21 additions and 0 deletions.
  1. +17 −0 test/objects.js
  2. +4 −0 underscore.js
View
@@ -358,6 +358,23 @@ $(document).ready(function() {
// Objects from another frame.
ok(_.isEqual({}, iObject));
+
+ // DOM elements
+ var aDom = document.createElement('div'),
+ bDom = document.createElement('span'),
+ $aDom = $(aDom),
+ $bDom = $(bDom),
+ $allDoms = $aDom.add($bDom);
+
+ ok(!_.isEqual(aDom, bDom), 'DOM Elements are not always equal.');
+
+ ok(!_.isEqual($aDom, $bDom), 'jQuery DOM Elements are not always equal.');
+
+ ok(_.isEqual(aDom, aDom), 'Same DOM Elements are equal.');
+
+ ok(_.isEqual($aDom, $aDom), 'Same jQuery DOM Elements are equal.');
+
+ ok(_.isEqual($allDoms, $allDoms), 'Same jQuery Elements are equal.');
});
test("isEmpty", function() {
View
@@ -828,6 +828,10 @@
// Unwrap any wrapped objects.
if (a instanceof _) a = a._wrapped;
if (b instanceof _) b = b._wrapped;
+ // Compare DOM elements.
+ if (a && a.nodeName || b && b.nodeName) {
+ return a === b;
+ }
// Compare `[[Class]]` names.
var className = toString.call(a);
if (className != toString.call(b)) return false;

0 comments on commit d34a223

Please sign in to comment.