-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfilter.test.ts
50 lines (42 loc) · 1.35 KB
/
filter.test.ts
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
import * as _ from 'lodash';
import test from 'ava';
import * as promiseUtils from '../src/index';
test('returns empty array when given no input', async (t) => {
const output = await promiseUtils.filter(null as any, _.identity);
t.deepEqual(output, []);
});
test('filters arrays', async (t) => {
const input = [1, 2];
const output = await promiseUtils.filter(input, async (value: any) => {
return value === 2;
});
t.deepEqual(output, [2]);
});
test('filters arrays with indices', async (t) => {
const input = [1, 2];
const output = await promiseUtils.filter(input, async (value: any, i: number) => {
return i === 1;
});
t.deepEqual(output, [2]);
});
test('filters objects with numeric keys', async (t) => {
const input = { 1: 'asdf', 2: 'abcd' };
const output = await promiseUtils.filter(input, async (value, i) => {
return (i as any) === 1 || (i as any) === 2;
});
t.deepEqual(output, []);
});
test('filters objects', async (t) => {
const input = { a: 1, b: 2 };
const output = await promiseUtils.filter(input, async (value: any) => {
return value === 2;
});
t.deepEqual(output, [2]);
});
test('filters objects without keys', async (t) => {
const input = { a: 1, b: 2 };
const output = await promiseUtils.filter(input, async (value: any, key: any) => {
return key === 'b';
});
t.deepEqual(output, [2]);
});