From 2465a6bdbdb63aa1b83c99025be9c0612dacc15a Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 6 Jun 2016 23:46:06 -0700 Subject: [PATCH] Add `fp.mergeAllWith` test. --- fp/_mapping.js | 21 +++++++++++---------- test/test-fp.js | 49 ++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/fp/_mapping.js b/fp/_mapping.js index 4d5cecf79..521b8de20 100644 --- a/fp/_mapping.js +++ b/fp/_mapping.js @@ -88,16 +88,17 @@ exports.aryMethod = { 'groupBy', 'gt', 'gte', 'has', 'hasIn', 'includes', 'indexOf', 'intersection', 'invertBy', 'invoke', 'invokeMap', 'isEqual', 'isMatch', 'join', 'keyBy', 'lastIndexOf', 'lt', 'lte', 'map', 'mapKeys', 'mapValues', 'matchesProperty', - 'maxBy', 'meanBy', 'merge', 'minBy', 'multiply', 'nth', 'omit', 'omitBy', - 'overArgs', 'pad', 'padEnd', 'padStart', 'parseInt', 'partial', 'partialRight', - 'partition', 'pick', 'pickBy', 'pull', 'pullAll', 'pullAt', 'random', 'range', - 'rangeRight', 'rearg', 'reject', 'remove', 'repeat', 'restFrom', 'result', - 'sampleSize', 'some', 'sortBy', 'sortedIndex', 'sortedIndexOf', 'sortedLastIndex', - 'sortedLastIndexOf', 'sortedUniqBy', 'split', 'spreadFrom', 'startsWith', - 'subtract', 'sumBy', 'take', 'takeRight', 'takeRightWhile', 'takeWhile', 'tap', - 'throttle', 'thru', 'times', 'trimChars', 'trimCharsEnd', 'trimCharsStart', - 'truncate', 'union', 'uniqBy', 'uniqWith', 'unset', 'unzipWith', 'without', - 'wrap', 'xor', 'zip', 'zipObject', 'zipObjectDeep' + 'maxBy', 'meanBy', 'merge', 'mergeAllWith', 'minBy', 'multiply', 'nth', 'omit', + 'omitBy', 'overArgs', 'pad', 'padEnd', 'padStart', 'parseInt', 'partial', + 'partialRight', 'partition', 'pick', 'pickBy', 'pull', 'pullAll', 'pullAt', + 'random', 'range', 'rangeRight', 'rearg', 'reject', 'remove', 'repeat', + 'restFrom', 'result', 'sampleSize', 'some', 'sortBy', 'sortedIndex', + 'sortedIndexOf', 'sortedLastIndex', 'sortedLastIndexOf', 'sortedUniqBy', + 'split', 'spreadFrom', 'startsWith', 'subtract', 'sumBy', 'take', 'takeRight', + 'takeRightWhile', 'takeWhile', 'tap', 'throttle', 'thru', 'times', 'trimChars', + 'trimCharsEnd', 'trimCharsStart', 'truncate', 'union', 'uniqBy', 'uniqWith', + 'unset', 'unzipWith', 'without', 'wrap', 'xor', 'zip', 'zipObject', + 'zipObjectDeep' ], '3': [ 'assignInWith', 'assignWith', 'clamp', 'differenceBy', 'differenceWith', diff --git a/test/test-fp.js b/test/test-fp.js index 58e2221b1..20895bebb 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -1460,11 +1460,11 @@ var args, stack = { '__data__': { '__data__': [] } }, - expected = [[1], [2, 3], 'a', { 'a': [1] }, { 'a': [2, 3] }, stack]; + expected = [[1, 2], [3], 'a', { 'a': [1, 2] }, { 'a': [3] }, stack]; fp.mergeWith(function() { args || (args = _.map(arguments, _.cloneDeep)); - })({ 'a': [1] })({ 'a': [2, 3] }); + })({ 'a': [1, 2] })({ 'a': [3] }); args[5] = _.omitBy(args[5], _.isFunction); args[5].__data__ = _.omitBy(args[5].__data__, _.isFunction); @@ -1475,17 +1475,44 @@ QUnit.test('should not mutate values', function(assert) { assert.expect(2); - var object = { 'a': { 'b': 2, 'c': 3 } }; - object.a.b = [1]; + var objects = [{ 'a': [1, 2] }, { 'a': [3] }], + actual = fp.mergeWith(_.noop, objects[0], objects[1]); - var actual = fp.mergeWith(function(objValue, srcValue) { - if (_.isArray(objValue)) { - return objValue.concat(srcValue); - } - }, object, { 'a': { 'b': [2, 3] } }); + assert.deepEqual(objects[0], { 'a': [1, 2] }); + assert.deepEqual(actual, { 'a': [3, 2] }); + }); + }()); - assert.deepEqual(object, { 'a': { 'b': [1], 'c': 3 } }); - assert.deepEqual(actual, { 'a': { 'b': [1, 2, 3], 'c': 3 } }); + /*--------------------------------------------------------------------------*/ + + QUnit.module('fp.mergeAllWith'); + + (function() { + QUnit.test('should provide the correct `customizer` arguments', function(assert) { + assert.expect(1); + + var args, + stack = { '__data__': { '__data__': [] } }, + expected = [[1, 2], [3], 'a', { 'a': [1, 2] }, { 'a': [3] }, stack]; + + fp.mergeAllWith(function() { + args || (args = _.map(arguments, _.cloneDeep)); + })([{ 'a': [1, 2] }, { 'a': [3] }]); + + args[5] = _.omitBy(args[5], _.isFunction); + args[5].__data__ = _.omitBy(args[5].__data__, _.isFunction); + + assert.deepEqual(args, expected); + }); + + QUnit.test('should not mutate values', function(assert) { + assert.expect(2); + + var objects = [{ 'a': [1, 2] }, { 'a': [3] }], + actual = fp.mergeAllWith(_.noop, objects); + + assert.deepEqual(objects[0], { 'a': [1, 2] }); + assert.deepEqual(actual, { 'a': [3, 2] }); }); }());