diff --git a/test/merge-all.ts b/test/merge-all.ts index 4d0405b..99b4821 100644 --- a/test/merge-all.ts +++ b/test/merge-all.ts @@ -60,7 +60,7 @@ test(`invoke merge on every item in array with clone should clone all elements`, t.end() }) -test(`invoke merge on every item in array clone=false should not clone all elements`, (t) => { +test(`invoke merge on every item in array with clone=false should not clone all elements`, (t) => { const firstObject = { a: { d: 123 } } const secondObject = { b: { e: true } } const thirdObject = { c: { f: `string` } } @@ -74,13 +74,12 @@ test(`invoke merge on every item in array clone=false should not clone all eleme t.end() }) - -test(`invoke merge on every item in array without clone should clone all elements`, (t) => { +test(`invoke merge on every item in array with clone=true should clone all elements`, (t) => { const firstObject = { a: { d: 123 } } const secondObject = { b: { e: true } } const thirdObject = { c: { f: `string` } } - const mergedWithoutClone = mergeAll([ firstObject, secondObject, thirdObject ]) + const mergedWithoutClone = mergeAll([ firstObject, secondObject, thirdObject ], { clone: true }) t.notEqual(mergedWithoutClone.a, firstObject.a) t.notEqual(mergedWithoutClone.b, secondObject.b) diff --git a/test/merge-plain-objects.ts b/test/merge-plain-objects.ts index c1c4964..0efd771 100644 --- a/test/merge-plain-objects.ts +++ b/test/merge-plain-objects.ts @@ -6,12 +6,12 @@ test(`plain objects are merged by default`, (t) => { newObject: new Object(), objectLiteral: { a: 123 }, } - const output = merge({}, input) + const output = merge({}, input, { clone: false }) t.deepEqual(output.newObject, input.newObject) - t.notEqual(output.newObject, input.newObject) + t.equal(output.newObject, input.newObject) t.deepEqual(output.objectLiteral, input.objectLiteral) - t.notEqual(output.objectLiteral, input.objectLiteral) + t.equal(output.objectLiteral, input.objectLiteral) t.end() }) diff --git a/test/merge.ts b/test/merge.ts index 50b1d5e..3b1bd36 100644 --- a/test/merge.ts +++ b/test/merge.ts @@ -80,8 +80,8 @@ test(`replace simple key with nested object in target`, (t) => { key2: `value2`, } - t.deepEqual(target, { key1: `value1`, key2: `value2` }) - t.deepEqual(merge(target, src), expected) + t.deepEqual(merge(target, src, { clone: true }), expected) + t.deepEqual(merge(target, src, { clone: false }), expected) t.end() }) @@ -139,7 +139,7 @@ test(`should clone source and target`, (t) => { t.end() }) -test(`should clone source and target`, (t) => { +test(`should clone source and target if specified`, (t) => { const src = { b: { c: `foo`, @@ -152,7 +152,7 @@ test(`should clone source and target`, (t) => { }, } - const merged = merge(target, src) + const merged = merge(target, src, { clone: true }) t.notEqual(merged.a, target.a) t.notEqual(merged.b, src.b) diff --git a/test/prototype-poisoning.ts b/test/prototype-poisoning.ts index 95f580e..cd1379c 100644 --- a/test/prototype-poisoning.ts +++ b/test/prototype-poisoning.ts @@ -29,7 +29,7 @@ test(`merging objects with plain and non-plain properties`, (t) => { [plainSymbolKey]: `qux`, } - const mergedObject = merge(target, source) + const mergedObject = merge(target, source, { clone: true }) t.equal(undefined, mergedObject.parentKey, `inherited properties of target should be removed, not merged or ignored`) t.equal(`bar`, mergedObject.plainKey, `enumerable own properties of target should be merged`) t.equal(`baz`, mergedObject.newKey, `properties not yet on target should be merged`) @@ -73,6 +73,6 @@ test(`merging objects with null prototype`, (t) => { }, } - t.deepEqual(expected, merge(target, source)) + t.deepEqual(merge(target, source, { clone: true }), expected) t.end() })