-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
72 lines (59 loc) · 1.9 KB
/
test.js
File metadata and controls
72 lines (59 loc) · 1.9 KB
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
69
70
71
72
import test from 'ava';
import get from '.';
// Test cases borrowed from:
// https://github.com/mickhansen/dottie.js/blob/master/test/get.test.js
// https://github.com/jonschlinkert/get-value/blob/master/test/units.js
const data = {
'foo': {
'bar': 'baz'
},
'zoo': 'lander',
'false': {
'value': false
},
'null': {
'value': null
},
'nullvalue': null
};
test('should return undefined if value is undefined', t => {
t.is(get(undefined, 'foo'), undefined);
t.is(get(undefined, 'foo'), undefined);
});
test('should return undefined if key is undefined', t => {
t.is(get(data, undefined), undefined);
t.is(get(data, null), undefined);
t.is(get(data, undefined, 'default'), 'default');
});
test('should get first-level values', t => {
t.is(get(data, 'zoo'), 'lander');
t.is(get(data, 'zoo'), 'lander');
});
test('should get nested-level values', t => {
t.is(get(data, 'foo.bar'), 'baz');
});
test('should get nested-level values multiple times', t => {
t.is(get(data, 'foo.bar'), 'baz');
t.is(get(data, 'foo.bar'), 'baz');
t.is(get(data, 'foo.bar'), 'baz');
t.is(get(data, 'foo.bar'), 'baz');
});
test('should return undefined if not found', t => {
t.is(get(data, 'foo.zoo.lander'), undefined);
});
test('should return false values properly', t => {
t.is(get(data, 'false.value'), false);
});
test('should return the default value passed in if not found', t => {
t.is(get(data, 'foo.zoo.lander', 'novalue'), 'novalue');
});
test('should return null if the value is null and not undefined', t => {
t.is(get(data, 'null.value'), null);
});
test('should return undefined if accessing a child property of a null value', t => {
t.is(get(data, 'nullvalue.childProp'), undefined);
t.is(get(data, 'null.value.childProp'), undefined);
});
test('should return undefined if accessing a child property of a string value', t => {
t.is(get(data, 'foo.bar.baz.yapa'), undefined);
});