-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathor.spec.ts
69 lines (53 loc) · 2.03 KB
/
or.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
68
69
import { Maybe } from '@/src/maybe';
describe('Maybe', () => {
describe('or', () => {
describe('value', () => {
test('will return a Maybe with the fallback when there is no value', () => {
const sut = Maybe.none<number>();
expect(sut.or(1)).toHaveValue(1);
});
test('will return a Maybe with the original value when there is a value', () => {
const value = 1;
const sut = Maybe.some(value);
expect(sut.or(100)).toHaveValue(value);
});
});
describe('value factory', () => {
test('will return a Maybe with the result of the fallback function when there is no value', () => {
const sut = Maybe.none<number>();
expect(sut.or(() => 1)).toHaveValue(1);
});
test('will return a Maybe with the original value when there is a value', () => {
const value = 1;
const sut = Maybe.some(value);
expect(sut.or(() => 100)).toHaveValue(value);
});
});
describe('maybe', () => {
test('will return the fallback Maybe when there is no value', () => {
const sut = Maybe.none<number>();
const fallback = Maybe.some(1);
expect(sut.or(fallback)).toBe(fallback);
});
test('will return a Maybe with the original value when there is no value', () => {
const value = 1;
const sut = Maybe.some(value);
const fallback = Maybe.some(100);
expect(sut.or(fallback)).toHaveValue(value);
});
});
describe('maybe factory', () => {
test('will return the Maybe result of the fallback function when there is no value', () => {
const sut = Maybe.none<number>();
const fallback = Maybe.some(1);
expect(sut.or(() => fallback)).toBe(fallback);
});
test('will return a Maybe with the original value when there is no value', () => {
const value = 1;
const sut = Maybe.some(value);
const fallback = Maybe.some(100);
expect(sut.or(() => fallback)).toHaveValue(value);
});
});
});
});