-
Notifications
You must be signed in to change notification settings - Fork 3
/
renameAll.js
47 lines (40 loc) · 919 Bytes
/
renameAll.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
const { expect } = require('chai')
const { renameAll } = require('..')
describe('renameAll', () => {
const orig = {
color: 'red',
name: 'bird',
sounds: {
call: 'chirp'
},
title: 'My title',
latestTitle: 'haha (business)',
}
const renames = {
color: 'appearance',
count: 'number',
sounds: {
call: 'say'
},
latestTitle: 'title',
title: 'updatedTitle',
}
const expected = {
appearance: 'red',
name: 'bird',
sounds: {
say: 'chirp'
},
title: 'haha (business)',
updatedTitle: 'My title',
}
it('renames multiple nested properties on an object using a name-map', () =>
expect(renameAll(renames, orig)).to.eql(expected)
)
it('is curried', () =>
expect(renameAll(renames)(orig)).to.eql(expected)
)
it('does not error in the pathological case', () =>
expect(renameAll({}, orig)).to.eql(orig)
)
})