mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-13 04:17:49 +00:00
Fix _.isEquals() for wrapped objects
This caught me out when writing some unit tests that use _.isEquals(). They were all passing even though I knew they shouldn't be, and I realised I was checking equality with a wrapped object that I'd forgotten to unwrap.
This commit is contained in:
@@ -51,7 +51,9 @@ $(document).ready(function() {
|
|||||||
ok(_.isEqual(new Date(100), new Date(100)), 'identical dates are equal');
|
ok(_.isEqual(new Date(100), new Date(100)), 'identical dates are equal');
|
||||||
ok(_.isEqual((/hello/ig), (/hello/ig)), 'identical regexes are equal');
|
ok(_.isEqual((/hello/ig), (/hello/ig)), 'identical regexes are equal');
|
||||||
ok(!_.isEqual(null, [1]), 'a falsy is never equal to a truthy');
|
ok(!_.isEqual(null, [1]), 'a falsy is never equal to a truthy');
|
||||||
ok(!_.isEqual({x: 1, y: undefined}, {x: 1, z: 2}), 'object with the same number of undefined keys are not equal');
|
ok(!_.isEqual({x: 1, y: undefined}, {x: 1, z: 2}), 'objects with the same number of undefined keys are not equal');
|
||||||
|
ok(!_.isEqual(_({x: 1, y: undefined}).chain(), _({x: 1, z: 2}).chain()), 'wrapped objects are not equal');
|
||||||
|
equals(_({x: 1, y: 2}).chain().isEqual(_({x: 1, y: 2}).chain()).value(), true, 'wrapped objects are equal');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("objects: isEmpty", function() {
|
test("objects: isEmpty", function() {
|
||||||
|
|||||||
@@ -519,6 +519,9 @@
|
|||||||
|
|
||||||
// Perform a deep comparison to check if two objects are equal.
|
// Perform a deep comparison to check if two objects are equal.
|
||||||
_.isEqual = function(a, b) {
|
_.isEqual = function(a, b) {
|
||||||
|
// Unwrap any wrapped objects
|
||||||
|
if (a && a._chain) a = a.value();
|
||||||
|
if (b && b._chain) b = b.value();
|
||||||
// Check object identity.
|
// Check object identity.
|
||||||
if (a === b) return true;
|
if (a === b) return true;
|
||||||
// Different types?
|
// Different types?
|
||||||
|
|||||||
Reference in New Issue
Block a user