siegel
Version:
Web application development ecosystem
1 lines • 1.31 kB
JavaScript
import"../../../global.d";import e,{resolveAsUndefSymbol as t}from"./index.js";describe("common/deep/merge",()=>{test("simple",()=>{expect(e({a:20,b:"qwerty",c:{ca:30}},{b:"some_str",d:30,c:{cb:40},e:{ea:40}})).toEqual({a:20,b:"some_str",c:{ca:30,cb:40},d:30,e:{ea:40}})}),test("with weird objects",()=>{expect(e({c:{ca:[1,2,{a:1}]}},{c:{ca:[2,[],{b:1}],cb:new Set([1,2])}})).toEqual({c:{ca:[2,[],{b:1}],cb:new Set([1,2])}})}),test("with resolveObject",()=>{expect(e({a:{__aa:"some_string-__aa",b:20},b:{$$qwerty:"some_string-$$qwerty",c:60},c:{d:[1,2,3]}},{a:{__aa:"another_string",b:20},b:{$$qwerty:"another_string",c:60},c:{ca:!1}},{resolveObject:(e,a)=>e.__aa&&a.__aa?a:e.$$qwerty&&a.$$qwerty?t:void 0})).toEqual({a:{__aa:"another_string",b:20},b:void 0,c:{d:[1,2,3],ca:!1}})}),test("with mergeResolve",()=>{let t=new Date,a=new Date;a.setSeconds(a.getSeconds()+1),expect(e({a:new Set([1,2]),b:t,c:{ca:[1,2,{a:1}]},d:20},{a:new Set([3,4]),b:a,c:{ca:[2,[],{b:1}]},d:void 0,e:void 0},{skipUndef:!0,mergeResolve:(e,t)=>e.constructor==Set&&t.constructor==Set?new Set(Array.from(e).concat(Array.from(t))):e.constructor==Array&&t.constructor==Array?e.concat(t):e.constructor==Date&&t.constructor==Date?e.valueOf()>t.valueOf()?e:t:void 0})).toEqual({a:new Set([1,2,3,4]),b:a,c:{ca:[1,2,{a:1},2,[],{b:1}]},d:20})})});