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
77 lines (73 loc) · 1.38 KB
/
Copy pathindex.js
File metadata and controls
77 lines (73 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
65
66
67
68
69
70
71
72
73
74
75
76
77
var test = require('tape');
var entries = require('../../packages/object-entries');
test('regular objects return pairs of property/value', function(t) {
t.plan(3);
t.deepEqual(entries({c: 8, a: 4}), [['c', 8], ['a', 4]]);
t.deepEqual(entries({b: {bb: 4}, a: {aa: 2}}), [
['b', {bb: 4}],
['a', {aa: 2}],
]);
t.deepEqual(entries({}), []);
t.end();
});
test('arrays return pairs of index/value', function(t) {
t.plan(3);
t.deepEqual(entries([{c: 8}, {a: 4}]), [
['0', {c: 8}],
['1', {a: 4}],
]);
t.deepEqual(entries([]), []);
t.notEqual(entries([]), []);
t.end();
});
test('irregular objects return pairs of property/value', function(t) {
t.plan(3);
t.deepEqual(entries(new String('hello')), [
['0', 'h'],
['1', 'e'],
['2', 'l'],
['3', 'l'],
['4', 'o'],
]);
t.deepEqual(
entries(function(a, b) {
return a + b;
}),
[]
);
var fn = function() {};
fn.a = 4;
t.deepEqual(entries(fn), [['a', 4]]);
t.end();
});
test('primitives throw exceptions', function(t) {
t.plan(4);
t.throws(
function() {
entries(1);
},
Error,
'number'
);
t.throws(
function() {
entries(true);
},
Error,
'boolean'
);
t.throws(
function() {
entries(undefined);
},
Error,
'undefined'
);
t.throws(
function() {
entries(null);
},
Error,
'null'
);
});