forked from angus-c/just
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (57 loc) · 1.38 KB
/
Copy pathindex.js
File metadata and controls
64 lines (57 loc) · 1.38 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
var test = require('../util/test')(__filename);
var pick = require('../../packages/object-pick');
var compare = require('../../packages/collection-compare');
// var obj = {a: 3, b: 5, c: 9};
// pick(obj, a, c); // {a: 3, c: 9}
//
// var obj = {a: 3, b: 5, c: 9};
// pick(obj, ['a', 'b', 'd']); // {a: 3, b: 5, d: undefined}
//
// var obj = {a: 3, b: 5, c: 9};
// pick(obj, ['a', 'a']); // {a: 3}
test('pick returns new object', function(t) {
t.plan(1);
var obj = {a: 3, b: 5, c: 9};
t.ok(pick(obj, []) !== obj);
t.end();
});
test('pick using array', function(t) {
t.plan(1);
var obj = {a: 3, b: 5, c: 9};
t.ok(compare(pick(obj, ['a', 'c']), {a: 3, c: 9}));
t.end();
});
test('pick using arguments', function(t) {
t.plan(1);
var obj = {a: 3, b: 5, c: 9};
t.ok(compare(pick(obj, 'a', 'c'), {a: 3, c: 9}));
t.end();
});
test('pick using a non-existent key', function(t) {
t.plan(1);
var obj = {a: 3, b: 5, c: 9};
t.ok(compare(pick(obj, ['a', 'b', 'd']), {a: 3, b: 5}));
t.end();
});
test('pick using a duplicate key', function(t) {
t.plan(1);
var obj = {a: 3, b: 5, c: 9};
t.ok(compare(pick(obj, ['a', 'a']), {a: 3}));
t.end();
});
test('pick where obj has a function value', function(t) {
t.plan(1);
var fn = function() {
return true;
};
var obj = {
a: 3,
b: fn,
};
t.ok(
compare(pick(obj, 'b'), {
b: fn,
})
);
t.end();
});