Skip to content

Commit

Permalink
test: get tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed Jan 23, 2021
1 parent 9ce11e4 commit 68e83a8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Merges the enumerable properties of two or more objects deeply.

### Example Usage
<!--js
const merge = require('./')
const { deepmerge: merge, deepmergeAll: mergeAll } = require('./')
-->

```js
Expand Down Expand Up @@ -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.

Expand All @@ -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!' }
```


Expand Down
4 changes: 2 additions & 2 deletions test/custom-is-mergeable-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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, {
Expand Down
21 changes: 11 additions & 10 deletions test/merge-all.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
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()
})

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()
})

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions test/merge.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -507,7 +507,7 @@ test('should handle custom merge functions', function(t) {
}

const options = {
customMerge: (key, options) => {
customMerge: (key) => {
if (key === 'people') {
return mergePeople
}
Expand Down Expand Up @@ -555,7 +555,7 @@ test('should handle custom merge functions', function(t) {


const options = {
customMerge: (key, options) => {
customMerge: (key) => {
if (key === 'letters') {
return mergeLetters
}
Expand Down Expand Up @@ -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()

Expand All @@ -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()
})

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion test/prototype-poisoning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 68e83a8

Please sign in to comment.