Ensure _.merge applies a given callback to nested properties. [closes #227]

Former-commit-id: 1a58c178e0ecb9c50512f221b4aed82762709066
This commit is contained in:
John-David Dalton
2013-04-01 23:49:35 -07:00
parent 6c25905ae4
commit b0d942d0ec
2 changed files with 14 additions and 4 deletions

View File

@@ -1801,8 +1801,15 @@
});
test('should handle merging if `callback` returns `undefined`', function() {
var actual = _.merge({ 'a': 1 }, { 'a': 2 }, function() { });
deepEqual(actual, { 'a': 2 });
var actual = _.merge({ 'a': { 'b': [1, 1] } }, { 'a': { 'b': [0] } }, function() { });
deepEqual(actual, { 'a': { 'b': [0, 1] } });
});
test('should defer to `callback` when it returns a value other than `undefined`', function() {
var actual = _.merge({ 'a': { 'b': [0, 1] } }, { 'a': { 'b': [2] } }, function(a, b) {
return _.isArray(a) ? a.concat(b) : undefined;
});
deepEqual(actual, { 'a': { 'b': [0, 1, 2] } });
});
}(1, 2, 3));