-
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.
- Loading branch information
1 parent
0933e04
commit fb69b46
Showing
6 changed files
with
473 additions
and
483 deletions.
There are no files selected for viewing
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,35 @@ | ||
import type { Options } from "deepmerge" | ||
import { deepmerge as merge } from "deepmerge" | ||
import test from "tape" | ||
|
||
test('isMergeable function copying object over object', function(t) { | ||
var src = { key: { isMergeable: false }, baz: 'yes' } | ||
var target = { key: { foo: 'wat' }, baz: 'whatever' } | ||
test(`isMergeable function copying object over object`, (t) => { | ||
const src = { key: { isMergeable: false }, baz: `yes` } | ||
const target = { key: { foo: `wat` }, baz: `whatever` } | ||
|
||
function customIsMergeable(object) { | ||
return object && typeof object === 'object' && object.isMergeable !== false | ||
} | ||
const customIsMergeable: Options[`isMergeable`] = (object) => | ||
object && typeof object === `object` && object.isMergeable !== false | ||
|
||
var res = merge(target, src, { | ||
isMergeable: customIsMergeable | ||
const res = merge(target, src, { | ||
isMergeable: customIsMergeable, | ||
}) | ||
|
||
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('isMergeable function copying object over nothing', function(t) { | ||
var src = { key: { isMergeable: false, foo: 'bar' }, baz: 'yes' } | ||
var target = { baz: 'whatever' } | ||
test(`isMergeable function copying object over nothing`, (t) => { | ||
const src = { key: { isMergeable: false, foo: `bar` }, baz: `yes` } | ||
const target = { baz: `whatever` } | ||
|
||
function customIsMergeable(object) { | ||
return object && typeof object === 'object' && object.isMergeable !== false | ||
} | ||
const customIsMergeable: Options[`isMergeable`] = (object) => | ||
object && typeof object === `object` && object.isMergeable !== false | ||
|
||
var res = merge(target, src, { | ||
isMergeable: customIsMergeable | ||
const res = merge(target, src, { | ||
isMergeable: customIsMergeable, | ||
}) | ||
|
||
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() | ||
}) |
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
Oops, something went wrong.