-
Notifications
You must be signed in to change notification settings - Fork 112
/
filter.pipe.spec.ts
67 lines (47 loc) · 1.62 KB
/
filter.pipe.spec.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { FilterPipe } from './filter.pipe';
describe('FilterPipe', () => {
let filterPipe: FilterPipe;
// synchronous beforeEach
beforeEach(() => {
filterPipe = new FilterPipe();
});
it('should be instanciated', () => {
expect(filterPipe).toBeDefined();
});
it('should return empty array if no items given', () => {
const items = null;
const filtered = filterPipe.transform(items, 'name', 'Hans');
expect(filtered.length).toBe(0);
expect(filtered).toEqual([]);
});
it('should return items if no field is given', () => {
const items = [];
items.push({ id: 1, name: 'Hans' });
const filtered = filterPipe.transform(items, null, 'Hans');
expect(filtered).toEqual(items);
});
it('should return items if no value is given', () => {
const items = [];
items.push({ id: 1, name: 'Hans' });
const filtered = filterPipe.transform(items, 'name', null);
expect(filtered).toEqual(items);
});
it('should filter correctly', () => {
const items = [];
items.push({ id: 1, name: 'Hans' });
items.push({ id: 2, name: 'Franz' });
items.push({ id: 3, name: 'Kurt' });
items.push({ id: 4, name: 'Gustav' });
const filtered = filterPipe.transform(items, 'name', 'Hans');
expect(filtered.length).toBe(1);
});
it('should filter two items', () => {
const items = [];
items.push({ id: 1, name: 'Hans' });
items.push({ id: 2, name: 'Hans' });
items.push({ id: 3, name: 'Kurt' });
items.push({ id: 4, name: 'Gustav' });
const filtered = filterPipe.transform(items, 'name', 'Hans');
expect(filtered.length).toBe(2);
});
});