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
32 lines (29 loc) · 803 Bytes
/
Copy pathindex.js
File metadata and controls
32 lines (29 loc) · 803 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
var test = require('../util/test')(__filename);
var flatten = require('../../packages/array-flatten');
test('flattened arrays are unchanged', function(t) {
t.plan(1);
var arr = [1, 2, 3, 4, 5];
t.deepEqual(flatten(arr), arr);
t.end();
});
test('unflattened arrays are flattened', function(t) {
t.plan(2);
var arr1 = [1, [2, 3], [4, [5, 6], 7], 8];
t.deepEqual(flatten(arr1), [1, 2, 3, 4, 5, 6, 7, 8]);
var arr2 = [{a: 4}, [{b: 5}, {c: false}], {d: 'd'}];
t.deepEqual(flatten(arr2), [{a: 4}, {b: 5}, {c: false}, {d: 'd'}]);
t.end();
});
test('throws on non-arrays return an empty array', function(t) {
t.plan(3);
t.throws(function() {
flatten({n: 4});
});
t.throws(function() {
flatten(2);
});
t.throws(function() {
flatten(undefined);
});
t.end();
});