-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtryLast.spec.ts
36 lines (25 loc) · 931 Bytes
/
tryLast.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
import { Maybe } from '@/src/maybe';
describe('Maybe', () => {
describe('tryLast', () => {
test('creates a Maybe with a value when the array has a value', () => {
const items = [1, 2, 3];
const sut = Maybe.tryLast(items);
expect(sut).toHaveValue(items[2]);
});
test('creates a Maybe with no value when the array is empty', () => {
const items: number[] = [];
const sut = Maybe.tryLast(items);
expect(sut).toHaveNoValue();
});
test('creates a Maybe with the last value which matches the predicate', () => {
const items = [1, 2, 3, 4];
const sut = Maybe.tryLast(items, (i) => i > 2);
expect(sut).toHaveValue(4);
});
test('creates a Maybe with no value when the predicate has no matches', () => {
const items = [1, 2, 3, 4];
const sut = Maybe.tryLast(items, (i) => i > 10);
expect(sut).toHaveNoValue();
});
});
});