-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
38 lines (33 loc) · 855 Bytes
/
test.js
File metadata and controls
38 lines (33 loc) · 855 Bytes
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
const getf = require('./index')
const { expect } = require('chai')
describe('getf', () => {
it ('should get initial value', () => {
const obj = {
name: {
first: 'Mihovil',
last: 'Rister',
}
}
const result = getf(obj, 'name.first')
expect(result).to.eql(obj.name.first)
})
it ('should get fallback value from path value', () => {
const obj = {
name: {
first: 'Mihovil',
}
}
const result = getf(obj, [ 'initials', 'name.first'])
expect(result).to.eql(obj.name.first)
})
it ('should return default value if none found', () => {
const obj = {
name: {
first: 'Mihovil',
}
}
const DEFAULT_VALUE = 'N/A';
const result = getf(obj, [ 'initials', 'address', 'gender'], DEFAULT_VALUE)
expect(result).to.eql(DEFAULT_VALUE)
})
})