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
71 lines (66 loc) · 1.44 KB
/
Copy pathindex.js
File metadata and controls
71 lines (66 loc) · 1.44 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
var test = require('../util/test')(__filename);
var index = require('../../packages/array-index');
test('indexes an array of objects', function(t) {
t.plan(1);
t.deepEqual(index([{id: 'first', val: 1}, {id: 'second', val: 2}], 'id'), {
first: {id: 'first', val: 1},
second: {id: 'second', val: 2},
});
t.end();
});
test('drops elements without specified key', function(t) {
t.plan(1);
t.deepEqual(index([{id: 'first', val: 1}, null], 'id'), {
first: {id: 'first', val: 1},
});
t.end();
});
test('returns empty array as empty object', function(t) {
t.plan(1);
t.deepEqual(index([], 'id'), {});
t.end();
});
test('throws if first argument is not an array', function(t) {
t.plan(6);
t.throws(function() {
index({}, 'name');
});
t.throws(function() {
index('hello', 'name');
});
t.throws(function() {
index(/hullo/, 'name');
});
t.throws(function() {
index(null, 'name');
});
t.throws(function() {
index(undefined, 'name');
});
t.throws(function() {
index();
});
t.end();
});
test('throws if second argument is not a string', function(t) {
t.plan(6);
t.throws(function() {
index([], {});
});
t.throws(function() {
index([], function() {});
});
t.throws(function() {
index([], /hullo/);
});
t.throws(function() {
index([], null);
});
t.throws(function() {
index([], undefined);
});
t.throws(function() {
index([]);
});
t.end();
});