Add _.merge. tests.

This commit is contained in:
jdalton
2015-02-19 00:14:59 -08:00
parent 10ee74d872
commit 89ed40e4a4
2 changed files with 32 additions and 1 deletions

View File

@@ -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));

View File

@@ -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] } });