-
-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathmutateMergeDeep.spec.ts
53 lines (46 loc) · 1.59 KB
/
mutateMergeDeep.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { describe, expect, test } from 'vitest'
import { mutateMergeDeep } from '../src/index'
describe('mutateMergeDeep', () => {
test('Should merge two objects by mutating', () => {
const a = { a: 1 }
const b = { b: 2 }
mutateMergeDeep(a, b)
expect(a).toStrictEqual({ a: 1, b: 2 })
})
test('Should merge two objects including overwriting with undefined', () => {
const a = { a: 1 }
const b = { a: undefined }
mutateMergeDeep(a, b)
expect(a).toStrictEqual({ a: undefined })
})
test('Should merge two object by overriding arrays', () => {
const target = { a: [1] }
const source = { a: [2] }
mutateMergeDeep(target, source)
expect(target).toStrictEqual({ a: [2] })
})
test('Should merge add array element when it does not exist in target', () => {
const target = { a: [] }
const source = { a: [2] }
mutateMergeDeep(target, source)
expect(target).toStrictEqual({ a: [2] })
})
test('Should override the target array if source is undefined', () => {
const target = { a: [2] }
const source = { a: undefined }
mutateMergeDeep(target, source)
expect(target).toStrictEqual({ a: undefined })
})
test('Should merge update array element when it does not exist in source', () => {
const target = { a: [2] }
const source = { a: [] }
mutateMergeDeep(target, source)
expect(target).toStrictEqual({ a: [] })
})
test('Should merge two deeply nested objects', () => {
const a = { a: { a: 1 } }
const b = { a: { b: 2 } }
mutateMergeDeep(a, b)
expect(a).toStrictEqual({ a: { a: 1, b: 2 } })
})
})