From 68e83a87f12f36c68db6cde5b6b5a4aef4f809de Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Sat, 23 Jan 2021 21:46:49 +1300 Subject: [PATCH] test: get tests working --- readme.md | 6 +++--- test/custom-is-mergeable-object.ts | 4 ++-- test/merge-all.ts | 21 +++++++++++---------- test/merge.ts | 14 +++++++------- test/prototype-poisoning.ts | 2 +- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/readme.md b/readme.md index c315fca..3375fb9 100644 --- a/readme.md +++ b/readme.md @@ -10,7 +10,7 @@ Merges the enumerable properties of two or more objects deeply. ### Example Usage ```js @@ -90,7 +90,7 @@ Merging creates a new object, so that neither `x` or `y` is modified. **Note:** By default, arrays are merged by concatenating them. -## `merge.all(arrayOfObjects, [options])` +## `mergeAll(arrayOfObjects, [options])` Merges any number of objects into a single result object. @@ -99,7 +99,7 @@ const foobar = { foo: { bar: 3 } } const foobaz = { foo: { baz: 4 } } const bar = { bar: 'yay!' } -merge.all([ foobar, foobaz, bar ]) // => { foo: { bar: 3, baz: 4 }, bar: 'yay!' } +mergeAll([ foobar, foobaz, bar ]) // => { foo: { bar: 3, baz: 4 }, bar: 'yay!' } ``` diff --git a/test/custom-is-mergeable-object.ts b/test/custom-is-mergeable-object.ts index b84edba..76903e0 100644 --- a/test/custom-is-mergeable-object.ts +++ b/test/custom-is-mergeable-object.ts @@ -6,7 +6,7 @@ test('isMergeable function copying object over object', function(t) { var target = { key: { foo: 'wat' }, baz: 'whatever' } function customIsMergeable(object) { - return object && typeof value === 'object' && object.isMergeable !== false + return object && typeof object === 'object' && object.isMergeable !== false } var res = merge(target, src, { @@ -23,7 +23,7 @@ test('isMergeable function copying object over nothing', function(t) { var target = { baz: 'whatever' } function customIsMergeable(object) { - return object && typeof value === 'object' && object.isMergeable !== false + return object && typeof object === 'object' && object.isMergeable !== false } var res = merge(target, src, { diff --git a/test/merge-all.ts b/test/merge-all.ts index 4177404..dc392b2 100644 --- a/test/merge-all.ts +++ b/test/merge-all.ts @@ -1,18 +1,19 @@ -import { deepmerge as merge } from "deepmerge" +import { deepmergeAll as mergeAll } from "deepmerge" import test from "tape" test('throw error if first argument is not an array', function(t) { - t.throws(merge.all.bind(null, { example: true }, { another: '2' }), Error) + // @ts-expect-error + t.throws(mergeAll.bind(null, { example: true }, { another: '2' }), Error) t.end() }) test('return an empty object if first argument is an array with no elements', function(t) { - t.deepEqual(merge.all([]), {}) + t.deepEqual(mergeAll([]), {}) t.end() }) test('Work just fine if first argument is an array with least than two elements', function(t) { - var actual = merge.all([{ example: true }]) + var actual = mergeAll([{ example: true }]) var expected = { example: true } t.deepEqual(actual, expected) t.end() @@ -20,13 +21,13 @@ test('Work just fine if first argument is an array with least than two elements' test('execute correctly if options object were not passed', function(t) { var arrayToMerge = [{ example: true }, { another: '123' }] - t.doesNotThrow(merge.all.bind(null, arrayToMerge)) + t.doesNotThrow(mergeAll.bind(null, arrayToMerge)) t.end() }) test('execute correctly if options object were passed', function(t) { var arrayToMerge = [{ example: true }, { another: '123' }] - t.doesNotThrow(merge.all.bind(null, arrayToMerge, { clone: true })) + t.doesNotThrow(mergeAll.bind(null, arrayToMerge, { clone: true })) t.end() }) @@ -36,7 +37,7 @@ test('invoke merge on every item in array should result with all props', functio var thirdObject = { third: 123 } var fourthObject = { fourth: 'some string' } - var mergedObject = merge.all([ firstObject, secondObject, thirdObject, fourthObject ]) + var mergedObject = mergeAll([ firstObject, secondObject, thirdObject, fourthObject ]) t.ok(mergedObject.first === true) t.ok(mergedObject.second === false) @@ -50,7 +51,7 @@ test('invoke merge on every item in array with clone should clone all elements', var secondObject = { b: { e: true } } var thirdObject = { c: { f: 'string' } } - var mergedWithClone = merge.all([ firstObject, secondObject, thirdObject ], { clone: true }) + var mergedWithClone = mergeAll([ firstObject, secondObject, thirdObject ], { clone: true }) t.notEqual(mergedWithClone.a, firstObject.a) t.notEqual(mergedWithClone.b, secondObject.b) @@ -64,7 +65,7 @@ test('invoke merge on every item in array clone=false should not clone all eleme var secondObject = { b: { e: true } } var thirdObject = { c: { f: 'string' } } - var mergedWithoutClone = merge.all([ firstObject, secondObject, thirdObject ], { clone: false }) + var mergedWithoutClone = mergeAll([ firstObject, secondObject, thirdObject ], { clone: false }) t.equal(mergedWithoutClone.a, firstObject.a) t.equal(mergedWithoutClone.b, secondObject.b) @@ -79,7 +80,7 @@ test('invoke merge on every item in array without clone should clone all element var secondObject = { b: { e: true } } var thirdObject = { c: { f: 'string' } } - var mergedWithoutClone = merge.all([ firstObject, secondObject, thirdObject ]) + var mergedWithoutClone = mergeAll([ firstObject, secondObject, thirdObject ]) t.notEqual(mergedWithoutClone.a, firstObject.a) t.notEqual(mergedWithoutClone.b, secondObject.b) diff --git a/test/merge.ts b/test/merge.ts index e4470c4..e46b9a5 100644 --- a/test/merge.ts +++ b/test/merge.ts @@ -1,4 +1,4 @@ -import { deepmerge as merge } from "deepmerge" +import { deepmerge as merge, deepmergeAll as mergeAll } from "deepmerge" import test from "tape" test('add keys in target that do not exist at the root', function(t) { @@ -339,7 +339,7 @@ test('should work on array of objects with clone option', function(t) { t.ok(Array.isArray(merge(target, src)[0].key1), 'subkey should be an array too') t.notEqual(merged[0].key1, src[0].key1) t.notEqual(merged[0].key1, target[0].key1) - t.notEqual(merged[0].key2, src[0].key2) + t.false(Object.prototype.hasOwnProperty.call(merged[0], 'key2'), '"key2" should not exist on "merged[0]"'); t.notEqual(merged[1].key3, src[1].key3) t.notEqual(merged[1].key3, target[1].key3) t.end() @@ -507,7 +507,7 @@ test('should handle custom merge functions', function(t) { } const options = { - customMerge: (key, options) => { + customMerge: (key) => { if (key === 'people') { return mergePeople } @@ -555,7 +555,7 @@ test('should handle custom merge functions', function(t) { const options = { - customMerge: (key, options) => { + customMerge: (key) => { if (key === 'letters') { return mergeLetters } @@ -609,7 +609,7 @@ test('should merge correctly if custom merge is not a valid function', function( } } - var actual = merge(target, source, options) + var actual = merge(target, source) t.deepEqual(actual, expected) t.end() @@ -634,7 +634,7 @@ test('copy symbol keys in target that do exist on the target', function(t) { var res = merge(target, src) - t.equal(res[mySymbol], 'value1') + t.equal(res[mySymbol as unknown as string], 'value1') t.end() }) @@ -698,7 +698,7 @@ test('With clone: false, merge should not clone the target root', t => { test('With clone: false, merge.all should not clone the target root', t => { const destination = {} - const output = merge.all([ + const output = mergeAll([ destination, { sup: true } diff --git a/test/prototype-poisoning.ts b/test/prototype-poisoning.ts index 94f42c0..48308fc 100644 --- a/test/prototype-poisoning.ts +++ b/test/prototype-poisoning.ts @@ -40,7 +40,7 @@ test('merging objects with plain and non-plain properties', function(t) { test('merging strings works with a custom string merge', function(t) { var target = { name: "Alexander" } var source = { name: "Hamilton" } - function customMerge(key, options) { + function customMerge(key) { if (key === 'name') { return function(target, source, options) { return target[0] + '. ' + source.substring(0, 3)