-
Notifications
You must be signed in to change notification settings - Fork 4
/
bind.spect.ts
61 lines (46 loc) · 1.75 KB
/
bind.spect.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
import { Result } from '@/src/result';
import { ResultAsync } from '@/src/resultAsync';
describe('ResultAsync', () => {
describe('bind', () => {
test('does not call the projection with a failed ResultAsync', async () => {
let wasCalled = false;
const sut = ResultAsync.failure<number>('error');
const result = await sut
.bind((num) => {
wasCalled = true;
return Result.success(num + 1);
})
.toPromise();
expect(result).toFailWith('error');
expect(wasCalled).toBe(false);
});
test('calls the projection returning a successful Result with a successful ResultAsync', async () => {
const sut = ResultAsync.success(1);
const result = await sut
.bind((num) => Result.success(num + 1))
.toPromise();
expect(result).toSucceedWith(2);
});
test('calls the projection returning a failed Result with a successful ResultAsync', async () => {
const sut = ResultAsync.success(1);
const result = await sut
.bind((_num) => Result.failure('error'))
.toPromise();
expect(result).toFailWith('error');
});
test('calls the projection returning a successful ResultAsync with a successful ResultAsync', async () => {
const sut = ResultAsync.success(1);
const result = await sut
.bind((num) => ResultAsync.success(num + 1))
.toPromise();
expect(result).toSucceedWith(2);
});
test('calls the projection returning a failed ResultAsync with a successful ResultAsync', async () => {
const sut = ResultAsync.success(1);
const result = await sut
.bind((_num) => ResultAsync.failure('error'))
.toPromise();
expect(result).toFailWith('error');
});
});
});