-
Notifications
You must be signed in to change notification settings - Fork 89
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
Deyan Totev
committed
Feb 1, 2024
1 parent
0276cac
commit ee4b09b
Showing
9 changed files
with
111 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,30 +1,36 @@ | ||
import { mergeDeepLeft } from './mergeDeepLeft' | ||
import { mergeDeepLeft as mergeDeepLeftRamda } from 'ramda' | ||
import { mergeDeepLeft } from './mergeDeepLeft'; | ||
|
||
it('takes two objects, recursively merges their own properties and returns a new object', function () { | ||
var a = {w: 1, x: 2, y: {z: 3}} | ||
var b = {a: 4, b: 5, c: {d: 6}} | ||
expect(mergeDeepLeft(a, b)).toEqual({w: 1, x: 2, y: {z: 3}, a: 4, b: 5, c: {d: 6}}) | ||
}) | ||
it('takes two objects, recursively merges their own properties and returns a new object', () => { | ||
const a = { w: 1, x: 2, y: { z: 3 } }; | ||
const b = { a: 4, b: 5, c: { d: 6 } }; | ||
expect(mergeDeepLeft(a, b)).toEqual({ | ||
w: 1, | ||
x: 2, | ||
y: { z: 3 }, | ||
a: 4, | ||
b: 5, | ||
c: { d: 6 }, | ||
}); | ||
}); | ||
|
||
it('overrides properties in the second object with properties in the first object', function () { | ||
var a = {a: {b: 1, c: 2}, y: 0} | ||
var b = {a: {b: 3, d: 4}, z: 0} | ||
expect(mergeDeepLeft(a, b)).toEqual({a: {b: 1, c: 2, d: 4}, y: 0, z: 0}) | ||
}) | ||
it('overrides properties in the second object with properties in the first object', () => { | ||
const a = { a: { b: 1, c: 2 }, y: 0 }; | ||
const b = { a: { b: 3, d: 4 }, z: 0 }; | ||
expect(mergeDeepLeft(a, b)).toEqual({ a: { b: 1, c: 2, d: 4 }, y: 0, z: 0 }); | ||
}); | ||
|
||
it('is not destructive', function () { | ||
var a = {w: 1, x: {y: 2}} | ||
var res = mergeDeepLeft(a, {x: {y: 3}}) | ||
expect(a).not.toBe(res) | ||
expect(a.x).not.toBe(res.x) | ||
expect(res).toEqual({w: 1, x: {y: 2}}) | ||
}) | ||
it('is not destructive', () => { | ||
const a = { w: 1, x: { y: 2 } }; | ||
const res = mergeDeepLeft(a, { x: { y: 3 } }); | ||
expect(a).not.toBe(res); | ||
expect(a.x).not.toBe(res.x); | ||
expect(res).toEqual({ w: 1, x: { y: 2 } }); | ||
}); | ||
|
||
it('reports only own properties', function () { | ||
var a = {w: 1, x: {y: 2}} | ||
function Cla() {} | ||
Cla.prototype.y = 5 | ||
expect(mergeDeepLeft({x: new Cla()}, a)).toEqual({w: 1, x: {y: 2}}) | ||
expect(mergeDeepLeft(a, {x: new Cla()})).toEqual({w: 1, x: {y: 2}}) | ||
}) | ||
it('reports only own properties', () => { | ||
const a = { w: 1, x: { y: 2 } }; | ||
function Cla() {} | ||
Cla.prototype.y = 5; | ||
expect(mergeDeepLeft({ x: new Cla() }, a)).toEqual({ w: 1, x: { y: 2 } }); | ||
expect(mergeDeepLeft(a, { x: new Cla() })).toEqual({ w: 1, x: { y: 2 } }); | ||
}); |
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