Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (43 loc) · 1.25 KB
/
Copy pathindex.js
File metadata and controls
49 lines (43 loc) · 1.25 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
var test = require('../util/test')(__filename);
var flush = require('../../packages/collection-flush');
/*
flush([1, undefined, 2, null, 3, NaN, 0]); // [1, 2, 3, NaN, 0]
flush([true, null, false, true, [null], undefined]); // [true, false, true, [null]]
flush({a: 2, b: null, c: 4, d: undefined}); // {a: 2, c: 4}
flush('something'); // undefined
flush(); // undefined
*/
test('removes null/undefined from array', function(t) {
t.plan(2);
t.deepEqual(flush([1, undefined, 2, null, 3, 0]), [1, 2, 3, 0]);
t.deepEqual(flush([true, null, false, true, [null], undefined]), [
true,
false,
true,
[null],
]);
t.end();
});
test('removes null/undefined from object', function(t) {
t.plan(1);
t.deepEqual(flush({a: 2, b: null, c: 4, d: undefined}), {a: 2, c: 4});
t.end();
});
test('returns empty array as-is', function(t) {
t.plan(1);
t.deepEqual(flush([]), []);
t.end();
});
test('returns empty object as-is', function(t) {
t.plan(1);
t.deepEqual(flush({}), {});
t.end();
});
test('returns undefined if argument is not an array or object', function(t) {
t.plan(4);
t.equal(flush('hello'), undefined);
t.equal(flush(null), undefined);
t.equal(flush(undefined), undefined);
t.equal(flush(), undefined);
t.end();
});