-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get is-plain-object example test passing
- Loading branch information
Showing
3 changed files
with
64 additions
and
52 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) |