-
Notifications
You must be signed in to change notification settings - Fork 4
/
from.spec.ts
63 lines (44 loc) · 1.76 KB
/
from.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
import { Result } from '@/src/result';
import { ResultAsync } from '@/src/resultAsync';
describe('ResultAsync', () => {
describe('from', () => {
describe('Result', () => {
test('constructs a successful ResultAsync from a sucessful Result', async () => {
const value = 1;
const sut = ResultAsync.from(Result.success(value));
const result = await sut.toPromise();
expect(result).toSucceedWith(value);
});
test('constructs a failed ResultAsync from a failed Result', async () => {
const error = 'error';
const sut = ResultAsync.from(Result.failure(error));
const result = await sut.toPromise();
expect(result).toFailWith(error);
});
});
describe('Promise Result', () => {
test("constructs a successful ResultAsync from a resolved Promise's successful Result value", async () => {
const number = 1;
const sut = ResultAsync.from(Promise.resolve(Result.success(number)));
const result = await sut.toPromise();
expect(result).toSucceedWith(number);
});
test("constructs a failed ResultAsync from a resolved Promise's failed Result value", async () => {
const error = 'error';
const sut = ResultAsync.from(
Promise.resolve(Result.failure<number>(error))
);
const innerResult = await sut.toPromise();
expect(innerResult).toFailWith(error);
});
});
describe('Promise', () => {
test("constructs a successful ResultAsync from a resolved Promise's value", async () => {
const number = 1;
const sut = ResultAsync.from(Promise.resolve(number));
const result = await sut.toPromise();
expect(result).toSucceedWith(number);
});
});
});
});