Skip to content

Commit

Permalink
Get is-plain-object example test passing
Browse files Browse the repository at this point in the history
  • Loading branch information
TehShrike committed Mar 16, 2023
1 parent 317ce0e commit 65f2b06
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 52 deletions.
39 changes: 8 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"@types/node": "^8.10.54",
"is-mergeable-object": "1.1.0",
"is-plain-object": "^2.0.4",
"is-plain-object": "^5.0.0",
"jsmd": "^1.0.2",
"rollup": "^1.23.1",
"rollup-plugin-commonjs": "^10.1.0",
Expand All @@ -38,6 +38,5 @@
"typescript": "=2.2.2",
"uglify-js": "^3.6.1"
},
"license": "MIT",
"dependencies": {}
"license": "MIT"
}
72 changes: 54 additions & 18 deletions test/custom-is-mergeable-object.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,72 @@
var merge = require('../')
var test = require('tape')
const merge = require(`..`)
const test = require(`tape`)

test('isMergeableObject function copying object over object', function(t) {
var src = { key: { isMergeable: false }, baz: 'yes' }
var target = { key: { foo: 'wat' }, baz: 'whatever' }
test(`isMergeableObject function copying object over object`, t => {
const src = { key: { isMergeable: false }, baz: `yes` }
const target = { key: { foo: `wat` }, baz: `whatever` }

function isMergeableObject(object) {
return object && typeof value === 'object' && object.isMergeable !== false
return object && typeof value === `object` && object.isMergeable !== false
}

var res = merge(target, src, {
isMergeableObject: isMergeableObject
const res = merge(target, src, {
isMergeableObject,
})

t.deepEqual(res, { key: { isMergeable: false }, baz: 'yes' })
t.equal(res.key, src.key, 'Object has the same identity and was not cloned')
t.deepEqual(res, { key: { isMergeable: false }, baz: `yes` })
t.equal(res.key, src.key, `Object has the same identity and was not cloned`)
t.end()
})

test('isMergeableObject function copying object over nothing', function(t) {
var src = { key: { isMergeable: false, foo: 'bar' }, baz: 'yes' }
var target = { baz: 'whatever' }
test(`isMergeableObject function copying object over nothing`, t => {
const src = { key: { isMergeable: false, foo: `bar` }, baz: `yes` }
const target = { baz: `whatever` }

function isMergeableObject(object) {
return object && typeof value === 'object' && object.isMergeable !== false
return object && typeof value === `object` && object.isMergeable !== false
}

var res = merge(target, src, {
isMergeableObject: isMergeableObject
const res = merge(target, src, {
isMergeableObject,
})

t.deepEqual(res, { key: { isMergeable: false, foo: 'bar' }, baz: 'yes' })
t.equal(res.key, src.key, 'Object has the same identity and was not cloned')
t.deepEqual(res, { key: { isMergeable: false, foo: `bar` }, baz: `yes` })
t.equal(res.key, src.key, `Object has the same identity and was not cloned`)
t.end()
})

test(`example from readme`, t => {
const { isPlainObject } = require(`is-plain-object`)

function SuperSpecial() {
this.special = `oh yeah man totally`
}

const instantiatedSpecialObject = new SuperSpecial()

const target = {
someProperty: {
cool: `oh for sure`,
},
}

const source = {
someProperty: instantiatedSpecialObject,
}

const defaultOutput = merge(target, source)

t.equal(defaultOutput.someProperty.cool, `oh for sure`)
t.equal(defaultOutput.someProperty.special, `oh yeah man totally`)
t.equal(defaultOutput.someProperty instanceof SuperSpecial, false)

const customMergeOutput = merge(target, source, {
isMergeableObject: isPlainObject,
})

t.equal(customMergeOutput.someProperty.cool, undefined)
t.equal(customMergeOutput.someProperty.special, `oh yeah man totally`)
t.equal(customMergeOutput.someProperty instanceof SuperSpecial, true)

t.end()
})

0 comments on commit 65f2b06

Please sign in to comment.