mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
Add _.merge. tests.
This commit is contained in:
@@ -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));
|
||||
|
||||
31
test/test.js
31
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] } });
|
||||
|
||||
Reference in New Issue
Block a user