|
1 | 1 | import { assert } from 'chai';
|
| 2 | +import { uniqWith, equals } from 'ramda'; |
2 | 3 |
|
3 | 4 | import {
|
4 | 5 | deepmerge,
|
@@ -455,6 +456,42 @@ describe('deepmerge', function () {
|
455 | 456 | assert.strictEqual(toValue(merged.get('name')), 'Alex and Tony');
|
456 | 457 | assert.deepEqual(toValue(merged.get('pets')), ['Cat', 'Parrot', 'Dog']);
|
457 | 458 | });
|
| 459 | + |
| 460 | + specify('should handle nested properties', function () { |
| 461 | + const x = new ObjectElement({ |
| 462 | + foo: { bar: { enum: [1, 2, 3, 4] } }, |
| 463 | + baz: { |
| 464 | + enum: [{ enum: [1, 2, 3] }, { enum: [1, 2, 3, 4] }], |
| 465 | + }, |
| 466 | + }); |
| 467 | + const y = new ObjectElement({ |
| 468 | + foo: { bar: { enum: [1, 2, 3, 5] } }, |
| 469 | + baz: { |
| 470 | + enum: [{ enum: [1, 2, 3, 4] }], |
| 471 | + }, |
| 472 | + }); |
| 473 | + const merged = deepmerge(x, y, { |
| 474 | + customMerge: (keyElement) => { |
| 475 | + if (toValue(keyElement) === 'enum') { |
| 476 | + return (targetElement, sourceElement) => |
| 477 | + new ArrayElement( |
| 478 | + uniqWith(equals)([...toValue(targetElement), ...toValue(sourceElement)]), |
| 479 | + ); |
| 480 | + } |
| 481 | + return deepmerge; |
| 482 | + }, |
| 483 | + }); |
| 484 | + const output = { |
| 485 | + foo: { |
| 486 | + bar: { enum: [1, 2, 3, 4, 5] }, |
| 487 | + }, |
| 488 | + baz: { |
| 489 | + enum: [{ enum: [1, 2, 3] }, { enum: [1, 2, 3, 4] }], |
| 490 | + }, |
| 491 | + }; |
| 492 | + |
| 493 | + assert.deepEqual(toValue(merged), output); |
| 494 | + }); |
458 | 495 | });
|
459 | 496 |
|
460 | 497 | context('given isMergeableElement option', function () {
|
|
0 commit comments