-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathorAsync.spec.ts
69 lines (51 loc) · 2.08 KB
/
orAsync.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';
import { MaybeAsync } from '@/src/maybeAsync';
describe('Maybe', () => {
describe('orAsync', () => {
describe('async value', () => {
test('will return a Maybe with the fallback when there is no value', async () => {
const sut = Maybe.none<number>();
const innerMaybe = await sut.orAsync(Promise.resolve(1)).toPromise();
expect(innerMaybe).toHaveValue(1);
});
test('will return a Maybe with the original value when there is a value', async () => {
const value = 1;
const sut = Maybe.some(value);
const innerMaybe = await sut.orAsync(Promise.resolve(100)).toPromise();
expect(innerMaybe).toHaveValue(value);
});
});
describe('async value factory', () => {
test('will return a Maybe with the result of the fallback function when there is no value', async () => {
const sut = Maybe.none<number>();
const innerMaybe = await sut
.orAsync(() => Promise.resolve(1))
.toPromise();
expect(innerMaybe).toHaveValue(1);
});
test('will return a Maybe with the original value when there is a value', async () => {
const value = 1;
const sut = Maybe.some(value);
const innerMaybe = await sut
.orAsync(() => Promise.resolve(100))
.toPromise();
expect(innerMaybe).toHaveValue(value);
});
});
describe('maybeAsync', () => {
test('will return the fallback MaybeAsync when there is no value', async () => {
const sut = Maybe.none<number>();
const fallback = MaybeAsync.some(1);
const innerMaybe = await sut.orAsync(fallback).toPromise();
expect(innerMaybe).toHaveValue(1);
});
test('will return a Maybe with the original value when there is no value', async () => {
const value = 1;
const sut = Maybe.some(value);
const fallback = MaybeAsync.some(100);
const innerMaybe = await sut.orAsync(fallback).toPromise();
expect(innerMaybe).toHaveValue(value);
});
});
});
});