From 89ed40e4a4f76c86fcd99be9a5deac020af15407 Mon Sep 17 00:00:00 2001 From: jdalton Date: Thu, 19 Feb 2015 00:14:59 -0800 Subject: [PATCH] Add `_.merge`. tests. --- lodash.src.js | 2 +- test/test.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lodash.src.js b/lodash.src.js index 18eac6170..5f1c095c2 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -2548,7 +2548,7 @@ * @returns {Object} Returns the destination object. */ function baseMerge(object, source, customizer, stackA, stackB) { - if (!isObjectLike(object)) { + if (!isObject(object)) { return object; } var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source)); diff --git a/test/test.js b/test/test.js index 4e0a1397d..805e6307c 100644 --- a/test/test.js +++ b/test/test.js @@ -9791,6 +9791,37 @@ deepEqual(actual, expected); }); + test('should work with a function `object` value', 2, function() { + function Foo() {} + + var source = { 'a': 1 }, + actual = _.merge(Foo, source); + + strictEqual(actual, Foo); + strictEqual(Foo.a, 1); + }); + + test('should work with a non-plain `object` value', 2, function() { + function Foo() {} + + var object = new Foo, + source = { 'a': 1 }, + actual = _.merge(object, source); + + strictEqual(actual, object); + strictEqual(object.a, 1); + }); + + test('should pass thru primitive `object` values', 1, function() { + var values = [true, 1, '1']; + + var actual = _.map(values, function(value) { + return _.merge(value, { 'a': 1 }); + }); + + deepEqual(actual, values); + }); + test('should handle merging if `customizer` returns `undefined`', 2, function() { var actual = _.merge({ 'a': { 'b': [1, 1] } }, { 'a': { 'b': [0] } }, _.noop); deepEqual(actual, { 'a': { 'b': [0, 1] } });