|
1 | | -const { setRaw } = require('./utils') |
| 1 | +const { setRaw, combineDeepmerge } = require('./utils') |
2 | 2 | const { StringSchema } = require('./StringSchema') |
3 | 3 | const { ObjectSchema } = require('./ObjectSchema') |
4 | 4 |
|
@@ -31,3 +31,45 @@ describe('setRaw', () => { |
31 | 31 | }) |
32 | 32 | }) |
33 | 33 | }) |
| 34 | + |
| 35 | +describe('combineDeepmerge', () => { |
| 36 | + it('should merge empty arrays', () => { |
| 37 | + const result = combineDeepmerge([], []); |
| 38 | + expect(result).toEqual([]) |
| 39 | + }) |
| 40 | + |
| 41 | + it('should merge array with primitive values', () => { |
| 42 | + const result = combineDeepmerge([1], [2]); |
| 43 | + expect(result).toEqual([1, 2]) |
| 44 | + }) |
| 45 | + |
| 46 | + it('should merge arrays with primitive values', () => { |
| 47 | + const result = combineDeepmerge([], [1, 2]); |
| 48 | + expect(result).toEqual([1, 2]) |
| 49 | + }) |
| 50 | + |
| 51 | + it('should merge arrays with primitive values', () => { |
| 52 | + const result = combineDeepmerge([1, 2], [1, 2, 3]); |
| 53 | + expect(result).toEqual([1, 2, 3]) |
| 54 | + }) |
| 55 | + |
| 56 | + it('should merge array with simple Schemas', () => { |
| 57 | + const result = combineDeepmerge([{ type: 'string' }], [{ type: 'string' }]); |
| 58 | + expect(result).toEqual([{ type: 'string' }]) |
| 59 | + }) |
| 60 | + |
| 61 | + it('should merge array with named Schemas', () => { |
| 62 | + const result = combineDeepmerge([{ name: 'variant 1', type: 'string' }], [{ name: 'variant 2', type: 'string' }]); |
| 63 | + expect(result).toEqual([{ name: 'variant 1', type: 'string' }, { name: 'variant 2', type: 'string' }]) |
| 64 | + }) |
| 65 | + |
| 66 | + it('should merge array with same named Schemas', () => { |
| 67 | + const result = combineDeepmerge([{ name: 'variant 2', type: 'string' }], [{ name: 'variant 2', type: 'number' }]); |
| 68 | + expect(result).toEqual([{ name: 'variant 2', type: 'number' }]) |
| 69 | + }) |
| 70 | + |
| 71 | + it('should merge array with same named Schemas', () => { |
| 72 | + const result = combineDeepmerge([{ name: 'variant 2', type: 'string' }], [{ name: 'variant 2', type: 'number' }, { name: 'variant 1', type: 'string' }]); |
| 73 | + expect(result).toEqual([{ name: 'variant 2', type: 'number' }, { name: 'variant 1', type: 'string' }]) |
| 74 | + }) |
| 75 | +}) |
0 commit comments