This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge.js
68 lines (58 loc) · 1.9 KB
/
merge.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var expect = require('must')
, merge = require('../lib/merge')
describe('merge', function() {
describe('when given just one object', function() {
it('should make a shallow copy of that object', function() {
var foo = { wibble: 1 }
, bar = merge(foo)
expect(foo).to.not.equal(bar)
expect(bar).to.have.own('wibble')
expect(bar.wibble).to.equal(1)
})
})
describe('when given two objects', function() {
it('should merge the two objects into a new object', function() {
var a = { foo: 1 }
, b = { bar: 2 }
, m = merge(a, b)
expect(m).to.not.equal(a)
expect(m).to.not.equal(b)
expect(m).to.have.keys(['foo', 'bar'])
expect(m.foo).to.equal(1)
expect(m.bar).to.equal(2)
})
it('should make sure the left-most object value is used in case of conflict', function() {
var a = { foo: 1 }
, b = { foo: 2, bar: 3 }
, m = merge(a, b)
expect(m).to.have.keys(['foo', 'bar'])
expect(m.foo).to.equal(2)
expect(m.bar).to.equal(3)
})
})
describe('when given more than two objects', function() {
it('should merge all objects into a new object', function() {
var a = { foo: 1 }
, b = { bar: 2 }
, c = { baz: 3 }
, m = merge(a, b, c)
expect(m).to.not.equal(a)
expect(m).to.not.equal(b)
expect(m).to.not.equal(c)
expect(m).to.have.keys(['foo', 'bar', 'baz'])
expect(m.foo).to.equal(1)
expect(m.bar).to.equal(2)
expect(m.baz).to.equal(3)
})
it('should make sure the left-most object value is used in case of conflict', function() {
var a = { foo: 1, bar: 2 }
, b = { bar: 3, baz: 4 }
, c = { baz: 5, foo: 6 }
, m = merge(a, b, c)
expect(m).to.have.keys(['foo', 'bar', 'baz'])
expect(m.foo).to.equal(6)
expect(m.bar).to.equal(3)
expect(m.baz).to.equal(5)
})
})
})